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