-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6af71f6
commit 320223f
Showing
3 changed files
with
67 additions
and
1 deletion.
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
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 | ||
} |
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,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) | ||
} | ||
} |