From cdbea5035c6996168b1d80e8cc1de4a5ee8673c1 Mon Sep 17 00:00:00 2001 From: Nan Zhong Date: Tue, 10 Mar 2015 09:12:55 -0400 Subject: [PATCH] Add support for embedded region in actions --- action.go | 2 ++ action_test.go | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/action.go b/action.go index ff7298fe..ad8521e6 100644 --- a/action.go +++ b/action.go @@ -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 diff --git a/action_test.go b/action_test.go index 501236e0..3126f8d3 100644 --- a/action_test.go +++ b/action_test.go @@ -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) }