|
| 1 | +package serverscom |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + . "github.com/onsi/gomega" |
| 8 | +) |
| 9 | + |
| 10 | +const ( |
| 11 | + backupVolumeID = "X7ax9byv" |
| 12 | +) |
| 13 | + |
| 14 | +func TestCloudBlockStorageBackupsCollection(t *testing.T) { |
| 15 | + g := NewGomegaWithT(t) |
| 16 | + |
| 17 | + ts, client := newFakeServer(). |
| 18 | + WithRequestPath("/cloud_block_storage/backups"). |
| 19 | + WithRequestMethod("GET"). |
| 20 | + WithResponseBodyStubInline(`[]`). |
| 21 | + WithResponseCode(200). |
| 22 | + Build() |
| 23 | + |
| 24 | + defer ts.Close() |
| 25 | + |
| 26 | + collection := client.CloudBlockStorageBackups.Collection() |
| 27 | + |
| 28 | + ctx := context.TODO() |
| 29 | + |
| 30 | + list, err := collection.List(ctx) |
| 31 | + |
| 32 | + g.Expect(err).To(BeNil()) |
| 33 | + g.Expect(list).To(BeEmpty()) |
| 34 | + g.Expect(collection.HasNextPage()).To(Equal(false)) |
| 35 | + g.Expect(collection.HasPreviousPage()).To(Equal(false)) |
| 36 | + g.Expect(collection.HasFirstPage()).To(Equal(false)) |
| 37 | + g.Expect(collection.HasLastPage()).To(Equal(false)) |
| 38 | +} |
| 39 | + |
| 40 | +func TestCloudBlockStorageBackupsCreate(t *testing.T) { |
| 41 | + g := NewGomegaWithT(t) |
| 42 | + |
| 43 | + ts, client := newFakeServer(). |
| 44 | + WithRequestPath("/cloud_block_storage/backups"). |
| 45 | + WithRequestMethod("POST"). |
| 46 | + WithResponseBodyStubFile("fixtures/cloud_backups/create_response.json"). |
| 47 | + WithResponseCode(201). |
| 48 | + Build() |
| 49 | + |
| 50 | + defer ts.Close() |
| 51 | + |
| 52 | + input := CloudBlockStorageBackupCreateInput{ |
| 53 | + VolumeID: backupVolumeID, |
| 54 | + Name: "test-backup-1", |
| 55 | + Incremental: true, |
| 56 | + Force: false, |
| 57 | + Labels: map[string]string{"env": "test"}, |
| 58 | + } |
| 59 | + |
| 60 | + ctx := context.TODO() |
| 61 | + |
| 62 | + cloudBackup, err := client.CloudBlockStorageBackups.Create(ctx, input) |
| 63 | + |
| 64 | + g.Expect(err).To(BeNil()) |
| 65 | + g.Expect(cloudBackup).ToNot(BeNil()) |
| 66 | + |
| 67 | + g.Expect(cloudBackup.ID).To(Equal(backupVolumeID)) |
| 68 | + g.Expect(cloudBackup.Status).To(Equal("pending")) |
| 69 | + g.Expect(cloudBackup.Name).To(Equal("test-backup-1")) |
| 70 | + g.Expect(cloudBackup.OpenstackVolumeUUID).To(Equal("1ac953dc-2414-4831-8124-c2dcbd405926")) |
| 71 | + g.Expect(cloudBackup.OpenstackUUID).To(BeNil()) |
| 72 | + g.Expect(cloudBackup.Labels).To(Equal(map[string]string{"env": "test"})) |
| 73 | + g.Expect(cloudBackup.Created.String()).To(Equal("2024-11-11 09:57:28 +0000 UTC")) |
| 74 | +} |
| 75 | + |
| 76 | +func TestCloudBlockStorageBackupsGet(t *testing.T) { |
| 77 | + g := NewGomegaWithT(t) |
| 78 | + |
| 79 | + ts, client := newFakeServer(). |
| 80 | + WithRequestPath("/cloud_block_storage/backups/" + backupVolumeID). |
| 81 | + WithRequestMethod("GET"). |
| 82 | + WithResponseBodyStubFile("fixtures/cloud_backups/get_response.json"). |
| 83 | + WithResponseCode(201). |
| 84 | + Build() |
| 85 | + |
| 86 | + defer ts.Close() |
| 87 | + |
| 88 | + ctx := context.TODO() |
| 89 | + |
| 90 | + cloudBackup, err := client.CloudBlockStorageBackups.Get(ctx, backupVolumeID) |
| 91 | + |
| 92 | + g.Expect(err).To(BeNil()) |
| 93 | + g.Expect(cloudBackup).ToNot(BeNil()) |
| 94 | + |
| 95 | + g.Expect(cloudBackup.ID).To(Equal(backupVolumeID)) |
| 96 | + g.Expect(cloudBackup.Status).To(Equal("available")) |
| 97 | + g.Expect(cloudBackup.Name).To(Equal("test-backup-1")) |
| 98 | + g.Expect(cloudBackup.Size).To(Equal(1)) |
| 99 | + g.Expect(cloudBackup.RegionID).To(Equal(1)) |
| 100 | + g.Expect(*cloudBackup.OpenstackUUID).To(Equal("d1473317-bb2c-4d68-992c-0c117a68c01a")) |
| 101 | + g.Expect(cloudBackup.OpenstackVolumeUUID).To(Equal("1ac953dc-2414-4831-8124-c2dcbd405926")) |
| 102 | + g.Expect(cloudBackup.Labels).To(Equal(map[string]string{"env": "test"})) |
| 103 | + g.Expect(cloudBackup.Created.String()).To(Equal("2024-11-11 09:57:28 +0000 UTC")) |
| 104 | +} |
| 105 | + |
| 106 | +func TestCloudBlockStorageBackupsUpdate(t *testing.T) { |
| 107 | + g := NewGomegaWithT(t) |
| 108 | + |
| 109 | + ts, client := newFakeServer(). |
| 110 | + WithRequestPath("/cloud_block_storage/backups/" + backupVolumeID). |
| 111 | + WithRequestMethod("PUT"). |
| 112 | + WithResponseBodyStubFile("fixtures/cloud_backups/update_response.json"). |
| 113 | + WithResponseCode(202). |
| 114 | + Build() |
| 115 | + |
| 116 | + defer ts.Close() |
| 117 | + |
| 118 | + ctx := context.TODO() |
| 119 | + |
| 120 | + newLabels := map[string]string{"env": "new-test"} |
| 121 | + |
| 122 | + cloudBackup, err := client.CloudBlockStorageBackups.Update(ctx, backupVolumeID, CloudBlockStorageBackupUpdateInput{Labels: newLabels}) |
| 123 | + |
| 124 | + g.Expect(err).To(BeNil()) |
| 125 | + g.Expect(cloudBackup).ToNot(BeNil()) |
| 126 | + |
| 127 | + g.Expect(cloudBackup.ID).To(Equal(backupVolumeID)) |
| 128 | + g.Expect(cloudBackup.Status).To(Equal("available")) |
| 129 | + g.Expect(cloudBackup.Name).To(Equal("test-backup-1")) |
| 130 | + g.Expect(cloudBackup.Size).To(Equal(1)) |
| 131 | + g.Expect(cloudBackup.RegionID).To(Equal(1)) |
| 132 | + g.Expect(*cloudBackup.OpenstackUUID).To(Equal("d1473317-bb2c-4d68-992c-0c117a68c01a")) |
| 133 | + g.Expect(cloudBackup.OpenstackVolumeUUID).To(Equal("1ac953dc-2414-4831-8124-c2dcbd405926")) |
| 134 | + g.Expect(cloudBackup.Labels).To(Equal(newLabels)) |
| 135 | + g.Expect(cloudBackup.Created.String()).To(Equal("2024-11-11 09:57:28 +0000 UTC")) |
| 136 | +} |
| 137 | + |
| 138 | +func TestCloudBlockStorageBackupsDelete(t *testing.T) { |
| 139 | + g := NewGomegaWithT(t) |
| 140 | + |
| 141 | + ts, client := newFakeServer(). |
| 142 | + WithRequestPath("/cloud_block_storage/backups/" + backupVolumeID). |
| 143 | + WithRequestMethod("DELETE"). |
| 144 | + WithResponseBodyStubFile("fixtures/cloud_backups/delete_response.json"). |
| 145 | + WithResponseCode(202). |
| 146 | + Build() |
| 147 | + |
| 148 | + defer ts.Close() |
| 149 | + |
| 150 | + ctx := context.TODO() |
| 151 | + |
| 152 | + cloudBackup, err := client.CloudBlockStorageBackups.Delete(ctx, backupVolumeID) |
| 153 | + |
| 154 | + g.Expect(err).To(BeNil()) |
| 155 | + g.Expect(cloudBackup).ToNot(BeNil()) |
| 156 | + |
| 157 | + g.Expect(cloudBackup.ID).To(Equal(backupVolumeID)) |
| 158 | + g.Expect(cloudBackup.Status).To(Equal("deleting")) |
| 159 | + g.Expect(cloudBackup.Name).To(Equal("test-backup-1")) |
| 160 | + g.Expect(cloudBackup.Size).To(Equal(1)) |
| 161 | + g.Expect(cloudBackup.RegionID).To(Equal(1)) |
| 162 | + g.Expect(*cloudBackup.OpenstackUUID).To(Equal("d1473317-bb2c-4d68-992c-0c117a68c01a")) |
| 163 | + g.Expect(cloudBackup.OpenstackVolumeUUID).To(Equal("1ac953dc-2414-4831-8124-c2dcbd405926")) |
| 164 | + g.Expect(cloudBackup.Labels).To(Equal(map[string]string{"env": "test"})) |
| 165 | + g.Expect(cloudBackup.Created.String()).To(Equal("2024-11-11 09:57:28 +0000 UTC")) |
| 166 | +} |
| 167 | + |
| 168 | +func TestCloudBlockStorageBackupsRestore(t *testing.T) { |
| 169 | + g := NewGomegaWithT(t) |
| 170 | + |
| 171 | + ts, client := newFakeServer(). |
| 172 | + WithRequestPath("/cloud_block_storage/backups/" + backupVolumeID + "/restore"). |
| 173 | + WithRequestMethod("POST"). |
| 174 | + WithResponseBodyStubFile("fixtures/cloud_backups/restore_response.json"). |
| 175 | + WithResponseCode(202). |
| 176 | + Build() |
| 177 | + |
| 178 | + defer ts.Close() |
| 179 | + |
| 180 | + ctx := context.TODO() |
| 181 | + |
| 182 | + newVolumeID := backupVolumeID |
| 183 | + |
| 184 | + cloudBackup, err := client.CloudBlockStorageBackups.Restore(ctx, backupVolumeID, CloudBlockStorageBackupRestoreInput{VolumeID: newVolumeID}) |
| 185 | + |
| 186 | + g.Expect(err).To(BeNil()) |
| 187 | + g.Expect(cloudBackup).ToNot(BeNil()) |
| 188 | + |
| 189 | + g.Expect(cloudBackup.ID).To(Equal(backupVolumeID)) |
| 190 | + g.Expect(cloudBackup.Status).To(Equal("restoring")) |
| 191 | + g.Expect(cloudBackup.Name).To(Equal("test-backup-1")) |
| 192 | + g.Expect(cloudBackup.Size).To(Equal(1)) |
| 193 | + g.Expect(cloudBackup.RegionID).To(Equal(1)) |
| 194 | + g.Expect(*cloudBackup.OpenstackUUID).To(Equal("d1473317-bb2c-4d68-992c-0c117a68c01a")) |
| 195 | + g.Expect(cloudBackup.OpenstackVolumeUUID).To(Equal("1ac953dc-2414-4831-8124-c2dcbd405926")) |
| 196 | + g.Expect(cloudBackup.Labels).To(Equal(map[string]string{"env": "test"})) |
| 197 | + g.Expect(cloudBackup.Created.String()).To(Equal("2024-11-11 09:57:28 +0000 UTC")) |
| 198 | +} |
0 commit comments