Add support for embedded region in actions
This commit is contained in:
parent
1a08a979da
commit
cdbea5035c
|
@ -43,6 +43,8 @@ type Action struct {
|
||||||
CompletedAt *Timestamp `json:"completed_at"`
|
CompletedAt *Timestamp `json:"completed_at"`
|
||||||
ResourceID int `json:"resource_id"`
|
ResourceID int `json:"resource_id"`
|
||||||
ResourceType string `json:"resource_type"`
|
ResourceType string `json:"resource_type"`
|
||||||
|
Region *Region `json:"region,omitempty"`
|
||||||
|
RegionSlug string `json:"region_slug,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all actions
|
// List all actions
|
||||||
|
|
|
@ -3,6 +3,7 @@ package godo
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -86,7 +87,7 @@ func TestAction_Get(t *testing.T) {
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
mux.HandleFunc("/v2/actions/12345", func(w http.ResponseWriter, r *http.Request) {
|
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")
|
testMethod(t, r, "GET")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -98,6 +99,21 @@ func TestAction_Get(t *testing.T) {
|
||||||
if action.ID != 12345 {
|
if action.ID != 12345 {
|
||||||
t.Fatalf("unexpected response")
|
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) {
|
func TestAction_String(t *testing.T) {
|
||||||
|
@ -119,7 +135,7 @@ func TestAction_String(t *testing.T) {
|
||||||
stringified := action.String()
|
stringified := action.String()
|
||||||
expected := `godo.Action{ID:1, Status:"in-progress", Type:"transfer", ` +
|
expected := `godo.Action{ID:1, Status:"in-progress", Type:"transfer", ` +
|
||||||
`StartedAt:godo.Timestamp{2014-05-08 20:36:47 +0000 UTC}, ` +
|
`StartedAt:godo.Timestamp{2014-05-08 20:36:47 +0000 UTC}, ` +
|
||||||
`ResourceID:0, ResourceType:""}`
|
`ResourceID:0, ResourceType:"", RegionSlug:""}`
|
||||||
if expected != stringified {
|
if expected != stringified {
|
||||||
t.Errorf("Action.Stringify returned %+v, expected %+v", stringified, expected)
|
t.Errorf("Action.Stringify returned %+v, expected %+v", stringified, expected)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue