Skip to content

Commit

Permalink
Merge pull request digitalocean#5 from digitalocean/bug/droplet-creat…
Browse files Browse the repository at this point in the history
…e-no-actions

Links aren't added to droplet create response
  • Loading branch information
bryanl committed Sep 10, 2014
2 parents db6b5a6 + 09b1d31 commit ed61c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions droplets.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func (s *DropletsServiceOp) Create(createRequest *DropletCreateRequest) (*Drople
if err != nil {
return nil, resp, err
}
if l := root.Links; l != nil {
resp.Links = l
}

return root, resp, err
}
Expand Down
13 changes: 8 additions & 5 deletions droplets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,20 @@ func TestDroplets_Create(t *testing.T) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest)
}

fmt.Fprintf(w, `{"droplet":{"id":1}}`)
fmt.Fprintf(w, `{"droplet":{"id":1}, "links":{"actions": [{"id": 1, "href": "http://example.com", "rel": "create"}]}}`)
})

droplet, _, err := client.Droplets.Create(createRequest)
root, resp, err := client.Droplets.Create(createRequest)
if err != nil {
t.Errorf("Droplets.Create returned error: %v", err)
}

expected := &DropletRoot{Droplet: &Droplet{ID: 1}}
if !reflect.DeepEqual(droplet, expected) {
t.Errorf("Droplets.Create returned %+v, expected %+v", droplet, expected)
if id := root.Droplet.ID; id != 1 {
t.Errorf("expected id '%d', received '%d'", 1, id)
}

if a := resp.Links.Actions[0]; a.ID != 1 {
t.Errorf("expected action id '%d', received '%d'", 1, a.ID)
}
}

Expand Down

0 comments on commit ed61c08

Please sign in to comment.