|
| 1 | +package testing |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | + "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | +) |
| 11 | + |
| 12 | +const APIListResponse = ` |
| 13 | +{ |
| 14 | + "versions": [ |
| 15 | + { |
| 16 | + "id": "v1.0", |
| 17 | + "links": [ |
| 18 | + { |
| 19 | + "href": "http://docs.openstack.org/", |
| 20 | + "rel": "describedby", |
| 21 | + "type": "text/html" |
| 22 | + }, |
| 23 | + { |
| 24 | + "href": "http://localhost:8776/v1/", |
| 25 | + "rel": "self" |
| 26 | + } |
| 27 | + ], |
| 28 | + "media-types": [ |
| 29 | + { |
| 30 | + "base": "application/json", |
| 31 | + "type": "application/vnd.openstack.volume+json;version=1" |
| 32 | + } |
| 33 | + ], |
| 34 | + "min_version": "", |
| 35 | + "status": "DEPRECATED", |
| 36 | + "updated": "2016-05-02T20:25:19Z", |
| 37 | + "version": "" |
| 38 | + }, |
| 39 | + { |
| 40 | + "id": "v2.0", |
| 41 | + "links": [ |
| 42 | + { |
| 43 | + "href": "http://docs.openstack.org/", |
| 44 | + "rel": "describedby", |
| 45 | + "type": "text/html" |
| 46 | + }, |
| 47 | + { |
| 48 | + "href": "http://localhost:8776/v2/", |
| 49 | + "rel": "self" |
| 50 | + } |
| 51 | + ], |
| 52 | + "media-types": [ |
| 53 | + { |
| 54 | + "base": "application/json", |
| 55 | + "type": "application/vnd.openstack.volume+json;version=1" |
| 56 | + } |
| 57 | + ], |
| 58 | + "min_version": "", |
| 59 | + "status": "SUPPORTED", |
| 60 | + "updated": "2014-06-28T12:20:21Z", |
| 61 | + "version": "" |
| 62 | + }, |
| 63 | + { |
| 64 | + "id": "v3.0", |
| 65 | + "links": [ |
| 66 | + { |
| 67 | + "href": "http://docs.openstack.org/", |
| 68 | + "rel": "describedby", |
| 69 | + "type": "text/html" |
| 70 | + }, |
| 71 | + { |
| 72 | + "href": "http://localhost:8776/v3/", |
| 73 | + "rel": "self" |
| 74 | + } |
| 75 | + ], |
| 76 | + "media-types": [ |
| 77 | + { |
| 78 | + "base": "application/json", |
| 79 | + "type": "application/vnd.openstack.volume+json;version=1" |
| 80 | + } |
| 81 | + ], |
| 82 | + "min_version": "3.0", |
| 83 | + "status": "CURRENT", |
| 84 | + "updated": "2016-02-08T12:20:21Z", |
| 85 | + "version": "3.27" |
| 86 | + } |
| 87 | + ] |
| 88 | +} |
| 89 | +` |
| 90 | + |
| 91 | +const APIGetResponse = ` |
| 92 | +{ |
| 93 | + "versions": [ |
| 94 | + { |
| 95 | + "id": "v3.0", |
| 96 | + "links": [ |
| 97 | + { |
| 98 | + "href": "http://docs.openstack.org/", |
| 99 | + "rel": "describedby", |
| 100 | + "type": "text/html" |
| 101 | + }, |
| 102 | + { |
| 103 | + "href": "http://localhost:8776/v3/", |
| 104 | + "rel": "self" |
| 105 | + } |
| 106 | + ], |
| 107 | + "media-types": [ |
| 108 | + { |
| 109 | + "base": "application/json", |
| 110 | + "type": "application/vnd.openstack.volume+json;version=1" |
| 111 | + } |
| 112 | + ], |
| 113 | + "min_version": "3.0", |
| 114 | + "status": "CURRENT", |
| 115 | + "updated": "2016-02-08T12:20:21Z", |
| 116 | + "version": "3.27" |
| 117 | + } |
| 118 | + ] |
| 119 | +} |
| 120 | +` |
| 121 | + |
| 122 | +func MockListResponse(t *testing.T) { |
| 123 | + th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 124 | + th.TestMethod(t, r, "GET") |
| 125 | + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 126 | + |
| 127 | + w.Header().Add("Content-Type", "application/json") |
| 128 | + w.WriteHeader(http.StatusOK) |
| 129 | + |
| 130 | + fmt.Fprintf(w, APIListResponse) |
| 131 | + }) |
| 132 | +} |
| 133 | + |
| 134 | +func MockGetResponse(t *testing.T) { |
| 135 | + th.Mux.HandleFunc("/v3/", func(w http.ResponseWriter, r *http.Request) { |
| 136 | + th.TestMethod(t, r, "GET") |
| 137 | + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 138 | + |
| 139 | + w.Header().Add("Content-Type", "application/json") |
| 140 | + w.WriteHeader(http.StatusOK) |
| 141 | + |
| 142 | + fmt.Fprintf(w, APIGetResponse) |
| 143 | + }) |
| 144 | +} |
0 commit comments