Skip to content

Commit

Permalink
Use a enum to represent resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
nanzhong committed Mar 22, 2016
1 parent a294b44 commit 960a9c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ type TagsServiceOp struct {

var _ TagsService = &TagsServiceOp{}

// Resource represent a single resource for associating/dissociating with tags
// ResourceType represents a class of resource, currently only droplet are supported
type ResourceType string

const (
DropletResourceType ResourceType = "droplet"
)

// Resource represent a single resource for associating/disassociating with tags
type Resource struct {
ID string `json:"resource_id,omit_empty"`
Type string `json:"resource_type,omit_empty"`
ID string `json:"resource_id,omit_empty"`
Type ResourceType `json:"resource_type,omit_empty"`
}

// TaggedResources represent the set of resources a tag is attached to
Expand Down
4 changes: 2 additions & 2 deletions tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestTags_TagResource(t *testing.T) {
defer teardown()

tagResourcesRequest := &TagResourcesRequest{
Resources: []Resource{{ID: "1", Type: "droplet"}},
Resources: []Resource{{ID: "1", Type: DropletResourceType}},
}

mux.HandleFunc("/v2/tags/testing-1/resources", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestTags_UntagResource(t *testing.T) {
defer teardown()

untagResourcesRequest := &UntagResourcesRequest{
Resources: []Resource{{ID: "1", Type: "droplet"}},
Resources: []Resource{{ID: "1", Type: DropletResourceType}},
}

mux.HandleFunc("/v2/tags/testing-1/resources", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 960a9c9

Please sign in to comment.