jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | "github.com/gophercloud/gophercloud/testhelper/client" |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 10 | ) |
| 11 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 12 | func MockListResponse(t *testing.T) { |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 13 | th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 14 | th.TestMethod(t, r, "GET") |
Ash Wilson | ff899c1 | 2014-10-22 09:14:30 -0400 | [diff] [blame] | 15 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 16 | |
| 17 | w.Header().Add("Content-Type", "application/json") |
| 18 | w.WriteHeader(http.StatusOK) |
| 19 | |
| 20 | fmt.Fprintf(w, `{ |
| 21 | "versions": [ |
| 22 | { |
| 23 | "status": "CURRENT", |
| 24 | "updated": "2012-01-04T11:33:21Z", |
| 25 | "id": "v1.0", |
| 26 | "links": [ |
| 27 | { |
| 28 | "href": "http://23.253.228.211:8776/v1/", |
| 29 | "rel": "self" |
| 30 | } |
| 31 | ] |
| 32 | }, |
| 33 | { |
| 34 | "status": "CURRENT", |
| 35 | "updated": "2012-11-21T11:33:21Z", |
| 36 | "id": "v2.0", |
| 37 | "links": [ |
| 38 | { |
| 39 | "href": "http://23.253.228.211:8776/v2/", |
| 40 | "rel": "self" |
| 41 | } |
| 42 | ] |
| 43 | } |
| 44 | ] |
| 45 | }`) |
| 46 | }) |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 47 | } |
| 48 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 49 | func MockGetResponse(t *testing.T) { |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 50 | th.Mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) { |
| 51 | th.TestMethod(t, r, "GET") |
Ash Wilson | ff899c1 | 2014-10-22 09:14:30 -0400 | [diff] [blame] | 52 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 53 | |
| 54 | w.Header().Add("Content-Type", "application/json") |
| 55 | w.WriteHeader(http.StatusOK) |
| 56 | |
| 57 | fmt.Fprintf(w, `{ |
| 58 | "version": { |
| 59 | "status": "CURRENT", |
| 60 | "updated": "2012-01-04T11:33:21Z", |
| 61 | "media-types": [ |
| 62 | { |
| 63 | "base": "application/xml", |
| 64 | "type": "application/vnd.openstack.volume+xml;version=1" |
| 65 | }, |
| 66 | { |
| 67 | "base": "application/json", |
| 68 | "type": "application/vnd.openstack.volume+json;version=1" |
| 69 | } |
| 70 | ], |
| 71 | "id": "v1.0", |
| 72 | "links": [ |
| 73 | { |
| 74 | "href": "http://23.253.228.211:8776/v1/", |
| 75 | "rel": "self" |
| 76 | }, |
| 77 | { |
| 78 | "href": "http://jorgew.github.com/block-storage-api/content/os-block-storage-1.0.pdf", |
| 79 | "type": "application/pdf", |
| 80 | "rel": "describedby" |
| 81 | }, |
| 82 | { |
| 83 | "href": "http://docs.rackspacecloud.com/servers/api/v1.1/application.wadl", |
| 84 | "type": "application/vnd.sun.wadl+xml", |
| 85 | "rel": "describedby" |
| 86 | } |
| 87 | ] |
| 88 | } |
| 89 | }`) |
| 90 | }) |
Jon Perritt | fd53bba | 2014-10-03 00:41:22 -0500 | [diff] [blame] | 91 | } |