@@ -260,3 +260,124 @@ func TestResizeVolume(t *testing.T) {
260
260
t .Errorf ("Expected %+v, got %+v" , expected , got )
261
261
}
262
262
}
263
+
264
+ func TestCreateVolumeSnapshot (t * testing.T ) {
265
+ client , server , _ := NewClientForTesting (map [string ]string {
266
+ "/v2/volumes/12346/snapshot" : `{
267
+ "snapshot_id": "12345",
268
+ "name": "test-snapshot",
269
+ "snapshot_description": "snapshot for testing",
270
+ "volume_id": "12346",
271
+ "state": "available",
272
+ "creation_time": "2020-01-01T00:00:00Z"
273
+ }` ,
274
+ })
275
+ defer server .Close ()
276
+ cfg := & VolumeSnapshotConfig {Name : "my-snapshot" }
277
+ got , err := client .CreateVolumeSnapshot ("12346" , cfg )
278
+ if err != nil {
279
+ t .Errorf ("Request returned an error: %s" , err )
280
+ return
281
+ }
282
+
283
+ expected := & VolumeSnapshot {
284
+ SnapshotID : "12345" ,
285
+ Name : "test-snapshot" ,
286
+ SnapshotDescription : "snapshot for testing" ,
287
+ VolumeID : "12346" ,
288
+ State : "available" ,
289
+ CreationTime : "2020-01-01T00:00:00Z" ,
290
+ }
291
+ if ! reflect .DeepEqual (got , expected ) {
292
+ t .Errorf ("Expected %+v, got %+v" , expected , got )
293
+ }
294
+ }
295
+
296
+ func TestGetVolumeSnapshotByVolumeID (t * testing.T ) {
297
+ client , server , _ := NewClientForTesting (map [string ]string {
298
+ "/v2/volumes/12346/snapshot/12345" : `{
299
+ "snapshot_id": "12345",
300
+ "name": "test-snapshot",
301
+ "snapshot_description": "snapshot for testing",
302
+ "volume_id": "12346",
303
+ "state": "available",
304
+ "creation_time": "2020-01-01T00:00:00Z"
305
+ }` ,
306
+ })
307
+ defer server .Close ()
308
+
309
+ got , err := client .GetVolumeSnapshotByVolumeID ("12346" , "12345" )
310
+ if err != nil {
311
+ t .Errorf ("Request returned an error: %s" , err )
312
+ return
313
+ }
314
+
315
+ expected := VolumeSnapshot {
316
+ SnapshotID : "12345" ,
317
+ Name : "test-snapshot" ,
318
+ SnapshotDescription : "snapshot for testing" ,
319
+ VolumeID : "12346" ,
320
+ State : "available" ,
321
+ CreationTime : "2020-01-01T00:00:00Z" ,
322
+ }
323
+
324
+ if ! reflect .DeepEqual (got , expected ) {
325
+ t .Errorf ("Expected %+v, got %+v" , expected , got )
326
+ }
327
+ }
328
+
329
+ func TestListVolumeSnapshotsByVolumeID (t * testing.T ) {
330
+ client , server , _ := NewClientForTesting (map [string ]string {
331
+ "/v2/volumes/12346/snapshots" : `[{
332
+ "snapshot_id": "12345",
333
+ "name": "test-snapshot",
334
+ "snapshot_description": "snapshot for testing",
335
+ "volume_id": "12346",
336
+ "state": "available",
337
+ "creation_time": "2020-01-01T00:00:00Z"
338
+ }]` ,
339
+ })
340
+ defer server .Close ()
341
+
342
+ got , err := client .ListVolumeSnapshotsByVolumeID ("12346" )
343
+ if err != nil {
344
+ t .Errorf ("Request returned an error: %s" , err )
345
+ return
346
+ }
347
+
348
+ expected := []VolumeSnapshot {
349
+ {
350
+ SnapshotID : "12345" ,
351
+ Name : "test-snapshot" ,
352
+ SnapshotDescription : "snapshot for testing" ,
353
+ VolumeID : "12346" ,
354
+ State : "available" ,
355
+ CreationTime : "2020-01-01T00:00:00Z" ,
356
+ },
357
+ }
358
+
359
+ if ! reflect .DeepEqual (got , expected ) {
360
+ t .Errorf ("Expected %+v, got %+v" , expected , got )
361
+ }
362
+ }
363
+
364
+ func TestDeleteVolumeAndAllSnapshot (t * testing.T ) {
365
+ client , server , _ := NewClientForTesting (map [string ]string {
366
+ "/v2/volumes/12346?delete_snapshot=true" : `{"result": "success"}` ,
367
+ })
368
+ defer server .Close ()
369
+
370
+ got , err := client .DeleteVolumeAndAllSnapshot ("12346" )
371
+ if err != nil {
372
+ t .Errorf ("Request returned an error: %s" , err )
373
+ return
374
+ }
375
+
376
+ expected := & SimpleResponse {
377
+ Result : "success" ,
378
+ }
379
+
380
+ if ! reflect .DeepEqual (got , expected ) {
381
+ t .Errorf ("Expected %+v, got %+v" , expected , got )
382
+ }
383
+ }
0 commit comments