Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add snapshot compressed size #162

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ type SnapshotServiceHandler struct {

// Snapshot represents a Vultr snapshot
type Snapshot struct {
ID string `json:"id"`
DateCreated string `json:"date_created"`
Description string `json:"description"`
Size int `json:"size"`
Status string `json:"status"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ID string `json:"id"`
DateCreated string `json:"date_created"`
Description string `json:"description"`
Size int `json:"size"`
CompressedSize int `json:"compressed_size"`
Status string `json:"status"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
}

// SnapshotReq struct is used to create snapshots.
Expand Down
68 changes: 36 additions & 32 deletions snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestSnapshotServiceHandler_Create(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/snapshots", func(writer http.ResponseWriter, request *http.Request) {
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"status": "complete","os_id": 127,"app_id": 0}}`
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"compressed_size": 1078864689,"status": "complete","os_id": 127,"app_id": 0}}`
fmt.Fprint(writer, response)
})

Expand All @@ -27,13 +27,14 @@ func TestSnapshotServiceHandler_Create(t *testing.T) {
}

expected := &Snapshot{
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
Status: "complete",
OsID: 127,
AppID: 0,
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
CompressedSize: 1078864689,
Status: "complete",
OsID: 127,
AppID: 0,
}

if !reflect.DeepEqual(snapshot, expected) {
Expand All @@ -46,7 +47,7 @@ func TestSnapshotServiceHandler_CreateFromURL(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/snapshots/create-from-url", func(writer http.ResponseWriter, request *http.Request) {
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"status": "complete","os_id": 127,"app_id": 0}}`
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"compressed_size" : 1078864689,"status": "complete","os_id": 127,"app_id": 0}}`
fmt.Fprint(writer, response)
})
snap := SnapshotURLReq{URL: "http://vultr.com"}
Expand All @@ -56,13 +57,14 @@ func TestSnapshotServiceHandler_CreateFromURL(t *testing.T) {
}

expected := &Snapshot{
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
Status: "complete",
OsID: 127,
AppID: 0,
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
CompressedSize: 1078864689,
Status: "complete",
OsID: 127,
AppID: 0,
}

if !reflect.DeepEqual(snapshot, expected) {
Expand All @@ -75,7 +77,7 @@ func TestSnapshotServiceHandler_Get(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/snapshots/5359435d28b9a", func(writer http.ResponseWriter, request *http.Request) {
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"status": "complete","os_id": 127,"app_id": 0}}`
response := `{"snapshot":{"id": "5359435d28b9a","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"compressed_size": 1078864689,"status": "complete","os_id": 127,"app_id": 0}}`
fmt.Fprint(writer, response)
})

Expand All @@ -85,13 +87,14 @@ func TestSnapshotServiceHandler_Get(t *testing.T) {
}

expected := &Snapshot{
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
Status: "complete",
OsID: 127,
AppID: 0,
ID: "5359435d28b9a",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
CompressedSize: 1078864689,
Status: "complete",
OsID: 127,
AppID: 0,
}

if !reflect.DeepEqual(snapshot, expected) {
Expand Down Expand Up @@ -119,7 +122,7 @@ func TestSnapshotServiceHandler_List(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/snapshots", func(writer http.ResponseWriter, request *http.Request) {
response := `{"snapshots": [{"id": "885ee0f4f263c","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"status": "complete","os_id": 127,"app_id": 0}],"meta": {"total": 4,"links": {"next": "","prev": ""}}}`
response := `{"snapshots": [{"id": "885ee0f4f263c","date_created": "2014-04-18 12:40:40","description": "Test snapshot","size": 42949672960,"compressed_size": 1078864689,"status": "complete","os_id": 127,"app_id": 0}],"meta": {"total": 4,"links": {"next": "","prev": ""}}}`
fmt.Fprint(writer, response)
})

Expand All @@ -130,13 +133,14 @@ func TestSnapshotServiceHandler_List(t *testing.T) {

expectedSnap := []Snapshot{
{
ID: "885ee0f4f263c",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
Status: "complete",
OsID: 127,
AppID: 0,
ID: "885ee0f4f263c",
DateCreated: "2014-04-18 12:40:40",
Description: "Test snapshot",
Size: 42949672960,
CompressedSize: 1078864689,
Status: "complete",
OsID: 127,
AppID: 0,
},
}

Expand Down