-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathvolume_snapshot_test.go
106 lines (92 loc) · 2.64 KB
/
volume_snapshot_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package civogo
import (
"reflect"
"testing"
)
func TestListVolumeSnapshots(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/snapshots?region=TEST&resource_type=volume": `[{
"name": "test-snapshot",
"snapshot_id": "12345",
"snapshot_description": "snapshot for test",
"volume_id": "12345",
"source_volume_name": "test-volume",
"instance_id": "ins1234",
"restore_size": 20,
"state": "available",
"creation_time": "2020-01-01T00:00:00Z"
}]`,
})
defer server.Close()
got, err := client.ListVolumeSnapshots()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := []VolumeSnapshot{
{
Name: "test-snapshot",
SnapshotID: "12345",
SnapshotDescription: "snapshot for test",
VolumeID: "12345",
SourceVolumeName: "test-volume",
InstanceID: "ins1234",
RestoreSize: 20,
State: "available",
CreationTime: "2020-01-01T00:00:00Z",
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestGetVolumeSnapshot(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/snapshots/snapshot-uuid?region=TEST&resource_type=volume": `{
"name": "test-snapshot",
"snapshot_id": "snapshot-uuid",
"snapshot_description": "snapshot for testing",
"volume_id": "12345",
"source_volume_name": "test-volume",
"instance_id": "ins1234",
"restore_size": 20,
"state": "available",
"creation_time": "2020-01-01T00:00:00Z"
}`,
})
defer server.Close()
got, err := client.GetVolumeSnapshot("snapshot-uuid")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := VolumeSnapshot{
Name: "test-snapshot",
SnapshotID: "snapshot-uuid",
SnapshotDescription: "snapshot for testing",
VolumeID: "12345",
SourceVolumeName: "test-volume",
InstanceID: "ins1234",
RestoreSize: 20,
State: "available",
CreationTime: "2020-01-01T00:00:00Z",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}
func TestDeleteVolumeSnapshot(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/snapshots/12346": `{"result": "success"}`,
})
defer server.Close()
got, err := client.DeleteVolumeSnapshot("12346")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
expected := &SimpleResponse{Result: "success"}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}