github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/nodes/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/clustering/v1/nodes" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 fake "github.com/gophercloud/gophercloud/testhelper/client" 12 ) 13 14 const CreateResponse = `{ 15 "node": { 16 "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 17 "created_at": "2016-05-13T07:02:20Z", 18 "data": { 19 "internal_ports": [ 20 { 21 "network_id": "847e4f65-1ff1-42b1-9e74-74e6a109ad11", 22 "security_group_ids": ["8db277ab-1d98-4148-ba72-724721789427"], 23 "fixed_ips": [ 24 { 25 "subnet_id": "863b20c0-c011-4650-85c2-ad531f4570a4", 26 "ip_address": "10.63.177.162" 27 } 28 ], 29 "id": "43aa53d7-a70b-4f40-812f-4feecb687018", 30 "remove": true 31 } 32 ], 33 "placement": { 34 "zone": "nova" 35 } 36 }, 37 "dependents": {}, 38 "domain": "1235be1e-8d8e-43bb-bd6c-943eccf76a6d", 39 "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 40 "index": 2, 41 "init_at": "2016-05-13T08:02:04Z", 42 "metadata": { 43 "test": { 44 "nil_interface": null, 45 "bool_value": false, 46 "string_value": "test_string", 47 "float_value": 123.3 48 }, 49 "foo": "bar" 50 }, 51 "name": "node-e395be1e-002", 52 "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", 53 "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 54 "profile_name": "pcirros", 55 "project": "eee0b7c083e84501bdd50fb269d2a10e", 56 "role": "", 57 "status": "ACTIVE", 58 "status_reason": "Creation succeeded", 59 "updated_at": null, 60 "user": "ab79b9647d074e46ac223a8fa297b846" 61 } 62 }` 63 64 var ExpectedCreate = nodes.Node{ 65 ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 66 CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), 67 Data: map[string]interface{}{ 68 "internal_ports": []map[string]interface{}{ 69 { 70 "network_id": "847e4f65-1ff1-42b1-9e74-74e6a109ad11", 71 "security_group_ids": []interface{}{ 72 "8db277ab-1d98-4148-ba72-724721789427", 73 }, 74 "fixed_ips": []interface{}{ 75 map[string]interface{}{ 76 "subnet_id": "863b20c0-c011-4650-85c2-ad531f4570a4", 77 "ip_address": "10.63.177.162", 78 }, 79 }, 80 "id": "43aa53d7-a70b-4f40-812f-4feecb687018", 81 "remove": true, 82 }, 83 }, 84 "placement": map[string]interface{}{ 85 "zone": "nova", 86 }, 87 }, 88 Dependents: map[string]interface{}{}, 89 Domain: "1235be1e-8d8e-43bb-bd6c-943eccf76a6d", 90 ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 91 Index: 2, 92 InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), 93 Metadata: map[string]interface{}{ 94 "foo": "bar", 95 "test": map[string]interface{}{ 96 "nil_interface": interface{}(nil), 97 "float_value": float64(123.3), 98 "string_value": "test_string", 99 "bool_value": false, 100 }, 101 }, 102 Name: "node-e395be1e-002", 103 PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", 104 ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 105 ProfileName: "pcirros", 106 Project: "eee0b7c083e84501bdd50fb269d2a10e", 107 Role: "", 108 Status: "ACTIVE", 109 StatusReason: "Creation succeeded", 110 User: "ab79b9647d074e46ac223a8fa297b846", 111 } 112 113 const ListResponse = ` 114 { 115 "nodes": [ 116 { 117 "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 118 "created_at": "2016-05-13T07:02:20Z", 119 "data": {}, 120 "dependents": {}, 121 "domain": null, 122 "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 123 "index": 2, 124 "init_at": "2016-05-13T08:02:04Z", 125 "metadata": {}, 126 "name": "node-e395be1e-002", 127 "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", 128 "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 129 "profile_name": "pcirros", 130 "project": "eee0b7c083e84501bdd50fb269d2a10e", 131 "role": "", 132 "status": "ACTIVE", 133 "status_reason": "Creation succeeded", 134 "updated_at": "2016-05-13T09:02:04Z", 135 "user": "ab79b9647d074e46ac223a8fa297b846" } 136 ] 137 }` 138 139 var ExpectedList1 = nodes.Node{ 140 ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 141 CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), 142 Data: map[string]interface{}{}, 143 Dependents: map[string]interface{}{}, 144 Domain: "", 145 ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 146 Index: 2, 147 InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), 148 Metadata: map[string]interface{}{}, 149 Name: "node-e395be1e-002", 150 PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", 151 ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 152 ProfileName: "pcirros", 153 Project: "eee0b7c083e84501bdd50fb269d2a10e", 154 Role: "", 155 Status: "ACTIVE", 156 StatusReason: "Creation succeeded", 157 UpdatedAt: time.Date(2016, 5, 13, 9, 2, 4, 0, time.UTC), 158 User: "ab79b9647d074e46ac223a8fa297b846", 159 } 160 161 var ExpectedList = []nodes.Node{ExpectedList1} 162 163 const GetResponse = ` 164 { 165 "node": { 166 "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 167 "created_at": "2016-05-13T07:02:20Z", 168 "data": {}, 169 "dependents": {}, 170 "domain": null, 171 "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 172 "index": 2, 173 "init_at": "2016-05-13T07:02:04Z", 174 "metadata": {"foo": "bar"}, 175 "name": "node-e395be1e-002", 176 "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", 177 "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 178 "profile_name": "pcirros", 179 "project": "eee0b7c083e84501bdd50fb269d2a10e", 180 "role": "", 181 "status": "ACTIVE", 182 "status_reason": "Creation succeeded", 183 "updated_at": "2016-05-13T07:02:20Z", 184 "user": "ab79b9647d074e46ac223a8fa297b846" 185 } 186 }` 187 188 var ExpectedGet = nodes.Node{ 189 ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 190 CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), 191 Data: map[string]interface{}{}, 192 Dependents: map[string]interface{}{}, 193 Domain: "", 194 ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 195 Index: 2, 196 InitAt: time.Date(2016, 5, 13, 7, 2, 4, 0, time.UTC), 197 Metadata: map[string]interface{}{"foo": "bar"}, 198 Name: "node-e395be1e-002", 199 PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", 200 ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 201 ProfileName: "pcirros", 202 Project: "eee0b7c083e84501bdd50fb269d2a10e", 203 Role: "", 204 Status: "ACTIVE", 205 StatusReason: "Creation succeeded", 206 UpdatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), 207 User: "ab79b9647d074e46ac223a8fa297b846", 208 } 209 210 const UpdateResponse = ` 211 { 212 "node": { 213 "cluster_id": "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 214 "created_at": "2016-05-13T07:02:20Z", 215 "data": {}, 216 "dependents": {}, 217 "domain": null, 218 "id": "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 219 "index": 2, 220 "init_at": "2016-05-13T08:02:04Z", 221 "metadata": {"foo":"bar"}, 222 "name": "node-e395be1e-002", 223 "physical_id": "66a81d68-bf48-4af5-897b-a3bfef7279a8", 224 "profile_id": "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 225 "profile_name": "pcirros", 226 "project": "eee0b7c083e84501bdd50fb269d2a10e", 227 "role": "", 228 "status": "ACTIVE", 229 "status_reason": "Creation succeeded", 230 "updated_at": "2016-05-13T09:02:04Z", 231 "user": "ab79b9647d074e46ac223a8fa297b846" 232 } 233 }` 234 235 var ExpectedUpdate = nodes.Node{ 236 ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d", 237 CreatedAt: time.Date(2016, 5, 13, 7, 2, 20, 0, time.UTC), 238 Data: map[string]interface{}{}, 239 Dependents: map[string]interface{}{}, 240 Domain: "", 241 ID: "82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", 242 Index: 2, 243 InitAt: time.Date(2016, 5, 13, 8, 2, 4, 0, time.UTC), 244 Metadata: map[string]interface{}{"foo": "bar"}, 245 Name: "node-e395be1e-002", 246 PhysicalID: "66a81d68-bf48-4af5-897b-a3bfef7279a8", 247 ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0", 248 ProfileName: "pcirros", 249 Project: "eee0b7c083e84501bdd50fb269d2a10e", 250 Role: "", 251 Status: "ACTIVE", 252 StatusReason: "Creation succeeded", 253 UpdatedAt: time.Date(2016, 5, 13, 9, 2, 4, 0, time.UTC), 254 User: "ab79b9647d074e46ac223a8fa297b846", 255 } 256 257 const OperationActionResponse = ` 258 { 259 "action": "2a0ff107-e789-4660-a122-3816c43af703" 260 }` 261 262 const OperationExpectedActionID = "2a0ff107-e789-4660-a122-3816c43af703" 263 264 const ActionResponse = ` 265 { 266 "action": "2a0ff107-e789-4660-a122-3816c43af703" 267 }` 268 269 const ExpectedActionID = "2a0ff107-e789-4660-a122-3816c43af703" 270 271 func HandleCreateSuccessfully(t *testing.T) { 272 th.Mux.HandleFunc("/v1/nodes", func(w http.ResponseWriter, r *http.Request) { 273 th.TestMethod(t, r, "POST") 274 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 275 276 w.Header().Add("Content-Type", "application/json") 277 w.Header().Add("X-OpenStack-Request-ID", "req-3791a089-9d46-4671-a3f9-55e95e55d2b4") 278 w.Header().Add("Location", "http://senlin.cloud.blizzard.net:8778/v1/actions/ffd94dd8-6266-4887-9a8c-5b78b72136da") 279 280 w.WriteHeader(http.StatusOK) 281 282 fmt.Fprint(w, CreateResponse) 283 }) 284 } 285 286 func HandleListSuccessfully(t *testing.T) { 287 th.Mux.HandleFunc("/v1/nodes", func(w http.ResponseWriter, r *http.Request) { 288 th.TestMethod(t, r, "GET") 289 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 290 291 w.Header().Add("Content-Type", "application/json") 292 w.WriteHeader(http.StatusOK) 293 294 fmt.Fprint(w, ListResponse) 295 }) 296 } 297 298 func HandleDeleteSuccessfully(t *testing.T) { 299 th.Mux.HandleFunc("/v1/nodes/6dc6d336e3fc4c0a951b5698cd1236ee", func(w http.ResponseWriter, r *http.Request) { 300 th.TestMethod(t, r, "DELETE") 301 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 302 303 w.Header().Add("Content-Type", "application/json") 304 w.WriteHeader(http.StatusNoContent) 305 }) 306 } 307 308 func HandleGetSuccessfully(t *testing.T) { 309 th.Mux.HandleFunc("/v1/nodes/573aa1ba-bf45-49fd-907d-6b5d6e6adfd3", func(w http.ResponseWriter, r *http.Request) { 310 th.TestMethod(t, r, "GET") 311 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 312 313 w.Header().Add("Content-Type", "application/json") 314 w.WriteHeader(http.StatusOK) 315 316 fmt.Fprint(w, GetResponse) 317 }) 318 } 319 320 func HandleUpdateSuccessfully(t *testing.T) { 321 th.Mux.HandleFunc("/v1/nodes/82fe28e0-9fcb-42ca-a2fa-6eb7dddd75a1", func(w http.ResponseWriter, r *http.Request) { 322 th.TestMethod(t, r, "PATCH") 323 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 324 325 w.Header().Add("Content-Type", "application/json") 326 w.WriteHeader(http.StatusOK) 327 328 fmt.Fprint(w, UpdateResponse) 329 }) 330 } 331 332 func HandleOpsSuccessfully(t *testing.T) { 333 th.Mux.HandleFunc("/v1/nodes/7d85f602-a948-4a30-afd4-e84f47471c15/ops", func(w http.ResponseWriter, r *http.Request) { 334 th.TestMethod(t, r, "POST") 335 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 336 337 w.Header().Add("Content-Type", "application/json") 338 w.WriteHeader(http.StatusAccepted) 339 340 fmt.Fprint(w, OperationActionResponse) 341 }) 342 } 343 344 func HandleRecoverSuccessfully(t *testing.T) { 345 th.Mux.HandleFunc("/v1/nodes/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { 346 th.TestMethod(t, r, "POST") 347 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 348 w.Header().Add("Content-Type", "application/json") 349 w.Header().Add("X-OpenStack-Request-ID", "req-edce3528-864f-41fb-8759-f4707925cc09") 350 w.WriteHeader(http.StatusAccepted) 351 fmt.Fprint(w, ActionResponse) 352 }) 353 } 354 355 func HandleCheckSuccessfully(t *testing.T) { 356 th.Mux.HandleFunc("/v1/nodes/edce3528-864f-41fb-8759-f4707925cc09/actions", func(w http.ResponseWriter, r *http.Request) { 357 th.TestMethod(t, r, "POST") 358 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 359 w.Header().Add("Content-Type", "application/json") 360 w.Header().Add("X-OpenStack-Request-ID", "req-edce3528-864f-41fb-8759-f4707925cc09") 361 w.WriteHeader(http.StatusAccepted) 362 fmt.Fprint(w, ActionResponse) 363 }) 364 }