2014-09-03 14:03:30 +00:00
|
|
|
package godo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDropletActions_Shutdown(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "shutdown",
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Shutdown(ctx, 1)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.Shutdown returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.Shutdown returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletActions_ShutdownByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "shutdown",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.ShutdownByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.ShutdownByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.ShutdownByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.ShutdownByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 14:03:30 +00:00
|
|
|
func TestDropletAction_PowerOff(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "power_off",
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerOff(ctx, 1)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.PowerOff returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Poweroff returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_PowerOffByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "power_off",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.PowerOffByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerOffByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.PowerOffByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.PoweroffByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 07:41:48 +00:00
|
|
|
func TestDropletAction_PowerOn(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "power_on",
|
2014-09-18 07:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-18 07:41:48 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-18 07:41:48 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerOn(ctx, 1)
|
2014-09-18 07:41:48 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_PowerOnByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "power_on",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.PowerOnByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerOnByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.PowerOnByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.PowerOnByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
func TestDropletAction_Reboot(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "reboot",
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Reboot(ctx, 1)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Reboot returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Reboot returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_Restore(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "restore",
|
|
|
|
"image": float64(1),
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Restore(ctx, 1, 1)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Restore returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Restore returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_Resize(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "resize",
|
|
|
|
"size": "1024mb",
|
2015-03-07 20:07:46 +00:00
|
|
|
"disk": true,
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Resize(ctx, 1, "1024mb", true)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Resize returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Resize returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_Rename(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "rename",
|
|
|
|
"name": "Droplet-Name",
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Rename(ctx, 1, "Droplet-Name")
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Rename returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.Rename returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_PowerCycle(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
2014-11-12 09:03:19 +00:00
|
|
|
"type": "power_cycle",
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-03 14:03:30 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-03 14:03:30 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerCycle(ctx, 1)
|
2014-09-03 14:03:30 +00:00
|
|
|
if err != nil {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.PowerCycle returned error: %v", err)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
2014-11-12 09:09:13 +00:00
|
|
|
t.Errorf("DropletActions.PowerCycle returned %+v, expected %+v", action, expected)
|
2014-09-03 14:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_PowerCycleByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "power_cycle",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.PowerCycleByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PowerCycleByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.PowerCycleByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.PowerCycleByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 03:52:15 +00:00
|
|
|
func TestDropletAction_Snapshot(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "snapshot",
|
|
|
|
"name": "Image-Name",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
2015-03-21 19:17:47 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
2014-09-05 03:52:15 +00:00
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2014-09-05 03:52:15 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Snapshot(ctx, 1, "Image-Name")
|
2014-09-05 03:52:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.Snapshot returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.Snapshot returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
2015-02-20 04:08:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_SnapshotByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "snapshot",
|
|
|
|
"name": "Image-Name",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.SnapshotByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.SnapshotByTag(ctx, "testing-1", "Image-Name")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.SnapshotByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.SnapshotByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 00:02:24 +00:00
|
|
|
func TestDropletAction_EnableBackups(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_backups",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-11-06 00:02:24 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnableBackups(ctx, 1)
|
2015-11-06 00:02:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnableBackups returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnableBackups returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_EnableBackupsByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_backups",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.EnableBackupByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnableBackupsByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnableBackupsByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnableBackupsByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:16:35 +00:00
|
|
|
func TestDropletAction_DisableBackups(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "disable_backups",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.DisableBackups(ctx, 1)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.DisableBackups returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.DisableBackups returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_DisableBackupsByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "disable_backups",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.DisableBackupsByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.DisableBackupsByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.DisableBackupsByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.DisableBackupsByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:16:35 +00:00
|
|
|
func TestDropletAction_PasswordReset(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "password_reset",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.PasswordReset(ctx, 1)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.PasswordReset returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.PasswordReset returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_RebuildByImageID(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "rebuild",
|
|
|
|
"image": float64(2),
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = \n%#v, expected \n%#v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.RebuildByImageID(ctx, 1, 2)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.RebuildByImageID returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.RebuildByImageID returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_RebuildByImageSlug(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "rebuild",
|
|
|
|
"image": "Image-Name",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.RebuildByImageSlug(ctx, 1, "Image-Name")
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.RebuildByImageSlug returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.RebuildByImageSlug returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_ChangeKernel(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "change_kernel",
|
|
|
|
"kernel": float64(2),
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.ChangeKernel(ctx, 1, 2)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.ChangeKernel returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.ChangeKernel returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDropletAction_EnableIPv6(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_ipv6",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnableIPv6(ctx, 1)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnableIPv6 returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnableIPv6 returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_EnableIPv6ByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_ipv6",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.EnableIPv6ByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnableIPv6ByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnableIPv6ByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnableIPv6byTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 20:16:35 +00:00
|
|
|
func TestDropletAction_EnablePrivateNetworking(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_private_networking",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/1/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2015-04-21 20:16:35 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnablePrivateNetworking(ctx, 1)
|
2015-04-21 20:16:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnablePrivateNetworking returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnablePrivateNetworking returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 05:45:16 +00:00
|
|
|
func TestDropletAction_EnablePrivateNetworkingByTag(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
request := &ActionRequest{
|
|
|
|
"type": "enable_private_networking",
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/actions", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Query().Get("tag_name") != "testing-1" {
|
|
|
|
t.Errorf("DropletActions.EnablePrivateNetworkingByTag did not request with a tag parameter")
|
|
|
|
}
|
|
|
|
|
|
|
|
v := new(ActionRequest)
|
|
|
|
err := json.NewDecoder(r.Body).Decode(v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("decode json: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodPost)
|
2016-03-17 05:45:16 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(v, request) {
|
|
|
|
t.Errorf("Request body = %+v, expected %+v", v, request)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
fmt.Fprint(w, `{"actions": [{"status":"in-progress"},{"status":"in-progress"}]}`)
|
2016-03-17 05:45:16 +00:00
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.EnablePrivateNetworkingByTag(ctx, "testing-1")
|
2016-03-17 05:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.EnablePrivateNetworkingByTag returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-04-29 21:08:00 +00:00
|
|
|
expected := []Action{{Status: "in-progress"}, {Status: "in-progress"}}
|
2016-03-17 05:45:16 +00:00
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.EnablePrivateNetworkingByTag returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:08:08 +00:00
|
|
|
func TestDropletActions_Get(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
mux.HandleFunc("/v2/droplets/123/actions/456", func(w http.ResponseWriter, r *http.Request) {
|
2017-07-02 11:55:56 +00:00
|
|
|
testMethod(t, r, http.MethodGet)
|
2015-02-20 04:08:08 +00:00
|
|
|
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
|
|
|
|
})
|
|
|
|
|
2016-11-29 02:42:23 +00:00
|
|
|
action, _, err := client.DropletActions.Get(ctx, 123, 456)
|
2015-02-20 04:08:08 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("DropletActions.Get returned error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Action{Status: "in-progress"}
|
|
|
|
if !reflect.DeepEqual(action, expected) {
|
|
|
|
t.Errorf("DropletActions.Get returned %+v, expected %+v", action, expected)
|
|
|
|
}
|
2015-03-07 20:07:46 +00:00
|
|
|
}
|