github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/vaults/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/cbr/v3/vaults" 9 "github.com/huaweicloud/golangsdk/openstack/common/tags" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 const ( 15 expectedCreateRequest = ` 16 { 17 "vault" : { 18 "backup_policy_id" : "6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b", 19 "billing" : { 20 "cloud_type" : "public", 21 "consistent_level" : "crash_consistent", 22 "object_type" : "server", 23 "protect_type" : "backup", 24 "size" : 100, 25 "charging_mode" : "post_paid", 26 "console_url" : "https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243®ion=testregion/cbr/manager/csbs/vaultList" 27 }, 28 "description" : "vault_description", 29 "name" : "vault_name", 30 "resources" : [ { 31 "extra_info" : { 32 "include_volumes" : [ { 33 "id" : "73ee8446-bce7-4371-9650-b440b5f4c1d0", 34 "os_version" : "CentOS 7.6 64bit" 35 } ] 36 }, 37 "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 38 "type" : "OS::Nova::Server" 39 } ], 40 "tags" : [ { 41 "key" : "key01", 42 "value" : "value01" 43 } ], 44 "enterprise_project_id" : "0" 45 } 46 }` 47 expectedCreateResponse = ` 48 { 49 "vault" : { 50 "provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66", 51 "description" : "vault_description", 52 "tags" : [ { 53 "value" : "value01", 54 "key" : "key01" 55 } ], 56 "enterprise_project_id" : "0", 57 "auto_bind" : false, 58 "id" : "ad7627ae-5b0b-492e-b6bd-cd809b745197", 59 "user_id" : "38d65be2ecd840d19046e239e841a734", 60 "name" : "vault_name", 61 "billing" : { 62 "status" : "available", 63 "used" : 0, 64 "protect_type" : "backup", 65 "object_type" : "server", 66 "allocated" : 40, 67 "spec_code" : "vault.backup.server.normal", 68 "size" : 100, 69 "cloud_type" : "public", 70 "consistent_level" : "crash_consistent", 71 "charging_mode" : "post_paid" 72 }, 73 "created_at" : "2019-05-23T12:51:10.071232", 74 "project_id" : "fc347bc64ccd4589ae52e4f44b7433c7", 75 "resources" : [ { 76 "name" : "ecs-b977-0002", 77 "backup_size" : 0, 78 "protect_status" : "available", 79 "backup_count" : 0, 80 "extra_info" : { 81 "include_volumes" : [ { 82 "os_version" : "CentOS 7.6 64bit", 83 "id" : "73ee8446-bce7-4371-9650-b440b5f4c1d0" 84 } ] 85 }, 86 "type" : "OS::Nova::Server", 87 "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 88 "size" : 40 89 } ] 90 } 91 }` 92 expectedUpdateRequest = ` 93 { 94 "vault" : { 95 "billing" : { 96 "size" : 100 97 }, 98 "name" : "vault_name" 99 } 100 } 101 }` 102 103 expectedListResponse = ` 104 { 105 "vaults" : [ { 106 "provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66", 107 "description" : "vault_description", 108 "tags" : [ { 109 "value" : "value01", 110 "key" : "key01" 111 } ], 112 "enterprise_project_id" : "0", 113 "auto_bind" : false, 114 "id" : "ad7627ae-5b0b-492e-b6bd-cd809b745197", 115 "user_id" : "38d65be2ecd840d19046e239e841a734", 116 "name" : "vault_name", 117 "billing" : { 118 "status" : "available", 119 "used" : 0, 120 "protect_type" : "backup", 121 "object_type" : "server", 122 "allocated" : 40, 123 "spec_code" : "vault.backup.server.normal", 124 "size" : 100, 125 "cloud_type" : "public", 126 "consistent_level" : "crash_consistent", 127 "charging_mode" : "post_paid" 128 }, 129 "created_at" : "2019-05-23T12:51:10.071232", 130 "project_id" : "fc347bc64ccd4589ae52e4f44b7433c7", 131 "resources" : [ { 132 "name" : "ecs-b977-0002", 133 "backup_size" : 0, 134 "protect_status" : "available", 135 "backup_count" : 0, 136 "extra_info" : { 137 "include_volumes" : [ { 138 "os_version" : "CentOS 7.6 64bit", 139 "id" : "73ee8446-bce7-4371-9650-b440b5f4c1d0" 140 } ] 141 }, 142 "type" : "OS::Nova::Server", 143 "id" : "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 144 "size" : 40 145 } ] 146 } ], 147 "count" : 1 148 }` 149 150 expectedPolicyBindingResponse = ` 151 { 152 "associate_policy" : { 153 "vault_id" : "ad7627ae-5b0b-492e-b6bd-cd809b745197", 154 "policy_id" : "7075c397-25a0-43e2-a83a-bb16eaca3ee5" 155 } 156 }` 157 158 expectedPolicyUnbindingResponse = ` 159 { 160 "dissociate_policy" : { 161 "vault_id" : "ad7627ae-5b0b-492e-b6bd-cd809b745197", 162 "policy_id" : "7075c397-25a0-43e2-a83a-bb16eaca3ee5" 163 } 164 }` 165 166 expectedAssociateResourcesRequest = ` 167 { 168 "resources" : [ { 169 "extra_info" : { 170 "exclude_volumes" : [ "bdef09bb-293f-446a-88a4-86e9f14408c4" ] 171 }, 172 "id" : "97595625-198e-4e4d-879b-9d53f68ba551", 173 "type" : "OS::Nova::Server" 174 } ] 175 }` 176 177 expectedAssociateResourcesResponse = ` 178 { 179 "add_resource_ids" : [ "97595625-198e-4e4d-879b-9d53f68ba551" ] 180 }` 181 182 expectedDissociateResourcesRequest = ` 183 { 184 "resource_ids" : [ "97595625-198e-4e4d-879b-9d53f68ba551" ] 185 }` 186 187 expectedDissociateResourcesResponse = ` 188 { 189 "remove_resource_ids" : [ "fe578a6c-d1a8-4790-bd52-5954af4d446c" ] 190 }` 191 192 expectedMigrateResourcesResponse = ` 193 { 194 'resource_ids': [ 'abcdde3f-e0e3-403a-b690-fc259dd70008' ], 195 'destination_vault_id': 'fe578a6c-d1a8-4790-bd52-5954af4d446c' 196 }` 197 ) 198 199 var ( 200 createOpts = &vaults.CreateOpts{ 201 BackupPolicyID: "6dd81d7d-a4cb-443e-b8ed-1af0bd3a261b", 202 Billing: &vaults.BillingCreate{ 203 ConsistentLevel: "crash_consistent", 204 CloudType: "public", 205 ObjectType: "server", 206 ProtectType: "backup", 207 Size: 100, 208 ChargingMode: "post_paid", 209 ConsoleURL: "https://console.demo.com/cbr/?agencyId=97fcd896b7914cb98f553a087232e243®ion=testregion/cbr/manager/csbs/vaultList", 210 }, 211 Description: "vault_description", 212 EnterpriseProjectID: "0", 213 Name: "vault_name", 214 Resources: []vaults.ResourceCreate{ 215 { 216 ID: "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 217 Type: "OS::Nova::Server", 218 ExtraInfo: &vaults.ResourceExtraInfo{ 219 IncludeVolumes: []vaults.ResourceExtraInfoIncludeVolumes{ 220 { 221 ID: "73ee8446-bce7-4371-9650-b440b5f4c1d0", 222 OSVersion: "CentOS 7.6 64bit", 223 }, 224 }, 225 }, 226 }, 227 }, 228 Tags: []tags.ResourceTag{ 229 { 230 Key: "key01", 231 Value: "value01", 232 }, 233 }, 234 } 235 236 expectedCreateResponseData = &vaults.Vault{ 237 ID: "ad7627ae-5b0b-492e-b6bd-cd809b745197", 238 Name: "vault_name", 239 UserID: "38d65be2ecd840d19046e239e841a734", 240 AutoBind: false, 241 ProviderID: "0daac4c5-6707-4851-97ba-169e36266b66", 242 ProjectID: "fc347bc64ccd4589ae52e4f44b7433c7", 243 Description: "vault_description", 244 EnterpriseProjectID: "0", 245 CreatedAt: "2019-05-23T12:51:10.071232", 246 Billing: vaults.Billing{ 247 Status: "available", 248 ProtectType: "backup", 249 ObjectType: "server", 250 SpecCode: "vault.backup.server.normal", 251 CloudType: "public", 252 ConsistentLevel: "crash_consistent", 253 ChargingMode: "post_paid", 254 Used: 0, 255 Allocated: 40, 256 Size: 100, 257 }, 258 Tags: []tags.ResourceTag{ 259 { 260 Key: "key01", 261 Value: "value01", 262 }, 263 }, 264 Resources: []vaults.ResourceResp{ 265 { 266 ID: "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 267 Type: "OS::Nova::Server", 268 Name: "ecs-b977-0002", 269 ProtectStatus: "available", 270 BackupSize: 0, 271 BackupCount: 0, 272 Size: 40, 273 ExtraInfo: vaults.ResourceExtraInfo{ 274 IncludeVolumes: []vaults.ResourceExtraInfoIncludeVolumes{ 275 { 276 ID: "73ee8446-bce7-4371-9650-b440b5f4c1d0", 277 OSVersion: "CentOS 7.6 64bit", 278 }, 279 }, 280 }, 281 }, 282 }, 283 } 284 285 updateOpts = &vaults.UpdateOpts{ 286 Billing: &vaults.BillingUpdate{ 287 Size: 100, 288 }, 289 Name: "vault_name", 290 } 291 292 expectedListResponseData = &[]vaults.Vault{ 293 { 294 ID: "ad7627ae-5b0b-492e-b6bd-cd809b745197", 295 Name: "vault_name", 296 UserID: "38d65be2ecd840d19046e239e841a734", 297 AutoBind: false, 298 ProviderID: "0daac4c5-6707-4851-97ba-169e36266b66", 299 ProjectID: "fc347bc64ccd4589ae52e4f44b7433c7", 300 Description: "vault_description", 301 EnterpriseProjectID: "0", 302 CreatedAt: "2019-05-23T12:51:10.071232", 303 Billing: vaults.Billing{ 304 Status: "available", 305 ProtectType: "backup", 306 ObjectType: "server", 307 SpecCode: "vault.backup.server.normal", 308 CloudType: "public", 309 ConsistentLevel: "crash_consistent", 310 ChargingMode: "post_paid", 311 Used: 0, 312 Allocated: 40, 313 Size: 100, 314 }, 315 Tags: []tags.ResourceTag{ 316 { 317 Key: "key01", 318 Value: "value01", 319 }, 320 }, 321 Resources: []vaults.ResourceResp{ 322 { 323 ID: "23a320a5-3efd-4568-b1aa-8dd9183cc64c", 324 Type: "OS::Nova::Server", 325 Name: "ecs-b977-0002", 326 ProtectStatus: "available", 327 BackupSize: 0, 328 BackupCount: 0, 329 Size: 40, 330 ExtraInfo: vaults.ResourceExtraInfo{ 331 IncludeVolumes: []vaults.ResourceExtraInfoIncludeVolumes{ 332 { 333 ID: "73ee8446-bce7-4371-9650-b440b5f4c1d0", 334 OSVersion: "CentOS 7.6 64bit", 335 }, 336 }, 337 }, 338 }, 339 }, 340 }, 341 } 342 343 bindPolicyOpts = &vaults.BindPolicyOpts{ 344 PolicyID: "7075c397-25a0-43e2-a83a-bb16eaca3ee5", 345 } 346 347 expectedPolicyBindingResponseData = &vaults.PolicyBinding{ 348 VaultID: "ad7627ae-5b0b-492e-b6bd-cd809b745197", 349 PolicyID: "7075c397-25a0-43e2-a83a-bb16eaca3ee5", 350 } 351 352 associateResourcesOpts = &vaults.AssociateResourcesOpts{ 353 Resources: []vaults.ResourceCreate{ 354 { 355 ExtraInfo: &vaults.ResourceExtraInfo{ 356 ExcludeVolumes: []string{ 357 "bdef09bb-293f-446a-88a4-86e9f14408c4", 358 }, 359 }, 360 ID: "97595625-198e-4e4d-879b-9d53f68ba551", 361 Type: "OS::Nova::Server", 362 }, 363 }, 364 } 365 366 expectedAssociateResourcesResponseData = []string{ 367 "97595625-198e-4e4d-879b-9d53f68ba551", 368 } 369 370 dissociateResourcesOpts = &vaults.DissociateResourcesOpts{ 371 ResourceIDs: []string{ 372 "97595625-198e-4e4d-879b-9d53f68ba551", 373 }, 374 } 375 ) 376 377 func handleVaultCreate(t *testing.T) { 378 th.Mux.HandleFunc("/vaults", func(w http.ResponseWriter, r *http.Request) { 379 th.TestMethod(t, r, "POST") 380 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 381 w.Header().Add("Content-Type", "application/json") 382 w.WriteHeader(http.StatusOK) 383 fmt.Fprint(w, expectedCreateResponse) 384 }) 385 } 386 387 func handleVaultGet(t *testing.T) { 388 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197", func(w http.ResponseWriter, r *http.Request) { 389 th.TestMethod(t, r, "GET") 390 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 391 w.Header().Add("Content-Type", "application/json") 392 w.WriteHeader(http.StatusOK) 393 _, _ = fmt.Fprint(w, expectedCreateResponse) 394 }) 395 } 396 397 func handleVaultUpdate(t *testing.T) { 398 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197", func(w http.ResponseWriter, r *http.Request) { 399 th.TestMethod(t, r, "PUT") 400 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 401 w.Header().Add("Content-Type", "application/json") 402 w.WriteHeader(http.StatusOK) 403 fmt.Fprint(w, expectedCreateResponse) 404 }) 405 } 406 407 func handleVaultDelete(t *testing.T) { 408 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197", func(w http.ResponseWriter, r *http.Request) { 409 th.TestMethod(t, r, "DELETE") 410 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 411 w.Header().Add("Content-Type", "application/json") 412 w.WriteHeader(http.StatusNoContent) 413 }) 414 } 415 416 func handleVaultList(t *testing.T) { 417 th.Mux.HandleFunc("/vaults", func(w http.ResponseWriter, r *http.Request) { 418 th.TestMethod(t, r, "GET") 419 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 420 w.Header().Add("Content-Type", "application/json") 421 w.WriteHeader(http.StatusOK) 422 _, _ = fmt.Fprint(w, expectedListResponse) 423 }) 424 } 425 426 func handleVaultBindPolicy(t *testing.T) { 427 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197/associatepolicy", 428 func(w http.ResponseWriter, r *http.Request) { 429 th.TestMethod(t, r, "POST") 430 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 431 w.Header().Add("Content-Type", "application/json") 432 w.WriteHeader(http.StatusOK) 433 _, _ = fmt.Fprint(w, expectedPolicyBindingResponse) 434 }) 435 } 436 437 func handleVaultUnbindPolicy(t *testing.T) { 438 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197/dissociatepolicy", 439 func(w http.ResponseWriter, r *http.Request) { 440 th.TestMethod(t, r, "POST") 441 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 442 w.Header().Add("Content-Type", "application/json") 443 w.WriteHeader(http.StatusOK) 444 _, _ = fmt.Fprint(w, expectedPolicyUnbindingResponse) 445 }) 446 } 447 448 func handleVaultAssociateResources(t *testing.T) { 449 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197/addresources", 450 func(w http.ResponseWriter, r *http.Request) { 451 th.TestMethod(t, r, "POST") 452 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 453 w.Header().Add("Content-Type", "application/json") 454 w.WriteHeader(http.StatusOK) 455 _, _ = fmt.Fprint(w, expectedAssociateResourcesResponse) 456 }) 457 } 458 459 func handleVaultDissociateResources(t *testing.T) { 460 th.Mux.HandleFunc("/vaults/ad7627ae-5b0b-492e-b6bd-cd809b745197/removeresources", 461 func(w http.ResponseWriter, r *http.Request) { 462 th.TestMethod(t, r, "POST") 463 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 464 w.Header().Add("Content-Type", "application/json") 465 w.WriteHeader(http.StatusOK) 466 _, _ = fmt.Fprint(w, expectedAssociateResourcesResponse) 467 }) 468 }