github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/apiversions/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/gophercloud/gophercloud/openstack/compute/apiversions" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 "github.com/gophercloud/gophercloud/testhelper/client" 12 ) 13 14 const NovaAPIVersionResponse_20 = ` 15 { 16 "version": { 17 "id": "v2.0", 18 "status": "SUPPORTED", 19 "version": "", 20 "min_version": "", 21 "updated": "2011-01-21T11:33:21Z", 22 "links": [ 23 { 24 "rel": "self", 25 "href": "http://10.1.5.216/compute/v2/" 26 }, 27 { 28 "rel": "describedby", 29 "type": "text/html", 30 "href": "http://docs.openstack.org/" 31 } 32 ], 33 "media-types": [ 34 { 35 "base": "application/json", 36 "type": "application/vnd.openstack.compute+json;version=2" 37 } 38 ] 39 } 40 } 41 ` 42 43 const NovaAPIVersionResponse_21 = ` 44 { 45 "version": { 46 "id": "v2.1", 47 "status": "CURRENT", 48 "version": "2.87", 49 "min_version": "2.1", 50 "updated": "2013-07-23T11:33:21Z", 51 "links": [ 52 { 53 "rel": "self", 54 "href": "http://10.1.5.216/compute/v2.1/" 55 }, 56 { 57 "rel": "describedby", 58 "type": "text/html", 59 "href": "http://docs.openstack.org/" 60 } 61 ], 62 "media-types": [ 63 { 64 "base": "application/json", 65 "type": "application/vnd.openstack.compute+json;version=2.1" 66 } 67 ] 68 } 69 } 70 71 ` 72 73 const NovaAPIInvalidVersionResponse = ` 74 { 75 "choices": [ 76 { 77 "id": "v2.0", 78 "status": "SUPPORTED", 79 "links": [ 80 { 81 "rel": "self", 82 "href": "http://10.1.5.216/compute/v2/compute/v3" 83 } 84 ], 85 "media-types": [ 86 { 87 "base": "application/json", 88 "type": "application/vnd.openstack.compute+json;version=2" 89 } 90 ] 91 }, 92 { 93 "id": "v2.1", 94 "status": "CURRENT", 95 "links": [ 96 { 97 "rel": "self", 98 "href": "http://10.1.5.216/compute/v2.1/compute/v3" 99 } 100 ], 101 "media-types": [ 102 { 103 "base": "application/json", 104 "type": "application/vnd.openstack.compute+json;version=2.1" 105 } 106 ] 107 } 108 ] 109 } 110 ` 111 112 const NovaAllAPIVersionsResponse = ` 113 { 114 "versions": [ 115 { 116 "id": "v2.0", 117 "status": "SUPPORTED", 118 "version": "", 119 "min_version": "", 120 "updated": "2011-01-21T11:33:21Z", 121 "links": [ 122 { 123 "rel": "self", 124 "href": "http://10.1.5.216/compute/v2/" 125 } 126 ] 127 }, 128 { 129 "id": "v2.1", 130 "status": "CURRENT", 131 "version": "2.87", 132 "min_version": "2.1", 133 "updated": "2013-07-23T11:33:21Z", 134 "links": [ 135 { 136 "rel": "self", 137 "href": "http://10.1.5.216/compute/v2.1/" 138 } 139 ] 140 } 141 ] 142 } 143 ` 144 145 var NovaAPIVersion20Result = apiversions.APIVersion{ 146 ID: "v2.0", 147 Status: "SUPPORTED", 148 Updated: time.Date(2011, 1, 21, 11, 33, 21, 0, time.UTC), 149 } 150 151 var NovaAPIVersion21Result = apiversions.APIVersion{ 152 ID: "v2.1", 153 Status: "CURRENT", 154 Updated: time.Date(2013, 7, 23, 11, 33, 21, 0, time.UTC), 155 MinVersion: "2.1", 156 Version: "2.87", 157 } 158 159 var NovaAllAPIVersionResults = []apiversions.APIVersion{ 160 NovaAPIVersion20Result, 161 NovaAPIVersion21Result, 162 } 163 164 func MockListResponse(t *testing.T) { 165 th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 166 th.TestMethod(t, r, "GET") 167 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 168 169 w.Header().Add("Content-Type", "application/json") 170 w.WriteHeader(http.StatusOK) 171 172 fmt.Fprintf(w, NovaAllAPIVersionsResponse) 173 }) 174 } 175 176 func MockGetResponse(t *testing.T) { 177 th.Mux.HandleFunc("/v2.1/", func(w http.ResponseWriter, r *http.Request) { 178 th.TestMethod(t, r, "GET") 179 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 180 181 w.Header().Add("Content-Type", "application/json") 182 w.WriteHeader(http.StatusOK) 183 184 fmt.Fprintf(w, NovaAPIVersionResponse_21) 185 }) 186 } 187 188 func MockGetMultipleResponses(t *testing.T) { 189 th.Mux.HandleFunc("/v3/", func(w http.ResponseWriter, r *http.Request) { 190 th.TestMethod(t, r, "GET") 191 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 192 193 w.Header().Add("Content-Type", "application/json") 194 w.WriteHeader(http.StatusOK) 195 196 fmt.Fprintf(w, NovaAPIInvalidVersionResponse) 197 }) 198 }