Skip to content

Commit

Permalink
Add tags for storage volumes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcodybaker committed Mar 13, 2019
1 parent 169afd3 commit 0416126
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
16 changes: 9 additions & 7 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Volume struct {
CreatedAt time.Time `json:"created_at"`
FilesystemType string `json:"filesystem_type"`
FilesystemLabel string `json:"filesystem_label"`
Tags []string `json:"tags"`
}

func (f Volume) String() string {
Expand All @@ -76,13 +77,14 @@ type storageVolumeRoot struct {
// VolumeCreateRequest represents a request to create a block store
// volume.
type VolumeCreateRequest struct {
Region string `json:"region"`
Name string `json:"name"`
Description string `json:"description"`
SizeGigaBytes int64 `json:"size_gigabytes"`
SnapshotID string `json:"snapshot_id"`
FilesystemType string `json:"filesystem_type"`
FilesystemLabel string `json:"filesystem_label"`
Region string `json:"region"`
Name string `json:"name"`
Description string `json:"description"`
SizeGigaBytes int64 `json:"size_gigabytes"`
SnapshotID string `json:"snapshot_id"`
FilesystemType string `json:"filesystem_type"`
FilesystemLabel string `json:"filesystem_label"`
Tags []string `json:"tags"`
}

// ListVolumes lists all storage volumes.
Expand Down
39 changes: 30 additions & 9 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
"droplet_ids": [10],
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "",
"filesystem_label": ""
"filesystem_label": "",
"tags": ["tag1", "tag2"]
},
{
"user_id": 42,
Expand All @@ -37,7 +38,8 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
"size_gigabytes": 100,
"created_at": "2012-10-03T15:00:01.05Z",
"filesystem_type": "ext4",
"filesystem_label": "my-volume"
"filesystem_label": "my-volume",
"tags": []
}
],
"links": {
Expand Down Expand Up @@ -70,6 +72,7 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
SizeGigaBytes: 100,
DropletIDs: []int{10},
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
},
{
Region: &Region{Slug: "nyc3"},
Expand All @@ -80,6 +83,7 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
CreatedAt: time.Date(2012, 10, 03, 15, 00, 01, 50000000, time.UTC),
FilesystemType: "ext4",
FilesystemLabel: "my-volume",
Tags: []string{},
},
}
if !reflect.DeepEqual(volumes, expected) {
Expand All @@ -99,6 +103,7 @@ func TestStorageVolumes_Get(t *testing.T) {
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
FilesystemType: "xfs",
FilesystemLabel: "my-vol",
Tags: []string{"tag1", "tag2"},
}
jBlob := `{
"volume":{
Expand All @@ -110,7 +115,8 @@ func TestStorageVolumes_Get(t *testing.T) {
"size_gigabytes": 100,
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "xfs",
"filesystem_label": "my-vol"
"filesystem_label": "my-vol",
"tags": ["tag1", "tag2"]
},
"links": {
"pages": {
Expand Down Expand Up @@ -153,7 +159,8 @@ func TestStorageVolumes_ListVolumesByName(t *testing.T) {
"droplet_ids": [10],
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "",
"filesystem_label": ""
"filesystem_label": "",
"tags": ["tag1", "tag2"]
}
],
"links": {},
Expand All @@ -171,6 +178,7 @@ func TestStorageVolumes_ListVolumesByName(t *testing.T) {
SizeGigaBytes: 100,
DropletIDs: []int{10},
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
},
}

Expand Down Expand Up @@ -211,7 +219,8 @@ func TestStorageVolumes_ListVolumesByRegion(t *testing.T) {
"droplet_ids": [10],
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "",
"filesystem_label": ""
"filesystem_label": "",
"tags": ["tag1", "tag2"]
}
],
"links": {},
Expand All @@ -229,6 +238,7 @@ func TestStorageVolumes_ListVolumesByRegion(t *testing.T) {
SizeGigaBytes: 100,
DropletIDs: []int{10},
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
},
}

Expand Down Expand Up @@ -269,7 +279,8 @@ func TestStorageVolumes_ListVolumesByNameAndRegion(t *testing.T) {
"droplet_ids": [10],
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "",
"filesystem_label": ""
"filesystem_label": "",
"tags": ["tag1", "tag2"]
}
],
"links": {},
Expand All @@ -287,6 +298,7 @@ func TestStorageVolumes_ListVolumesByNameAndRegion(t *testing.T) {
SizeGigaBytes: 100,
DropletIDs: []int{10},
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
},
}

Expand Down Expand Up @@ -321,6 +333,7 @@ func TestStorageVolumes_Create(t *testing.T) {
Name: "my volume",
Description: "my description",
SizeGigaBytes: 100,
Tags: []string{"tag1", "tag2"},
}

want := &Volume{
Expand All @@ -330,6 +343,7 @@ func TestStorageVolumes_Create(t *testing.T) {
Description: "my description",
SizeGigaBytes: 100,
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
}
jBlob := `{
"volume":{
Expand All @@ -338,7 +352,8 @@ func TestStorageVolumes_Create(t *testing.T) {
"name": "my volume",
"description": "my description",
"size_gigabytes": 100,
"created_at": "2002-10-02T15:00:00.05Z"
"created_at": "2002-10-02T15:00:00.05Z",
"tags": ["tag1", "tag2"]
},
"links": {}
}`
Expand Down Expand Up @@ -377,6 +392,7 @@ func TestStorageVolumes_CreateFormatted(t *testing.T) {
Description: "my description",
SizeGigaBytes: 100,
FilesystemType: "xfs",
Tags: []string{"tag1", "tag2"},
}

want := &Volume{
Expand All @@ -387,6 +403,7 @@ func TestStorageVolumes_CreateFormatted(t *testing.T) {
SizeGigaBytes: 100,
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
FilesystemType: "xfs",
Tags: []string{"tag1", "tag2"},
}
jBlob := `{
"volume":{
Expand All @@ -397,7 +414,8 @@ func TestStorageVolumes_CreateFormatted(t *testing.T) {
"size_gigabytes": 100,
"created_at": "2002-10-02T15:00:00.05Z",
"filesystem_type": "xfs",
"filesystem_label": ""
"filesystem_label": "",
"tags": ["tag1", "tag2"]
},
"links": {}
}`
Expand Down Expand Up @@ -435,6 +453,7 @@ func TestStorageVolumes_CreateFromSnapshot(t *testing.T) {
Description: "my description",
SizeGigaBytes: 100,
SnapshotID: "0d165eff-0b4c-11e7-9093-0242ac110207",
Tags: []string{"tag1", "tag2"},
}

want := &Volume{
Expand All @@ -444,6 +463,7 @@ func TestStorageVolumes_CreateFromSnapshot(t *testing.T) {
Description: "my description",
SizeGigaBytes: 100,
CreatedAt: time.Date(2002, 10, 02, 15, 00, 00, 50000000, time.UTC),
Tags: []string{"tag1", "tag2"},
}
jBlob := `{
"volume":{
Expand All @@ -452,7 +472,8 @@ func TestStorageVolumes_CreateFromSnapshot(t *testing.T) {
"name": "my-volume-from-a-snapshot",
"description": "my description",
"size_gigabytes": 100,
"created_at": "2002-10-02T15:00:00.05Z"
"created_at": "2002-10-02T15:00:00.05Z",
"tags": ["tag1", "tag2"]
},
"links": {}
}`
Expand Down

0 comments on commit 0416126

Please sign in to comment.