Add support for embedded region in actions

This commit is contained in:
Nan Zhong 2015-03-10 09:12:55 -04:00
parent 1a08a979da
commit cdbea5035c
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -3,6 +3,7 @@ package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
@ -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")
})
@ -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) {
@ -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)
}