Skip to content

Commit

Permalink
Merge pull request digitalocean#28 from digitalocean/feature/embedded…
Browse files Browse the repository at this point in the history
…-region

Add support for embedded region in actions
  • Loading branch information
phillbaker committed Mar 20, 2015
2 parents 51284f6 + cdbea50 commit 2973bd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Action struct {
CompletedAt *Timestamp `json:"completed_at"`
ResourceID int `json:"resource_id"`
ResourceType string `json:"resource_type"`
Region *Region `json:"region,omitempty"`
RegionSlug string `json:"region_slug,omitempty"`
}

// List all actions
Expand Down
20 changes: 18 additions & 2 deletions action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func TestAction_Get(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/actions/12345", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"action": {"id":12345}}`)
fmt.Fprint(w, `{"action": {"id":12345,"region":{"name":"name","slug":"slug","available":true,"sizes":["512mb"],"features":["virtio"]},"region_slug":"slug"}}`)
testMethod(t, r, "GET")
})

Expand All @@ -98,6 +99,21 @@ func TestAction_Get(t *testing.T) {
if action.ID != 12345 {
t.Fatalf("unexpected response")
}

region := &Region{
Name: "name",
Slug: "slug",
Available: true,
Sizes: []string{"512mb"},
Features: []string{"virtio"},
}
if !reflect.DeepEqual(action.Region, region) {
t.Fatalf("unexpected response, invalid region")
}

if action.RegionSlug != "slug" {
t.Fatalf("unexpected response, invalid region slug")
}
}

func TestAction_String(t *testing.T) {
Expand All @@ -119,7 +135,7 @@ func TestAction_String(t *testing.T) {
stringified := action.String()
expected := `godo.Action{ID:1, Status:"in-progress", Type:"transfer", ` +
`StartedAt:godo.Timestamp{2014-05-08 20:36:47 +0000 UTC}, ` +
`ResourceID:0, ResourceType:""}`
`ResourceID:0, ResourceType:"", RegionSlug:""}`
if expected != stringified {
t.Errorf("Action.Stringify returned %+v, expected %+v", stringified, expected)
}
Expand Down

0 comments on commit 2973bd3

Please sign in to comment.