@@ -22,6 +22,7 @@ type FakeClient struct {
22
22
IP []IP
23
23
Networks []Network
24
24
Volumes []Volume
25
+ VolumeSnapshots []VolumeSnapshot
25
26
SSHKeys []SSHKey
26
27
Webhooks []Webhook
27
28
DiskImage []DiskImage
@@ -165,6 +166,15 @@ type Clienter interface {
165
166
DetachVolume (id string ) (* SimpleResponse , error )
166
167
DeleteVolume (id string ) (* SimpleResponse , error )
167
168
169
+ // VolumeSnapshot
170
+ GetVolumeSnapshotByVolumeID (volumeID , snapshotID string ) (* VolumeSnapshot , error )
171
+ ListVolumeSnapshotsByVolumeID (volumeID string ) ([]VolumeSnapshot , error )
172
+ CreateVolumeSnapshot (volumeID string , config * VolumeSnapshotConfig ) (* VolumeSnapshot , error )
173
+ DeleteVolumeAndAllSnapshot (volumeID string ) (* SimpleResponse , error )
174
+ ListVolumeSnapshots () ([]VolumeSnapshot , error )
175
+ GetVolumeSnapshot (id string ) (* VolumeSnapshot , error )
176
+ DeleteVolumeSnapshot (id string ) (* SimpleResponse , error )
177
+
168
178
// Webhooks
169
179
CreateWebhook (r * WebhookConfig ) (* Webhook , error )
170
180
ListWebhooks () ([]Webhook , error )
@@ -1330,6 +1340,93 @@ func (c *FakeClient) DeleteVolume(id string) (*SimpleResponse, error) {
1330
1340
return & SimpleResponse {Result : "failed" }, nil
1331
1341
}
1332
1342
1343
+ // GetVolumeSnapshotByVolumeID implemented in a fake way for automated tests
1344
+ func (c * FakeClient ) GetVolumeSnapshotByVolumeID (volumeID , snapshotID string ) (* VolumeSnapshot , error ) {
1345
+ for _ , snapshot := range c .VolumeSnapshots {
1346
+ if snapshot .VolumeID == volumeID && snapshot .SnapshotID == snapshotID {
1347
+ return & snapshot , nil
1348
+ }
1349
+ }
1350
+
1351
+ err := fmt .Errorf ("unable to find volume snapshot %s, zero matches" , snapshotID )
1352
+ return nil , ZeroMatchesError .wrap (err )
1353
+ }
1354
+
1355
+ // ListVolumeSnapshotsByVolumeID implemented in a fake way for automated tests
1356
+ func (c * FakeClient ) ListVolumeSnapshotsByVolumeID (volumeID string ) ([]VolumeSnapshot , error ) {
1357
+ snapshots := make ([]VolumeSnapshot , 0 )
1358
+ for _ , snapshot := range c .VolumeSnapshots {
1359
+ if snapshot .VolumeID == volumeID {
1360
+ snapshots = append (snapshots , snapshot )
1361
+ }
1362
+ }
1363
+
1364
+ return snapshots , nil
1365
+ }
1366
+
1367
+ // CreateVolumeSnapshot implemented in a fake way for automated tests
1368
+ func (c * FakeClient ) CreateVolumeSnapshot (volumeID string , config * VolumeSnapshotConfig ) (* VolumeSnapshot , error ) {
1369
+ snapshot := VolumeSnapshot {
1370
+ SnapshotID : c .generateID (),
1371
+ Name : config .Name ,
1372
+ VolumeID : volumeID ,
1373
+ State : "Ready" ,
1374
+ }
1375
+ c .VolumeSnapshots = append (c .VolumeSnapshots , snapshot )
1376
+
1377
+ return & snapshot , nil
1378
+ }
1379
+
1380
+ // DeleteVolumeAndAllSnapshot implemented in a fake way for automated tests
1381
+ func (c * FakeClient ) DeleteVolumeAndAllSnapshot (volumeID string ) (* SimpleResponse , error ) {
1382
+ for i , volume := range c .Volumes {
1383
+ if volume .ID == volumeID {
1384
+ c .Volumes [len (c .Volumes )- 1 ], c .Volumes [i ] = c .Volumes [i ], c .Volumes [len (c .Volumes )- 1 ]
1385
+ c .Volumes = c .Volumes [:len (c .Volumes )- 1 ]
1386
+ break
1387
+ }
1388
+ }
1389
+
1390
+ for i := 0 ; i < len (c .VolumeSnapshots ); i ++ {
1391
+ if c .VolumeSnapshots [i ].VolumeID == volumeID {
1392
+ c .VolumeSnapshots = append (c .VolumeSnapshots [:i ], c .VolumeSnapshots [i + 1 :]... )
1393
+ i --
1394
+ }
1395
+ }
1396
+
1397
+ return & SimpleResponse {Result : "success" }, nil
1398
+ }
1399
+
1400
+ // ListVolumeSnapshots implemented in a fake way for automated tests
1401
+ func (c * FakeClient ) ListVolumeSnapshots () ([]VolumeSnapshot , error ) {
1402
+ return c .VolumeSnapshots , nil
1403
+ }
1404
+
1405
+ // GetVolumeSnapshot implemented in a fake way for automated tests
1406
+ func (c * FakeClient ) GetVolumeSnapshot (snapshotID string ) (* VolumeSnapshot , error ) {
1407
+ for _ , snapshot := range c .VolumeSnapshots {
1408
+ if snapshot .SnapshotID == snapshotID {
1409
+ return & snapshot , nil
1410
+ }
1411
+ }
1412
+
1413
+ err := fmt .Errorf ("unable to find volume snapshot %s, zero matches" , snapshotID )
1414
+ return nil , ZeroMatchesError .wrap (err )
1415
+ }
1416
+
1417
+ // DeleteVolumeSnapshot implemented in a fake way for automated tests
1418
+ func (c * FakeClient ) DeleteVolumeSnapshot (snapshotID string ) (* SimpleResponse , error ) {
1419
+ for i , snapshot := range c .VolumeSnapshots {
1420
+ if snapshot .SnapshotID == snapshotID {
1421
+ c .VolumeSnapshots [len (c .VolumeSnapshots )- 1 ], c .VolumeSnapshots [i ] = c .VolumeSnapshots [i ], c .VolumeSnapshots [len (c .VolumeSnapshots )- 1 ]
1422
+ c .VolumeSnapshots = c .VolumeSnapshots [:len (c .VolumeSnapshots )- 1 ]
1423
+ return & SimpleResponse {Result : "success" }, nil
1424
+ }
1425
+ }
1426
+
1427
+ return & SimpleResponse {Result : "failed" }, nil
1428
+ }
1429
+
1333
1430
// CreateWebhook implemented in a fake way for automated tests
1334
1431
func (c * FakeClient ) CreateWebhook (r * WebhookConfig ) (* Webhook , error ) {
1335
1432
webhook := Webhook {
0 commit comments