From 04161265d0d7f310a87c4c1f950c3fb76e032a94 Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Fri, 8 Mar 2019 16:30:07 -0500 Subject: [PATCH] Add tags for storage volumes. --- storage.go | 16 +++++++++------- storage_test.go | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/storage.go b/storage.go index a79332a7..88fd8a40 100644 --- a/storage.go +++ b/storage.go @@ -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 { @@ -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. diff --git a/storage_test.go b/storage_test.go index ffe9545c..8f753f4e 100644 --- a/storage_test.go +++ b/storage_test.go @@ -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, @@ -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": { @@ -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"}, @@ -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) { @@ -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":{ @@ -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": { @@ -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": {}, @@ -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"}, }, } @@ -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": {}, @@ -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"}, }, } @@ -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": {}, @@ -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"}, }, } @@ -321,6 +333,7 @@ func TestStorageVolumes_Create(t *testing.T) { Name: "my volume", Description: "my description", SizeGigaBytes: 100, + Tags: []string{"tag1", "tag2"}, } want := &Volume{ @@ -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":{ @@ -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": {} }` @@ -377,6 +392,7 @@ func TestStorageVolumes_CreateFormatted(t *testing.T) { Description: "my description", SizeGigaBytes: 100, FilesystemType: "xfs", + Tags: []string{"tag1", "tag2"}, } want := &Volume{ @@ -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":{ @@ -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": {} }` @@ -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{ @@ -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":{ @@ -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": {} }`