-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for volume snapshot endpoints
- Loading branch information
1 parent
1e6a79a
commit 2ffdc71
Showing
4 changed files
with
221 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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", | ||
"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", | ||
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", | ||
"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", | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters