Skip to content

Commit

Permalink
Add /v2/volumetypes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fulviodenza committed Sep 20, 2024
1 parent 6af71f6 commit 320223f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestListVolumes(t *testing.T) {
"openstack_id": "null",
"size_gb": 25,
"bootable": false
}]`,
}]`,
})
defer server.Close()
got, err := client.ListVolumes()
Expand Down
31 changes: 31 additions & 0 deletions volumetype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package civogo

import (
"encoding/json"
"fmt"
)

// VolumeType represent the storage class related to a volume
// https://www.civo.com/api/volumes
type VolumeType struct {
Name string `json:"name"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Labels []string `json:"labels"`
}

// ListVolumeTypes returns a page of Instances owned by the calling API account
func (c *Client) ListVolumeTypes() ([]VolumeType, error) {
resp, err := c.SendGetRequest("/v2/volumetypes")
if err != nil {
return nil, err
}

volumeTypes := make([]VolumeType, 0)
fmt.Println(string(resp))
if err := json.Unmarshal(resp, &volumeTypes); err != nil {
return nil, err
}

return volumeTypes, nil
}
35 changes: 35 additions & 0 deletions volumetype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package civogo

import (
"reflect"
"testing"
)

func TestListVolumeTypes(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/volumetypes": `[{
"name": "my-volume-type",
"description": "a volume type",
"enabled": true,
"labels": ["label"]
}]`,
})
defer server.Close()

got, err := client.ListVolumeTypes()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}

expected := []VolumeType{{
Name: "my-volume-type",
Description: "a volume type",
Enabled: true,
Labels: []string{"label"},
}}

if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected %+v, got %+v", expected, got)
}
}

0 comments on commit 320223f

Please sign in to comment.