Skip to content

Commit

Permalink
iaas/digitalocean: fix tests with delete wait
Browse files Browse the repository at this point in the history
(cherry picked from commit 11ceda4)
  • Loading branch information
cezarsa committed May 4, 2017
1 parent 6e340b2 commit 5bcdac1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions iaas/digitalocean/iaas.go
Expand Up @@ -152,7 +152,7 @@ func (i *digitalOceanIaas) DeleteMachine(m *iaas.Machine) error {
// PowerOff force the shutdown
action, _, err = i.client.DropletActions.PowerOff(context.Background(), machineId)
if err != nil {
return err
return errors.WithStack(err)
}
}
u, _ := i.base.GetConfigString("url")
Expand All @@ -161,11 +161,11 @@ func (i *digitalOceanIaas) DeleteMachine(m *iaas.Machine) error {
defer cancel()
err = util.WaitForActive(ctx, i.client, uri)
if err != nil {
return err
return errors.WithStack(err)
}
resp, err := i.client.Droplets.Delete(context.Background(), machineId)
if err != nil {
return err
return errors.WithStack(err)
}
if resp.StatusCode != 204 {
return errors.New("failed to delete machine")
Expand Down
8 changes: 7 additions & 1 deletion iaas/digitalocean/iaas_test.go
Expand Up @@ -122,13 +122,16 @@ func (s *digitaloceanSuite) TestDeleteMachine(c *check.C) {
if r.URL.Path == "/v2/droplets/503/actions" {
fmt.Fprintln(w, `{"action":{"id": 123456, "status": "in-progress", "started_at": "2014-11-04T17:08:03Z", "resource_id": 503, "resource_type": "droplet"}}`)
}
if r.URL.Path == "/v2/actions/123456" {
fmt.Fprintln(w, `{"action":{"id": 123456, "status": "completed", "started_at": "2014-11-04T17:08:03Z", "resource_id": 503, "resource_type": "droplet"}}`)
}
}))
defer fakeServer.Close()
config.Set("iaas:digitalocean:url", fakeServer.URL)
do := newDigitalOceanIaas("digitalocean")
machine := iaas.Machine{Id: "503", CreationParams: map[string]string{"projectid": "projid"}}
err := do.DeleteMachine(&machine)
c.Assert(err, check.IsNil)
c.Assert(err, check.IsNil, check.Commentf("%+v", err))
}

func (s *digitaloceanSuite) TestDeleteMachineFailure(c *check.C) {
Expand All @@ -140,6 +143,9 @@ func (s *digitaloceanSuite) TestDeleteMachineFailure(c *check.C) {
if r.URL.Path == "/v2/droplets/13/actions" {
fmt.Fprintln(w, `{"action":{"id": 123456, "status": "in-progress", "started_at": "2014-11-04T17:08:03Z", "resource_id": 13, "resource_type": "droplet"}}`)
}
if r.URL.Path == "/v2/actions/123456" {
fmt.Fprintln(w, `{"action":{"id": 123456, "status": "completed", "started_at": "2014-11-04T17:08:03Z", "resource_id": 503, "resource_type": "droplet"}}`)
}
}))
defer fakeServer.Close()
config.Set("iaas:digitalocean:url", fakeServer.URL)
Expand Down

0 comments on commit 5bcdac1

Please sign in to comment.