add support for tagging snapshots

This commit is contained in:
Cody Baker 2019-03-14 15:52:32 -04:00 committed by Cody Baker
parent 69f334e64b
commit cc58c69571
5 changed files with 17 additions and 9 deletions

View File

@ -37,6 +37,7 @@ type Snapshot struct {
MinDiskSize int `json:"min_disk_size,omitempty"`
SizeGigaBytes float64 `json:"size_gigabytes,omitempty"`
Created string `json:"created_at,omitempty"`
Tags []string `json:"tags,omitempty"`
}
type snapshotRoot struct {

View File

@ -176,10 +176,11 @@ func TestSnapshot_String(t *testing.T) {
MinDiskSize: 20,
SizeGigaBytes: 4.84,
Created: "2013-11-27T09:24:55Z",
Tags: []string{"one", "two"},
}
stringified := snapshot.String()
expected := `godo.Snapshot{ID:"1", Name:"Snapsh176ot", ResourceID:"0", ResourceType:"droplet", Regions:["one"], MinDiskSize:20, SizeGigaBytes:4.84, Created:"2013-11-27T09:24:55Z"}`
expected := `godo.Snapshot{ID:"1", Name:"Snapsh176ot", ResourceID:"0", ResourceType:"droplet", Regions:["one"], MinDiskSize:20, SizeGigaBytes:4.84, Created:"2013-11-27T09:24:55Z", Tags:["one" "two"]}`
if expected != stringified {
t.Errorf("Snapshot.String returned %+v, expected %+v", stringified, expected)
}

View File

@ -175,9 +175,10 @@ func (svc *StorageServiceOp) DeleteVolume(ctx context.Context, id string) (*Resp
// SnapshotCreateRequest represents a request to create a block store
// volume.
type SnapshotCreateRequest struct {
VolumeID string `json:"volume_id"`
Name string `json:"name"`
Description string `json:"description"`
VolumeID string `json:"volume_id"`
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
}
// ListSnapshots lists all snapshots related to a storage volume.

View File

@ -631,6 +631,7 @@ func TestStorageSnapshots_Create(t *testing.T) {
VolumeID: "98d414c6-295e-4e3a-ac58-eb9456c1e1d1",
Name: "my snapshot",
Description: "my description",
Tags: []string{"one", "two"},
}
want := &Snapshot{
@ -639,6 +640,7 @@ func TestStorageSnapshots_Create(t *testing.T) {
Name: "my snapshot",
SizeGigaBytes: 100,
Created: "2002-10-02T15:00:00.05Z",
Tags: []string{"one", "two"},
}
jBlob := `{
"snapshot":{
@ -647,7 +649,8 @@ func TestStorageSnapshots_Create(t *testing.T) {
"name": "my snapshot",
"description": "my description",
"size_gigabytes": 100,
"created_at": "2002-10-02T15:00:00.05Z"
"created_at": "2002-10-02T15:00:00.05Z",
"tags": ["one", "two"]
},
"links": {
"pages": {

10
tags.go
View File

@ -33,14 +33,16 @@ var _ TagsService = &TagsServiceOp{}
type ResourceType string
const (
//DropletResourceType holds the string representing our ResourceType of Droplet.
// DropletResourceType holds the string representing our ResourceType of Droplet.
DropletResourceType ResourceType = "droplet"
//ImageResourceType holds the string representing our ResourceType of Image.
// ImageResourceType holds the string representing our ResourceType of Image.
ImageResourceType ResourceType = "image"
//VolumeResourceType holds the string representing our ResourceType of Volume.
// VolumeResourceType holds the string representing our ResourceType of Volume.
VolumeResourceType ResourceType = "volume"
//LoadBalancerResourceType holds the string representing our ResourceType of LoadBalancer.
// LoadBalancerResourceType holds the string representing our ResourceType of LoadBalancer.
LoadBalancerResourceType ResourceType = "load_balancer"
// VolumeSnapshotResourceType holds the string representing our ResourceType for storage Snapshots.
VolumeSnapshotResourceType ResourceType = "volumesnapshot"
)
// Resource represent a single resource for associating/disassociating with tags