Skip to content

Commit

Permalink
Merge branch 'nitrous-io-add-poweron'
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanl committed Sep 19, 2014
2 parents ed61c08 + c2a4a75 commit 0a9eb5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions droplet_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type DropletActionsService interface {
Shutdown(int) (*Action, *Response, error)
PowerOff(int) (*Action, *Response, error)
PowerOn(int) (*Action, *Response, error)
PowerCycle(int) (*Action, *Response, error)
Reboot(int) (*Action, *Response, error)
Restore(int, int) (*Action, *Response, error)
Expand Down Expand Up @@ -39,6 +40,12 @@ func (s *DropletActionsServiceOp) PowerOff(id int) (*Action, *Response, error) {
return s.doAction(id, request)
}

// PowerOn a Droplet
func (s *DropletActionsServiceOp) PowerOn(id int) (*Action, *Response, error) {
request := &ActionRequest{Type: "power_on"}
return s.doAction(id, request)
}

// PowerCycle a Droplet
func (s *DropletActionsServiceOp) PowerCycle(id int) (*Action, *Response, error) {
request := &ActionRequest{Type: "power_cycle"}
Expand Down
31 changes: 31 additions & 0 deletions droplet_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,37 @@ func TestDropletAction_PowerOff(t *testing.T) {
}
}

func TestDropletAction_PowerOn(t *testing.T) {
setup()
defer teardown()

request := &ActionRequest{
Type: "power_on",
}

mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
v := new(ActionRequest)
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")
if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request)
}

fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
})

action, _, err := client.DropletActions.PowerOn(1)
if err != nil {
t.Errorf("DropletActions.PowerOn returned error: %v", err)
}

expected := &Action{Status: "in-progress"}
if !reflect.DeepEqual(action, expected) {
t.Errorf("DropletActions.PowerOn returned %+v, expected %+v", action, expected)
}
}

func TestDropletAction_Reboot(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 0a9eb5a

Please sign in to comment.