Skip to content

Commit

Permalink
add snapshot compressed size (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamclaughlin committed Sep 27, 2021
1 parent 257ee7d commit d662021
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
15 changes: 8 additions & 7 deletions snapshot.go
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
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

0 comments on commit d662021

Please sign in to comment.