github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vbs/v2/backups/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/vbs/v2/backups" 8 fake "github.com/huaweicloud/golangsdk/openstack/vbs/v2/common" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 ) 11 12 func TestListBackup(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListSuccessfully(t, FullListOutput) 16 17 actual, err := backups.List(fake.ServiceClient(), backups.ListOpts{}) 18 if err != nil { 19 t.Errorf("Failed to extract backups: %v", err) 20 } 21 th.AssertDeepEquals(t, ListExpected, actual) 22 th.AssertNoErr(t, err) 23 } 24 25 func TestGetBackup(t *testing.T) { 26 th.SetupHTTP() 27 defer th.TeardownHTTP() 28 29 HandleGetSuccessfully(t) 30 31 s, err := backups.Get(fake.ServiceClient(), "87566ed6-72cb-4053-aa6e-6f6216b3d507").Extract() 32 th.AssertNoErr(t, err) 33 th.AssertDeepEquals(t, s, &backups.Backup{ 34 Name: "c2c-test-buckup", 35 Id: "87566ed6-72cb-4053-aa6e-6f6216b3d507", 36 Status: "available", 37 ObjectCount: 0, 38 TenantId: "17fbda95add24720a4038ba4b1c705ed", 39 Container: "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 40 AvailabilityZone: "eu-de-01", 41 DependentBackups: false, 42 SnapshotId: "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3", 43 VolumeId: "5024a06e-6990-4f12-9dcc-8fe26b01a710", 44 Incremental: false, 45 Size: 10, 46 Links: []golangsdk.Link{ 47 { 48 Href: "https://vbs.eu-de.otc.t-systems.com/v2/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507", 49 Rel: "self", 50 }, 51 { 52 Href: "https://vbs.eu-de.otc.t-systems.com/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507", 53 Rel: "bookmark", 54 }, 55 }, 56 }) 57 } 58 59 func TestCreateBackup(t *testing.T) { 60 th.SetupHTTP() 61 defer th.TeardownHTTP() 62 HandleCreateSuccessfully(t, CreateOutput) 63 64 createOpts := backups.CreateOpts{ 65 Name: "backup_test", 66 VolumeId: "5024a06e-6990-4f12-9dcc-8fe26b01a710", 67 } 68 actual, err := backups.Create(fake.ServiceClient(), createOpts).ExtractJobResponse() 69 th.AssertNoErr(t, err) 70 71 expected := CreateExpected 72 th.AssertDeepEquals(t, expected, actual) 73 } 74 75 func TestDeleteBackup(t *testing.T) { 76 th.SetupHTTP() 77 defer th.TeardownHTTP() 78 HandleDeleteSuccessfully(t) 79 80 result := backups.Delete(fake.ServiceClient(), "87566ed6-72cb-4053-aa6e-6f6216b3d507") 81 th.AssertNoErr(t, result.Err) 82 } 83 84 func TestCreateRestore(t *testing.T) { 85 th.SetupHTTP() 86 defer th.TeardownHTTP() 87 HandleRestoreSuccessfully(t, RestoreOutput) 88 89 restoreOpts := backups.BackupRestoreOpts{ 90 VolumeId: "5024a06e-6990-4f12-9dcc-8fe26b01a710", 91 } 92 actual, err := backups.CreateBackupRestore(fake.ServiceClient(), "87566ed6-72cb-4053-aa6e-6f6216b3d507", restoreOpts).ExtractBackupRestore() 93 th.AssertNoErr(t, err) 94 95 expected := RestoreExpected 96 th.AssertDeepEquals(t, expected, actual) 97 }