use http.MethodX instead of "GET"/"POST"/"DELETE"

This commit is contained in:
Guus van Weelden 2017-07-02 13:55:56 +02:00
parent 4fa9e9d999
commit 9e24e26f6b
39 changed files with 277 additions and 247 deletions

View File

@ -1,6 +1,10 @@
package godo package godo
import "github.com/digitalocean/godo/context" import (
"net/http"
"github.com/digitalocean/godo/context"
)
// AccountService is an interface for interfacing with the Account // AccountService is an interface for interfacing with the Account
// endpoints of the DigitalOcean API // endpoints of the DigitalOcean API
@ -41,7 +45,7 @@ func (s *AccountServiceOp) Get(ctx context.Context) (*Account, *Response, error)
path := "v2/account" path := "v2/account"
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -12,7 +12,7 @@ func TestAccountGet(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
response := ` response := `
{ "account": { { "account": {

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -61,7 +62,7 @@ func (s *ActionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Action
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -85,7 +86,7 @@ func (s *ActionsServiceOp) Get(ctx context.Context, id int) (*Action, *Response,
} }
path := fmt.Sprintf("%s/%d", actionsBasePath, id) path := fmt.Sprintf("%s/%d", actionsBasePath, id)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -14,7 +14,7 @@ func TestAction_List(t *testing.T) {
mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}]}`)
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
}) })
actions, _, err := client.Actions.List(ctx, nil) actions, _, err := client.Actions.List(ctx, nil)
@ -34,7 +34,7 @@ func TestAction_ListActionMultiplePages(t *testing.T) {
mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/droplets/?page=2"}}}`) fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/droplets/?page=2"}}}`)
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
}) })
_, resp, err := client.Actions.List(ctx, nil) _, resp, err := client.Actions.List(ctx, nil)
@ -63,7 +63,7 @@ func TestAction_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -82,7 +82,7 @@ func TestAction_Get(t *testing.T) {
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,"region":{"name":"name","slug":"slug","available":true,"sizes":["512mb"],"features":["virtio"]},"region_slug":"slug"}}`) 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, http.MethodGet)
}) })
action, _, err := client.Actions.Get(ctx, 12345) action, _, err := client.Actions.Get(ctx, 12345)

View File

@ -1,6 +1,7 @@
package godo package godo
import ( import (
"net/http"
"path" "path"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
@ -54,7 +55,7 @@ var _ CertificatesService = &CertificatesServiceOp{}
func (c *CertificatesServiceOp) Get(ctx context.Context, cID string) (*Certificate, *Response, error) { func (c *CertificatesServiceOp) Get(ctx context.Context, cID string) (*Certificate, *Response, error) {
urlStr := path.Join(certificatesBasePath, cID) urlStr := path.Join(certificatesBasePath, cID)
req, err := c.client.NewRequest(ctx, "GET", urlStr, nil) req, err := c.client.NewRequest(ctx, http.MethodGet, urlStr, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -75,7 +76,7 @@ func (c *CertificatesServiceOp) List(ctx context.Context, opt *ListOptions) ([]C
return nil, nil, err return nil, nil, err
} }
req, err := c.client.NewRequest(ctx, "GET", urlStr, nil) req, err := c.client.NewRequest(ctx, http.MethodGet, urlStr, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -94,7 +95,7 @@ func (c *CertificatesServiceOp) List(ctx context.Context, opt *ListOptions) ([]C
// Create a new certificate with provided configuration. // Create a new certificate with provided configuration.
func (c *CertificatesServiceOp) Create(ctx context.Context, cr *CertificateRequest) (*Certificate, *Response, error) { func (c *CertificatesServiceOp) Create(ctx context.Context, cr *CertificateRequest) (*Certificate, *Response, error) {
req, err := c.client.NewRequest(ctx, "POST", certificatesBasePath, cr) req, err := c.client.NewRequest(ctx, http.MethodPost, certificatesBasePath, cr)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -112,7 +113,7 @@ func (c *CertificatesServiceOp) Create(ctx context.Context, cr *CertificateReque
func (c *CertificatesServiceOp) Delete(ctx context.Context, cID string) (*Response, error) { func (c *CertificatesServiceOp) Delete(ctx context.Context, cID string) (*Response, error) {
urlStr := path.Join(certificatesBasePath, cID) urlStr := path.Join(certificatesBasePath, cID)
req, err := c.client.NewRequest(ctx, "DELETE", urlStr, nil) req, err := c.client.NewRequest(ctx, http.MethodDelete, urlStr, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -55,7 +55,7 @@ func TestCertificates_Get(t *testing.T) {
cID := "892071a0-bb95-49bc-8021-3afd67a210bf" cID := "892071a0-bb95-49bc-8021-3afd67a210bf"
urlStr = path.Join(urlStr, cID) urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, certJSONResponse) fmt.Fprint(w, certJSONResponse)
}) })
@ -81,7 +81,7 @@ func TestCertificates_List(t *testing.T) {
urlStr := "/v2/certificates" urlStr := "/v2/certificates"
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, certsJSONResponse) fmt.Fprint(w, certsJSONResponse)
}) })
@ -130,7 +130,7 @@ func TestCertificates_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
assert.Equal(t, createRequest, v) assert.Equal(t, createRequest, v)
fmt.Fprint(w, certJSONResponse) fmt.Fprint(w, certJSONResponse)
@ -160,7 +160,7 @@ func TestCertificates_Delete(t *testing.T) {
urlStr := "/v2/certificates" urlStr := "/v2/certificates"
urlStr = path.Join(urlStr, cID) urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Certificates.Delete(ctx, cID) _, err := client.Certificates.Delete(ctx, cID)

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -101,7 +102,7 @@ func (s DomainsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Domain,
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -126,7 +127,7 @@ func (s *DomainsServiceOp) Get(ctx context.Context, name string) (*Domain, *Resp
path := fmt.Sprintf("%s/%s", domainsBasePath, name) path := fmt.Sprintf("%s/%s", domainsBasePath, name)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -148,7 +149,7 @@ func (s *DomainsServiceOp) Create(ctx context.Context, createRequest *DomainCrea
path := domainsBasePath path := domainsBasePath
req, err := s.client.NewRequest(ctx, "POST", path, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -169,7 +170,7 @@ func (s *DomainsServiceOp) Delete(ctx context.Context, name string) (*Response,
path := fmt.Sprintf("%s/%s", domainsBasePath, name) path := fmt.Sprintf("%s/%s", domainsBasePath, name)
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -201,7 +202,7 @@ func (s *DomainsServiceOp) Records(ctx context.Context, domain string, opt *List
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -230,7 +231,7 @@ func (s *DomainsServiceOp) Record(ctx context.Context, domain string, id int) (*
path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id) path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -256,7 +257,7 @@ func (s *DomainsServiceOp) DeleteRecord(ctx context.Context, domain string, id i
path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id) path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id)
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -313,7 +314,7 @@ func (s *DomainsServiceOp) CreateRecord(ctx context.Context,
} }
path := fmt.Sprintf("%s/%s/records", domainsBasePath, domain) path := fmt.Sprintf("%s/%s/records", domainsBasePath, domain)
req, err := s.client.NewRequest(ctx, "POST", path, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -13,7 +13,7 @@ func TestDomains_ListDomains(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domains": [{"name":"foo.com"},{"name":"bar.com"}]}`) fmt.Fprint(w, `{"domains": [{"name":"foo.com"},{"name":"bar.com"}]}`)
}) })
@ -33,7 +33,7 @@ func TestDomains_ListDomainsMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domains": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/domains/?page=2"}}}`) fmt.Fprint(w, `{"domains": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/domains/?page=2"}}}`)
}) })
@ -63,7 +63,7 @@ func TestDomains_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -81,7 +81,7 @@ func TestDomains_GetDomain(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain":{"name":"example.com"}}`) fmt.Fprint(w, `{"domain":{"name":"example.com"}}`)
}) })
@ -112,7 +112,7 @@ func TestDomains_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -136,7 +136,7 @@ func TestDomains_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Domains.Delete(ctx, "example.com") _, err := client.Domains.Delete(ctx, "example.com")
@ -150,7 +150,7 @@ func TestDomains_AllRecordsForDomainName(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains/example.com/records", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains/example.com/records", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain_records":[{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"domain_records":[{"id":1},{"id":2}]}`)
}) })
@ -195,7 +195,7 @@ func TestDomains_GetRecordforDomainName(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain_record":{"id":1}}`) fmt.Fprint(w, `{"domain_record":{"id":1}}`)
}) })
@ -215,7 +215,7 @@ func TestDomains_DeleteRecordForDomainName(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Domains.DeleteRecord(ctx, "example.com", 1) _, err := client.Domains.DeleteRecord(ctx, "example.com", 1)
@ -247,7 +247,7 @@ func TestDomains_CreateRecordForDomainName(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"net/url" "net/url"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
@ -247,7 +248,7 @@ func (s *DropletActionsServiceOp) doAction(ctx context.Context, id int, request
path := dropletActionPath(id) path := dropletActionPath(id)
req, err := s.client.NewRequest(ctx, "POST", path, request) req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -272,7 +273,7 @@ func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string,
path := dropletActionPathByTag(tag) path := dropletActionPathByTag(tag)
req, err := s.client.NewRequest(ctx, "POST", path, request) req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -312,7 +313,7 @@ func (s *DropletActionsServiceOp) GetByURI(ctx context.Context, rawurl string) (
} }
func (s *DropletActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) { func (s *DropletActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -23,7 +23,7 @@ func TestDropletActions_Shutdown(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -61,7 +61,7 @@ func TestDropletActions_ShutdownByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -95,7 +95,7 @@ func TestDropletAction_PowerOff(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -133,7 +133,7 @@ func TestDropletAction_PowerOffByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -167,7 +167,7 @@ func TestDropletAction_PowerOn(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -205,7 +205,7 @@ func TestDropletAction_PowerOnByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -238,7 +238,7 @@ func TestDropletAction_Reboot(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -274,7 +274,7 @@ func TestDropletAction_Restore(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -312,7 +312,7 @@ func TestDropletAction_Resize(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -349,7 +349,7 @@ func TestDropletAction_Rename(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -384,7 +384,7 @@ func TestDropletAction_PowerCycle(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -423,7 +423,7 @@ func TestDropletAction_PowerCycleByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
} }
@ -458,7 +458,7 @@ func TestDropletAction_Snapshot(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -498,7 +498,7 @@ func TestDropletAction_SnapshotByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -533,7 +533,7 @@ func TestDropletAction_EnableBackups(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -572,7 +572,7 @@ func TestDropletAction_EnableBackupsByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -607,7 +607,7 @@ func TestDropletAction_DisableBackups(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -646,7 +646,7 @@ func TestDropletAction_DisableBackupsByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -681,7 +681,7 @@ func TestDropletAction_PasswordReset(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -717,7 +717,7 @@ func TestDropletAction_RebuildByImageID(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = \n%#v, expected \n%#v", v, request) t.Errorf("Request body = \n%#v, expected \n%#v", v, request)
@ -753,7 +753,7 @@ func TestDropletAction_RebuildByImageSlug(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -789,7 +789,7 @@ func TestDropletAction_ChangeKernel(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -824,7 +824,7 @@ func TestDropletAction_EnableIPv6(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -863,7 +863,7 @@ func TestDropletAction_EnableIPv6ByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -898,7 +898,7 @@ func TestDropletAction_EnablePrivateNetworking(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -937,7 +937,7 @@ func TestDropletAction_EnablePrivateNetworkingByTag(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -972,7 +972,7 @@ func TestDropletAction_Upgrade(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, request) { if !reflect.DeepEqual(v, request) {
t.Errorf("Request body = %+v, expected %+v", v, request) t.Errorf("Request body = %+v, expected %+v", v, request)
@ -997,7 +997,7 @@ func TestDropletActions_Get(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/123/actions/456", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/123/actions/456", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`) fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
}) })

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -275,7 +276,7 @@ func (n NetworkV6) String() string {
// Performs a list request given a path. // Performs a list request given a path.
func (s *DropletsServiceOp) list(ctx context.Context, path string) ([]Droplet, *Response, error) { func (s *DropletsServiceOp) list(ctx context.Context, path string) ([]Droplet, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -322,7 +323,7 @@ func (s *DropletsServiceOp) Get(ctx context.Context, dropletID int) (*Droplet, *
path := fmt.Sprintf("%s/%d", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d", dropletBasePath, dropletID)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -344,7 +345,7 @@ func (s *DropletsServiceOp) Create(ctx context.Context, createRequest *DropletCr
path := dropletBasePath path := dropletBasePath
req, err := s.client.NewRequest(ctx, "POST", path, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -369,7 +370,7 @@ func (s *DropletsServiceOp) CreateMultiple(ctx context.Context, createRequest *D
path := dropletBasePath path := dropletBasePath
req, err := s.client.NewRequest(ctx, "POST", path, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -388,7 +389,7 @@ func (s *DropletsServiceOp) CreateMultiple(ctx context.Context, createRequest *D
// Performs a delete request given a path // Performs a delete request given a path
func (s *DropletsServiceOp) delete(ctx context.Context, path string) (*Response, error) { func (s *DropletsServiceOp) delete(ctx context.Context, path string) (*Response, error) {
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -432,7 +433,7 @@ func (s *DropletsServiceOp) Kernels(ctx context.Context, dropletID int, opt *Lis
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -458,7 +459,7 @@ func (s *DropletsServiceOp) Actions(ctx context.Context, dropletID int, opt *Lis
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -487,7 +488,7 @@ func (s *DropletsServiceOp) Backups(ctx context.Context, dropletID int, opt *Lis
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -516,7 +517,7 @@ func (s *DropletsServiceOp) Snapshots(ctx context.Context, dropletID int, opt *L
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -541,7 +542,7 @@ func (s *DropletsServiceOp) Neighbors(ctx context.Context, dropletID int) ([]Dro
path := fmt.Sprintf("%s/%d/neighbors", dropletBasePath, dropletID) path := fmt.Sprintf("%s/%d/neighbors", dropletBasePath, dropletID)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -13,7 +13,7 @@ func TestDroplets_ListDroplets(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`)
}) })
@ -37,7 +37,7 @@ func TestDroplets_ListDropletsByTag(t *testing.T) {
t.Errorf("Droplets.ListByTag did not request with a tag parameter") t.Errorf("Droplets.ListByTag did not request with a tag parameter")
} }
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`)
}) })
@ -57,7 +57,7 @@ func TestDroplets_ListDropletsMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
dr := dropletsRoot{ dr := dropletsRoot{
Droplets: []Droplet{ Droplets: []Droplet{
@ -103,7 +103,7 @@ func TestDroplets_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -121,7 +121,7 @@ func TestDroplets_GetDroplet(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"droplet":{"id":12345}}`) fmt.Fprint(w, `{"droplet":{"id":12345}}`)
}) })
@ -265,7 +265,7 @@ func TestDroplets_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Droplets.Delete(ctx, 12345) _, err := client.Droplets.Delete(ctx, 12345)
@ -283,7 +283,7 @@ func TestDroplets_DestroyByTag(t *testing.T) {
t.Errorf("Droplets.DeleteByTag did not request with a tag parameter") t.Errorf("Droplets.DeleteByTag did not request with a tag parameter")
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Droplets.DeleteByTag(ctx, "testing-1") _, err := client.Droplets.DeleteByTag(ctx, "testing-1")
@ -297,7 +297,7 @@ func TestDroplets_Kernels(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345/kernels", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345/kernels", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"kernels": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"kernels": [{"id":1},{"id":2}]}`)
}) })
@ -318,7 +318,7 @@ func TestDroplets_Snapshots(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"snapshots": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"snapshots": [{"id":1},{"id":2}]}`)
}) })
@ -339,7 +339,7 @@ func TestDroplets_Backups(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345/backups", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345/backups", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"backups": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"backups": [{"id":1},{"id":2}]}`)
}) })
@ -360,7 +360,7 @@ func TestDroplets_Actions(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}]}`)
}) })
@ -381,7 +381,7 @@ func TestDroplets_Neighbors(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/12345/neighbors", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/12345/neighbors", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}]}`)
}) })

View File

@ -1,6 +1,7 @@
package godo package godo
import ( import (
"net/http"
"path" "path"
"strconv" "strconv"
@ -107,7 +108,7 @@ var _ FirewallsService = &FirewallsServiceOp{}
func (fw *FirewallsServiceOp) Get(ctx context.Context, fID string) (*Firewall, *Response, error) { func (fw *FirewallsServiceOp) Get(ctx context.Context, fID string) (*Firewall, *Response, error) {
path := path.Join(firewallsBasePath, fID) path := path.Join(firewallsBasePath, fID)
req, err := fw.client.NewRequest(ctx, "GET", path, nil) req, err := fw.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -123,7 +124,7 @@ func (fw *FirewallsServiceOp) Get(ctx context.Context, fID string) (*Firewall, *
// Create a new Firewall with a given configuration. // Create a new Firewall with a given configuration.
func (fw *FirewallsServiceOp) Create(ctx context.Context, fr *FirewallRequest) (*Firewall, *Response, error) { func (fw *FirewallsServiceOp) Create(ctx context.Context, fr *FirewallRequest) (*Firewall, *Response, error) {
req, err := fw.client.NewRequest(ctx, "POST", firewallsBasePath, fr) req, err := fw.client.NewRequest(ctx, http.MethodPost, firewallsBasePath, fr)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -158,7 +159,7 @@ func (fw *FirewallsServiceOp) Update(ctx context.Context, fID string, fr *Firewa
// Delete a Firewall by its identifier. // Delete a Firewall by its identifier.
func (fw *FirewallsServiceOp) Delete(ctx context.Context, fID string) (*Response, error) { func (fw *FirewallsServiceOp) Delete(ctx context.Context, fID string) (*Response, error) {
path := path.Join(firewallsBasePath, fID) path := path.Join(firewallsBasePath, fID)
return fw.createAndDoReq(ctx, "DELETE", path, nil) return fw.createAndDoReq(ctx, http.MethodDelete, path, nil)
} }
// List Firewalls. // List Firewalls.
@ -185,37 +186,37 @@ func (fw *FirewallsServiceOp) ListByDroplet(ctx context.Context, dID int, opt *L
// AddDroplets to a Firewall. // AddDroplets to a Firewall.
func (fw *FirewallsServiceOp) AddDroplets(ctx context.Context, fID string, dropletIDs ...int) (*Response, error) { func (fw *FirewallsServiceOp) AddDroplets(ctx context.Context, fID string, dropletIDs ...int) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "droplets") path := path.Join(firewallsBasePath, fID, "droplets")
return fw.createAndDoReq(ctx, "POST", path, &dropletsRequest{IDs: dropletIDs}) return fw.createAndDoReq(ctx, http.MethodPost, path, &dropletsRequest{IDs: dropletIDs})
} }
// RemoveDroplets from a Firewall. // RemoveDroplets from a Firewall.
func (fw *FirewallsServiceOp) RemoveDroplets(ctx context.Context, fID string, dropletIDs ...int) (*Response, error) { func (fw *FirewallsServiceOp) RemoveDroplets(ctx context.Context, fID string, dropletIDs ...int) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "droplets") path := path.Join(firewallsBasePath, fID, "droplets")
return fw.createAndDoReq(ctx, "DELETE", path, &dropletsRequest{IDs: dropletIDs}) return fw.createAndDoReq(ctx, http.MethodDelete, path, &dropletsRequest{IDs: dropletIDs})
} }
// AddTags to a Firewall. // AddTags to a Firewall.
func (fw *FirewallsServiceOp) AddTags(ctx context.Context, fID string, tags ...string) (*Response, error) { func (fw *FirewallsServiceOp) AddTags(ctx context.Context, fID string, tags ...string) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "tags") path := path.Join(firewallsBasePath, fID, "tags")
return fw.createAndDoReq(ctx, "POST", path, &tagsRequest{Tags: tags}) return fw.createAndDoReq(ctx, http.MethodPost, path, &tagsRequest{Tags: tags})
} }
// RemoveTags from a Firewall. // RemoveTags from a Firewall.
func (fw *FirewallsServiceOp) RemoveTags(ctx context.Context, fID string, tags ...string) (*Response, error) { func (fw *FirewallsServiceOp) RemoveTags(ctx context.Context, fID string, tags ...string) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "tags") path := path.Join(firewallsBasePath, fID, "tags")
return fw.createAndDoReq(ctx, "DELETE", path, &tagsRequest{Tags: tags}) return fw.createAndDoReq(ctx, http.MethodDelete, path, &tagsRequest{Tags: tags})
} }
// AddRules to a Firewall. // AddRules to a Firewall.
func (fw *FirewallsServiceOp) AddRules(ctx context.Context, fID string, rr *FirewallRulesRequest) (*Response, error) { func (fw *FirewallsServiceOp) AddRules(ctx context.Context, fID string, rr *FirewallRulesRequest) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "rules") path := path.Join(firewallsBasePath, fID, "rules")
return fw.createAndDoReq(ctx, "POST", path, rr) return fw.createAndDoReq(ctx, http.MethodPost, path, rr)
} }
// RemoveRules from a Firewall. // RemoveRules from a Firewall.
func (fw *FirewallsServiceOp) RemoveRules(ctx context.Context, fID string, rr *FirewallRulesRequest) (*Response, error) { func (fw *FirewallsServiceOp) RemoveRules(ctx context.Context, fID string, rr *FirewallRulesRequest) (*Response, error) {
path := path.Join(firewallsBasePath, fID, "rules") path := path.Join(firewallsBasePath, fID, "rules")
return fw.createAndDoReq(ctx, "DELETE", path, rr) return fw.createAndDoReq(ctx, http.MethodDelete, path, rr)
} }
type dropletsRequest struct { type dropletsRequest struct {
@ -245,7 +246,7 @@ func (fw *FirewallsServiceOp) createAndDoReq(ctx context.Context, method, path s
} }
func (fw *FirewallsServiceOp) listHelper(ctx context.Context, path string) ([]Firewall, *Response, error) { func (fw *FirewallsServiceOp) listHelper(ctx context.Context, path string) ([]Firewall, *Response, error) {
req, err := fw.client.NewRequest(ctx, "GET", path, nil) req, err := fw.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -224,7 +224,7 @@ func TestFirewalls_Get(t *testing.T) {
urlStr = path.Join(urlStr, fID) urlStr = path.Join(urlStr, fID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, firewallJSONResponse) fmt.Fprint(w, firewallJSONResponse)
}) })
@ -333,7 +333,7 @@ func TestFirewalls_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, expectedFirewallRequest) { if !reflect.DeepEqual(v, expectedFirewallRequest) {
t.Errorf("Request body = %+v, expected %+v", v, expectedFirewallRequest) t.Errorf("Request body = %+v, expected %+v", v, expectedFirewallRequest)
} }
@ -481,7 +481,7 @@ func TestFirewalls_Delete(t *testing.T) {
fID := "fe6b88f2-b42b-4bf7-bbd3-5ae20208f0b0" fID := "fe6b88f2-b42b-4bf7-bbd3-5ae20208f0b0"
urlStr = path.Join(urlStr, fID) urlStr = path.Join(urlStr, fID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Firewalls.Delete(ctx, fID) _, err := client.Firewalls.Delete(ctx, fID)
@ -496,7 +496,7 @@ func TestFirewalls_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/firewalls", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/firewalls", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, firewallListJSONResponse) fmt.Fprint(w, firewallListJSONResponse)
}) })
@ -517,7 +517,7 @@ func TestFirewalls_ListByDroplet(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/droplets/123/firewalls", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/droplets/123/firewalls", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, firewallListJSONResponse) fmt.Fprint(w, firewallListJSONResponse)
}) })
@ -550,7 +550,7 @@ func TestFirewalls_AddDroplets(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, dRequest) { if !reflect.DeepEqual(v, dRequest) {
t.Errorf("Request body = %+v, expected %+v", v, dRequest) t.Errorf("Request body = %+v, expected %+v", v, dRequest)
} }
@ -589,7 +589,7 @@ func TestFirewalls_RemoveDroplets(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
if !reflect.DeepEqual(v, dRequest) { if !reflect.DeepEqual(v, dRequest) {
t.Errorf("Request body = %+v, expected %+v", v, dRequest) t.Errorf("Request body = %+v, expected %+v", v, dRequest)
} }
@ -628,7 +628,7 @@ func TestFirewalls_AddTags(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, tRequest) { if !reflect.DeepEqual(v, tRequest) {
t.Errorf("Request body = %+v, expected %+v", v, tRequest) t.Errorf("Request body = %+v, expected %+v", v, tRequest)
} }
@ -666,7 +666,7 @@ func TestFirewalls_RemoveTags(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
if !reflect.DeepEqual(v, tRequest) { if !reflect.DeepEqual(v, tRequest) {
t.Errorf("Request body = %+v, expected %+v", v, tRequest) t.Errorf("Request body = %+v, expected %+v", v, tRequest)
} }
@ -721,7 +721,7 @@ func TestFirewalls_AddRules(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, rr) { if !reflect.DeepEqual(v, rr) {
t.Errorf("Request body = %+v, expected %+v", v, rr) t.Errorf("Request body = %+v, expected %+v", v, rr)
} }
@ -776,7 +776,7 @@ func TestFirewalls_RemoveRules(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
if !reflect.DeepEqual(v, rr) { if !reflect.DeepEqual(v, rr) {
t.Errorf("Request body = %+v, expected %+v", v, rr) t.Errorf("Request body = %+v, expected %+v", v, rr)
} }

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -63,7 +64,7 @@ func (f *FloatingIPsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Fl
return nil, nil, err return nil, nil, err
} }
req, err := f.client.NewRequest(ctx, "GET", path, nil) req, err := f.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -84,7 +85,7 @@ func (f *FloatingIPsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Fl
func (f *FloatingIPsServiceOp) Get(ctx context.Context, ip string) (*FloatingIP, *Response, error) { func (f *FloatingIPsServiceOp) Get(ctx context.Context, ip string) (*FloatingIP, *Response, error) {
path := fmt.Sprintf("%s/%s", floatingBasePath, ip) path := fmt.Sprintf("%s/%s", floatingBasePath, ip)
req, err := f.client.NewRequest(ctx, "GET", path, nil) req, err := f.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -103,7 +104,7 @@ func (f *FloatingIPsServiceOp) Get(ctx context.Context, ip string) (*FloatingIP,
func (f *FloatingIPsServiceOp) Create(ctx context.Context, createRequest *FloatingIPCreateRequest) (*FloatingIP, *Response, error) { func (f *FloatingIPsServiceOp) Create(ctx context.Context, createRequest *FloatingIPCreateRequest) (*FloatingIP, *Response, error) {
path := floatingBasePath path := floatingBasePath
req, err := f.client.NewRequest(ctx, "POST", path, createRequest) req, err := f.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -124,7 +125,7 @@ func (f *FloatingIPsServiceOp) Create(ctx context.Context, createRequest *Floati
func (f *FloatingIPsServiceOp) Delete(ctx context.Context, ip string) (*Response, error) { func (f *FloatingIPsServiceOp) Delete(ctx context.Context, ip string) (*Response, error) {
path := fmt.Sprintf("%s/%s", floatingBasePath, ip) path := fmt.Sprintf("%s/%s", floatingBasePath, ip)
req, err := f.client.NewRequest(ctx, "DELETE", path, nil) req, err := f.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -57,7 +58,7 @@ func (s *FloatingIPActionsServiceOp) List(ctx context.Context, ip string, opt *L
func (s *FloatingIPActionsServiceOp) doAction(ctx context.Context, ip string, request *ActionRequest) (*Action, *Response, error) { func (s *FloatingIPActionsServiceOp) doAction(ctx context.Context, ip string, request *ActionRequest) (*Action, *Response, error) {
path := floatingIPActionPath(ip) path := floatingIPActionPath(ip)
req, err := s.client.NewRequest(ctx, "POST", path, request) req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -72,7 +73,7 @@ func (s *FloatingIPActionsServiceOp) doAction(ctx context.Context, ip string, re
} }
func (s *FloatingIPActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) { func (s *FloatingIPActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -87,7 +88,7 @@ func (s *FloatingIPActionsServiceOp) get(ctx context.Context, path string) (*Act
} }
func (s *FloatingIPActionsServiceOp) list(ctx context.Context, path string) ([]Action, *Response, error) { func (s *FloatingIPActionsServiceOp) list(ctx context.Context, path string) ([]Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -24,7 +24,7 @@ func TestFloatingIPsActions_Assign(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, assignRequest) { if !reflect.DeepEqual(v, assignRequest) {
t.Errorf("Request body = %#v, expected %#v", v, assignRequest) t.Errorf("Request body = %#v, expected %#v", v, assignRequest)
} }
@ -59,7 +59,7 @@ func TestFloatingIPsActions_Unassign(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, unassignRequest) { if !reflect.DeepEqual(v, unassignRequest) {
t.Errorf("Request body = %+v, expected %+v", v, unassignRequest) t.Errorf("Request body = %+v, expected %+v", v, unassignRequest)
} }
@ -83,7 +83,7 @@ func TestFloatingIPsActions_Get(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions/456", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions/456", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`) fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
}) })
@ -103,7 +103,7 @@ func TestFloatingIPsActions_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"actions":[{"status":"in-progress"}]}`) fmt.Fprintf(w, `{"actions":[{"status":"in-progress"}]}`)
}) })
@ -123,7 +123,7 @@ func TestFloatingIPsActions_ListMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/192.168.0.1/actions?page=2"}}}`) fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/192.168.0.1/actions?page=2"}}}`)
}) })
@ -153,7 +153,7 @@ func TestFloatingIPsActions_ListPageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })

View File

@ -13,7 +13,7 @@ func TestFloatingIPs_ListFloatingIPs(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}]}`) fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}]}`)
}) })
@ -36,7 +36,7 @@ func TestFloatingIPs_ListFloatingIPsMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/?page=2"}}}`) fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/?page=2"}}}`)
}) })
@ -66,7 +66,7 @@ func TestFloatingIPs_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -84,7 +84,7 @@ func TestFloatingIPs_Get(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips/192.168.0.1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"floating_ip":{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"}}`) fmt.Fprint(w, `{"floating_ip":{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"}}`)
}) })
@ -115,7 +115,7 @@ func TestFloatingIPs_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -139,7 +139,7 @@ func TestFloatingIPs_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/floating_ips/192.168.0.1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/floating_ips/192.168.0.1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.FloatingIPs.Delete(ctx, "192.168.0.1") _, err := client.FloatingIPs.Delete(ctx, "192.168.0.1")

View File

@ -138,7 +138,7 @@ func TestNewRequest(t *testing.T) {
`{"name":"l","region":"","size":"","image":0,`+ `{"name":"l","region":"","size":"","image":0,`+
`"ssh_keys":null,"backups":false,"ipv6":false,`+ `"ssh_keys":null,"backups":false,"ipv6":false,`+
`"private_networking":false,"monitoring":false,"tags":null}`+"\n" `"private_networking":false,"monitoring":false,"tags":null}`+"\n"
req, _ := c.NewRequest(ctx, "GET", inURL, inBody) req, _ := c.NewRequest(ctx, http.MethodGet, inURL, inBody)
// test relative URL was expanded // test relative URL was expanded
if req.URL.String() != outURL { if req.URL.String() != outURL {
@ -166,7 +166,7 @@ func TestNewRequest_withUserData(t *testing.T) {
`{"name":"l","region":"","size":"","image":0,`+ `{"name":"l","region":"","size":"","image":0,`+
`"ssh_keys":null,"backups":false,"ipv6":false,`+ `"ssh_keys":null,"backups":false,"ipv6":false,`+
`"private_networking":false,"monitoring":false,"user_data":"u","tags":null}`+"\n" `"private_networking":false,"monitoring":false,"user_data":"u","tags":null}`+"\n"
req, _ := c.NewRequest(ctx, "GET", inURL, inBody) req, _ := c.NewRequest(ctx, http.MethodGet, inURL, inBody)
// test relative URL was expanded // test relative URL was expanded
if req.URL.String() != outURL { if req.URL.String() != outURL {
@ -188,7 +188,7 @@ func TestNewRequest_withUserData(t *testing.T) {
func TestNewRequest_badURL(t *testing.T) { func TestNewRequest_badURL(t *testing.T) {
c := NewClient(nil) c := NewClient(nil)
_, err := c.NewRequest(ctx, "GET", ":", nil) _, err := c.NewRequest(ctx, http.MethodGet, ":", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }
@ -200,7 +200,7 @@ func TestNewRequest_withCustomUserAgent(t *testing.T) {
t.Fatalf("New() unexpected error: %v", err) t.Fatalf("New() unexpected error: %v", err)
} }
req, _ := c.NewRequest(ctx, "GET", "/foo", nil) req, _ := c.NewRequest(ctx, http.MethodGet, "/foo", nil)
expected := fmt.Sprintf("%s+%s", ua, userAgent) expected := fmt.Sprintf("%s+%s", ua, userAgent)
if got := req.Header.Get("User-Agent"); got != expected { if got := req.Header.Get("User-Agent"); got != expected {
@ -217,13 +217,13 @@ func TestDo(t *testing.T) {
} }
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if m := "GET"; m != r.Method { if m := http.MethodGet; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m) t.Errorf("Request method = %v, expected %v", r.Method, m)
} }
fmt.Fprint(w, `{"A":"a"}`) fmt.Fprint(w, `{"A":"a"}`)
}) })
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
body := new(foo) body := new(foo)
_, err := client.Do(context.Background(), req, body) _, err := client.Do(context.Background(), req, body)
if err != nil { if err != nil {
@ -244,7 +244,7 @@ func TestDo_httpError(t *testing.T) {
http.Error(w, "Bad Request", 400) http.Error(w, "Bad Request", 400)
}) })
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
_, err := client.Do(context.Background(), req, nil) _, err := client.Do(context.Background(), req, nil)
if err == nil { if err == nil {
@ -262,7 +262,7 @@ func TestDo_redirectLoop(t *testing.T) {
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
}) })
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
_, err := client.Do(context.Background(), req, nil) _, err := client.Do(context.Background(), req, nil)
if err == nil { if err == nil {
@ -347,7 +347,7 @@ func TestDo_rateLimit(t *testing.T) {
t.Errorf("Client rate reset not initialized to zero value") t.Errorf("Client rate reset not initialized to zero value")
} }
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
_, err := client.Do(context.Background(), req, nil) _, err := client.Do(context.Background(), req, nil)
if err != nil { if err != nil {
t.Fatalf("Do(): %v", err) t.Fatalf("Do(): %v", err)
@ -378,7 +378,7 @@ func TestDo_rateLimit_errorResponse(t *testing.T) {
var expected int var expected int
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
_, _ = client.Do(context.Background(), req, nil) _, _ = client.Do(context.Background(), req, nil)
if expected = 60; client.Rate.Limit != expected { if expected = 60; client.Rate.Limit != expected {
@ -414,13 +414,13 @@ func TestDo_completion_callback(t *testing.T) {
} }
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if m := "GET"; m != r.Method { if m := http.MethodGet; m != r.Method {
t.Errorf("Request method = %v, expected %v", r.Method, m) t.Errorf("Request method = %v, expected %v", r.Method, m)
} }
fmt.Fprint(w, `{"A":"a"}`) fmt.Fprint(w, `{"A":"a"}`)
}) })
req, _ := client.NewRequest(ctx, "GET", "/", nil) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil)
body := new(foo) body := new(foo)
var completedReq *http.Request var completedReq *http.Request
var completedResp string var completedResp string

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -35,7 +36,7 @@ func (i *ImageActionsServiceOp) Transfer(ctx context.Context, imageID int, trans
path := fmt.Sprintf("v2/images/%d/actions", imageID) path := fmt.Sprintf("v2/images/%d/actions", imageID)
req, err := i.client.NewRequest(ctx, "POST", path, transferRequest) req, err := i.client.NewRequest(ctx, http.MethodPost, path, transferRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -61,7 +62,7 @@ func (i *ImageActionsServiceOp) Convert(ctx context.Context, imageID int) (*Acti
"type": "convert", "type": "convert",
} }
req, err := i.client.NewRequest(ctx, "POST", path, convertRequest) req, err := i.client.NewRequest(ctx, http.MethodPost, path, convertRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -87,7 +88,7 @@ func (i *ImageActionsServiceOp) Get(ctx context.Context, imageID, actionID int)
path := fmt.Sprintf("v2/images/%d/actions/%d", imageID, actionID) path := fmt.Sprintf("v2/images/%d/actions/%d", imageID, actionID)
req, err := i.client.NewRequest(ctx, "GET", path, nil) req, err := i.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -21,7 +21,7 @@ func TestImageActions_Transfer(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, transferRequest) { if !reflect.DeepEqual(v, transferRequest) {
t.Errorf("Request body = %+v, expected %+v", v, transferRequest) t.Errorf("Request body = %+v, expected %+v", v, transferRequest)
} }
@ -56,7 +56,7 @@ func TestImageActions_Convert(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, convertRequest) { if !reflect.DeepEqual(v, convertRequest) {
t.Errorf("Request body = %+v, expected %+v", v, convertRequest) t.Errorf("Request body = %+v, expected %+v", v, convertRequest)
} }
@ -81,7 +81,7 @@ func TestImageActions_Get(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images/123/actions/456", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images/123/actions/456", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`) fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
}) })

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -140,7 +141,7 @@ func (s *ImagesServiceOp) Delete(ctx context.Context, imageID int) (*Response, e
path := fmt.Sprintf("%s/%d", imageBasePath, imageID) path := fmt.Sprintf("%s/%d", imageBasePath, imageID)
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -154,7 +155,7 @@ func (s *ImagesServiceOp) Delete(ctx context.Context, imageID int) (*Response, e
func (s *ImagesServiceOp) get(ctx context.Context, ID interface{}) (*Image, *Response, error) { func (s *ImagesServiceOp) get(ctx context.Context, ID interface{}) (*Image, *Response, error) {
path := fmt.Sprintf("%s/%v", imageBasePath, ID) path := fmt.Sprintf("%s/%v", imageBasePath, ID)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -180,7 +181,7 @@ func (s *ImagesServiceOp) list(ctx context.Context, opt *ListOptions, listOpt *l
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -13,7 +13,7 @@ func TestImages_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"images":[{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"images":[{"id":1},{"id":2}]}`)
}) })
@ -33,7 +33,7 @@ func TestImages_ListDistribution(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
expected := "distribution" expected := "distribution"
actual := r.URL.Query().Get("type") actual := r.URL.Query().Get("type")
if actual != expected { if actual != expected {
@ -58,7 +58,7 @@ func TestImages_ListApplication(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
expected := "application" expected := "application"
actual := r.URL.Query().Get("type") actual := r.URL.Query().Get("type")
if actual != expected { if actual != expected {
@ -83,7 +83,7 @@ func TestImages_ListUser(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
expected := "true" expected := "true"
actual := r.URL.Query().Get("private") actual := r.URL.Query().Get("private")
if actual != expected { if actual != expected {
@ -109,7 +109,7 @@ func TestImages_ListImagesMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"images": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/images/?page=2"}}}`) fmt.Fprint(w, `{"images": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/images/?page=2"}}}`)
}) })
@ -138,7 +138,7 @@ func TestImages_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -156,7 +156,7 @@ func TestImages_GetImageByID(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"image":{"id":12345}}`) fmt.Fprint(w, `{"image":{"id":12345}}`)
}) })
@ -176,7 +176,7 @@ func TestImages_GetImageBySlug(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images/ubuntu", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images/ubuntu", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"image":{"id":12345}}`) fmt.Fprint(w, `{"image":{"id":12345}}`)
}) })
@ -232,7 +232,7 @@ func TestImages_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/images/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/images/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Images.Delete(ctx, 12345) _, err := client.Images.Delete(ctx, 12345)

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -70,7 +71,7 @@ func (s *KeysServiceOp) List(ctx context.Context, opt *ListOptions) ([]Key, *Res
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -89,7 +90,7 @@ func (s *KeysServiceOp) List(ctx context.Context, opt *ListOptions) ([]Key, *Res
// Performs a get given a path // Performs a get given a path
func (s *KeysServiceOp) get(ctx context.Context, path string) (*Key, *Response, error) { func (s *KeysServiceOp) get(ctx context.Context, path string) (*Key, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -129,7 +130,7 @@ func (s *KeysServiceOp) Create(ctx context.Context, createRequest *KeyCreateRequ
return nil, nil, NewArgError("createRequest", "cannot be nil") return nil, nil, NewArgError("createRequest", "cannot be nil")
} }
req, err := s.client.NewRequest(ctx, "POST", keysBasePath, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, keysBasePath, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -195,7 +196,7 @@ func (s *KeysServiceOp) UpdateByFingerprint(ctx context.Context, fingerprint str
// Delete key using a path // Delete key using a path
func (s *KeysServiceOp) delete(ctx context.Context, path string) (*Response, error) { func (s *KeysServiceOp) delete(ctx context.Context, path string) (*Response, error) {
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -13,7 +13,7 @@ func TestKeys_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"ssh_keys":[{"id":1},{"id":2}]}`) fmt.Fprint(w, `{"ssh_keys":[{"id":1},{"id":2}]}`)
}) })
@ -33,7 +33,7 @@ func TestKeys_ListKeysMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/account/keys/?page=2"}}}`) fmt.Fprint(w, `{"droplets": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/account/keys/?page=2"}}}`)
}) })
@ -62,7 +62,7 @@ func TestKeys_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -79,7 +79,7 @@ func TestKeys_GetByID(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"ssh_key": {"id":12345}}`) fmt.Fprint(w, `{"ssh_key": {"id":12345}}`)
}) })
@ -99,7 +99,7 @@ func TestKeys_GetByFingerprint(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys/aa:bb:cc", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys/aa:bb:cc", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"ssh_key": {"fingerprint":"aa:bb:cc"}}`) fmt.Fprint(w, `{"ssh_key": {"fingerprint":"aa:bb:cc"}}`)
}) })
@ -130,7 +130,7 @@ func TestKeys_Create(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -226,7 +226,7 @@ func TestKeys_DestroyByID(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Keys.DeleteByID(ctx, 12345) _, err := client.Keys.DeleteByID(ctx, 12345)
@ -240,7 +240,7 @@ func TestKeys_DestroyByFingerprint(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/account/keys/aa:bb:cc", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/account/keys/aa:bb:cc", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Keys.DeleteByFingerprint(ctx, "aa:bb:cc") _, err := client.Keys.DeleteByFingerprint(ctx, "aa:bb:cc")

View File

@ -2,12 +2,14 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
const loadBalancersBasePath = "/v2/load_balancers" const loadBalancersBasePath = "/v2/load_balancers"
const forwardingRulesPath = "forwarding_rules" const forwardingRulesPath = "forwarding_rules"
const dropletsPath = "droplets" const dropletsPath = "droplets"
// LoadBalancersService is an interface for managing load balancers with the DigitalOcean API. // LoadBalancersService is an interface for managing load balancers with the DigitalOcean API.
@ -143,7 +145,7 @@ var _ LoadBalancersService = &LoadBalancersServiceOp{}
func (l *LoadBalancersServiceOp) Get(ctx context.Context, lbID string) (*LoadBalancer, *Response, error) { func (l *LoadBalancersServiceOp) Get(ctx context.Context, lbID string) (*LoadBalancer, *Response, error) {
path := fmt.Sprintf("%s/%s", loadBalancersBasePath, lbID) path := fmt.Sprintf("%s/%s", loadBalancersBasePath, lbID)
req, err := l.client.NewRequest(ctx, "GET", path, nil) req, err := l.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -164,7 +166,7 @@ func (l *LoadBalancersServiceOp) List(ctx context.Context, opt *ListOptions) ([]
return nil, nil, err return nil, nil, err
} }
req, err := l.client.NewRequest(ctx, "GET", path, nil) req, err := l.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -183,7 +185,7 @@ func (l *LoadBalancersServiceOp) List(ctx context.Context, opt *ListOptions) ([]
// Create a new load balancer with a given configuration. // Create a new load balancer with a given configuration.
func (l *LoadBalancersServiceOp) Create(ctx context.Context, lbr *LoadBalancerRequest) (*LoadBalancer, *Response, error) { func (l *LoadBalancersServiceOp) Create(ctx context.Context, lbr *LoadBalancerRequest) (*LoadBalancer, *Response, error) {
req, err := l.client.NewRequest(ctx, "POST", loadBalancersBasePath, lbr) req, err := l.client.NewRequest(ctx, http.MethodPost, loadBalancersBasePath, lbr)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -219,7 +221,7 @@ func (l *LoadBalancersServiceOp) Update(ctx context.Context, lbID string, lbr *L
func (l *LoadBalancersServiceOp) Delete(ctx context.Context, ldID string) (*Response, error) { func (l *LoadBalancersServiceOp) Delete(ctx context.Context, ldID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", loadBalancersBasePath, ldID) path := fmt.Sprintf("%s/%s", loadBalancersBasePath, ldID)
req, err := l.client.NewRequest(ctx, "DELETE", path, nil) req, err := l.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -231,7 +233,7 @@ func (l *LoadBalancersServiceOp) Delete(ctx context.Context, ldID string) (*Resp
func (l *LoadBalancersServiceOp) AddDroplets(ctx context.Context, lbID string, dropletIDs ...int) (*Response, error) { func (l *LoadBalancersServiceOp) AddDroplets(ctx context.Context, lbID string, dropletIDs ...int) (*Response, error) {
path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, dropletsPath) path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, dropletsPath)
req, err := l.client.NewRequest(ctx, "POST", path, &dropletIDsRequest{IDs: dropletIDs}) req, err := l.client.NewRequest(ctx, http.MethodPost, path, &dropletIDsRequest{IDs: dropletIDs})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -243,7 +245,7 @@ func (l *LoadBalancersServiceOp) AddDroplets(ctx context.Context, lbID string, d
func (l *LoadBalancersServiceOp) RemoveDroplets(ctx context.Context, lbID string, dropletIDs ...int) (*Response, error) { func (l *LoadBalancersServiceOp) RemoveDroplets(ctx context.Context, lbID string, dropletIDs ...int) (*Response, error) {
path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, dropletsPath) path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, dropletsPath)
req, err := l.client.NewRequest(ctx, "DELETE", path, &dropletIDsRequest{IDs: dropletIDs}) req, err := l.client.NewRequest(ctx, http.MethodDelete, path, &dropletIDsRequest{IDs: dropletIDs})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -255,7 +257,7 @@ func (l *LoadBalancersServiceOp) RemoveDroplets(ctx context.Context, lbID string
func (l *LoadBalancersServiceOp) AddForwardingRules(ctx context.Context, lbID string, rules ...ForwardingRule) (*Response, error) { func (l *LoadBalancersServiceOp) AddForwardingRules(ctx context.Context, lbID string, rules ...ForwardingRule) (*Response, error) {
path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, forwardingRulesPath) path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, forwardingRulesPath)
req, err := l.client.NewRequest(ctx, "POST", path, &forwardingRulesRequest{Rules: rules}) req, err := l.client.NewRequest(ctx, http.MethodPost, path, &forwardingRulesRequest{Rules: rules})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -267,7 +269,7 @@ func (l *LoadBalancersServiceOp) AddForwardingRules(ctx context.Context, lbID st
func (l *LoadBalancersServiceOp) RemoveForwardingRules(ctx context.Context, lbID string, rules ...ForwardingRule) (*Response, error) { func (l *LoadBalancersServiceOp) RemoveForwardingRules(ctx context.Context, lbID string, rules ...ForwardingRule) (*Response, error) {
path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, forwardingRulesPath) path := fmt.Sprintf("%s/%s/%s", loadBalancersBasePath, lbID, forwardingRulesPath)
req, err := l.client.NewRequest(ctx, "DELETE", path, &forwardingRulesRequest{Rules: rules}) req, err := l.client.NewRequest(ctx, http.MethodDelete, path, &forwardingRulesRequest{Rules: rules})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -280,7 +280,7 @@ func TestLoadBlanacers_Get(t *testing.T) {
loadBalancerId := "37e6be88-01ec-4ec7-9bc6-a514d4719057" loadBalancerId := "37e6be88-01ec-4ec7-9bc6-a514d4719057"
path = fmt.Sprintf("%s/%s", path, loadBalancerId) path = fmt.Sprintf("%s/%s", path, loadBalancerId)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, lbGetJSONResponse) fmt.Fprint(w, lbGetJSONResponse)
}) })
@ -377,7 +377,7 @@ func TestLoadBlanacers_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
assert.Equal(t, createRequest, v) assert.Equal(t, createRequest, v)
fmt.Fprint(w, lbCreateJSONResponse) fmt.Fprint(w, lbCreateJSONResponse)
@ -553,7 +553,7 @@ func TestLoadBlanacers_List(t *testing.T) {
path := "/v2/load_balancers" path := "/v2/load_balancers"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, lbListJSONResponse) fmt.Fprint(w, lbListJSONResponse)
}) })
@ -614,7 +614,7 @@ func TestLoadBlanacers_List_Pagination(t *testing.T) {
path := "/v2/load_balancers" path := "/v2/load_balancers"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
testFormValues(t, r, map[string]string{"page": "2"}) testFormValues(t, r, map[string]string{"page": "2"})
fmt.Fprint(w, lbListJSONResponse) fmt.Fprint(w, lbListJSONResponse)
}) })
@ -638,7 +638,7 @@ func TestLoadBlanacers_Delete(t *testing.T) {
path := "/v2/load_balancers" path := "/v2/load_balancers"
path = fmt.Sprintf("%s/%s", path, lbID) path = fmt.Sprintf("%s/%s", path, lbID)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.LoadBalancers.Delete(ctx, lbID) _, err := client.LoadBalancers.Delete(ctx, lbID)
@ -665,7 +665,7 @@ func TestLoadBlanacers_AddDroplets(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
assert.Equal(t, dropletIdsRequest, v) assert.Equal(t, dropletIdsRequest, v)
fmt.Fprint(w, nil) fmt.Fprint(w, nil)
@ -695,7 +695,7 @@ func TestLoadBlanacers_RemoveDroplets(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
assert.Equal(t, dropletIdsRequest, v) assert.Equal(t, dropletIdsRequest, v)
fmt.Fprint(w, nil) fmt.Fprint(w, nil)
@ -739,7 +739,7 @@ func TestLoadBlanacers_AddForwardingRules(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
assert.Equal(t, frr, v) assert.Equal(t, frr, v)
fmt.Fprint(w, nil) fmt.Fprint(w, nil)
@ -782,7 +782,7 @@ func TestLoadBlanacers_RemoveForwardingRules(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
assert.Equal(t, frr, v) assert.Equal(t, frr, v)
fmt.Fprint(w, nil) fmt.Fprint(w, nil)

View File

@ -1,6 +1,10 @@
package godo package godo
import "github.com/digitalocean/godo/context" import (
"net/http"
"github.com/digitalocean/godo/context"
)
// RegionsService is an interface for interfacing with the regions // RegionsService is an interface for interfacing with the regions
// endpoints of the DigitalOcean API // endpoints of the DigitalOcean API
@ -43,7 +47,7 @@ func (s *RegionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Region
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -12,7 +12,7 @@ func TestRegions_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"regions":[{"slug":"1"},{"slug":"2"}]}`) fmt.Fprint(w, `{"regions":[{"slug":"1"},{"slug":"2"}]}`)
}) })
@ -32,7 +32,7 @@ func TestRegions_ListRegionsMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"regions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/regions/?page=2"}}}`) fmt.Fprint(w, `{"regions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/regions/?page=2"}}}`)
}) })
@ -62,7 +62,7 @@ func TestRegions_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })

View File

@ -1,6 +1,10 @@
package godo package godo
import "github.com/digitalocean/godo/context" import (
"net/http"
"github.com/digitalocean/godo/context"
)
// SizesService is an interface for interfacing with the size // SizesService is an interface for interfacing with the size
// endpoints of the DigitalOcean API // endpoints of the DigitalOcean API
@ -47,7 +51,7 @@ func (s *SizesServiceOp) List(ctx context.Context, opt *ListOptions) ([]Size, *R
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -12,7 +12,7 @@ func TestSizes_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"sizes":[{"slug":"1"},{"slug":"2"}]}`) fmt.Fprint(w, `{"sizes":[{"slug":"1"},{"slug":"2"}]}`)
}) })
@ -32,7 +32,7 @@ func TestSizes_ListSizesMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"sizes": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/sizes/?page=2"}}}`) fmt.Fprint(w, `{"sizes": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/sizes/?page=2"}}}`)
}) })
@ -62,7 +62,7 @@ func TestSizes_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -82,7 +83,7 @@ func (s *SnapshotsServiceOp) Get(ctx context.Context, snapshotID string) (*Snaps
func (s *SnapshotsServiceOp) Delete(ctx context.Context, snapshotID string) (*Response, error) { func (s *SnapshotsServiceOp) Delete(ctx context.Context, snapshotID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", snapshotBasePath, snapshotID) path := fmt.Sprintf("%s/%s", snapshotBasePath, snapshotID)
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,7 +97,7 @@ func (s *SnapshotsServiceOp) Delete(ctx context.Context, snapshotID string) (*Re
func (s *SnapshotsServiceOp) get(ctx context.Context, ID string) (*Snapshot, *Response, error) { func (s *SnapshotsServiceOp) get(ctx context.Context, ID string) (*Snapshot, *Response, error) {
path := fmt.Sprintf("%s/%s", snapshotBasePath, ID) path := fmt.Sprintf("%s/%s", snapshotBasePath, ID)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -122,7 +123,7 @@ func (s *SnapshotsServiceOp) list(ctx context.Context, opt *ListOptions, listOpt
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -14,7 +14,7 @@ func TestSnapshots_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"snapshots":[{"id":"1"},{"id":"2", "size_gigabytes": 4.84}]}`) fmt.Fprint(w, `{"snapshots":[{"id":"1"},{"id":"2", "size_gigabytes": 4.84}]}`)
}) })
ctx := context.Background() ctx := context.Background()
@ -34,7 +34,7 @@ func TestSnapshots_ListVolume(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
expected := "volume" expected := "volume"
actual := r.URL.Query().Get("resource_type") actual := r.URL.Query().Get("resource_type")
if actual != expected { if actual != expected {
@ -60,7 +60,7 @@ func TestSnapshots_ListDroplet(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
expected := "droplet" expected := "droplet"
actual := r.URL.Query().Get("resource_type") actual := r.URL.Query().Get("resource_type")
if actual != expected { if actual != expected {
@ -87,7 +87,7 @@ func TestSnapshots_ListSnapshotsMultiplePages(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"snapshots": [{"id":"1"},{"id":"2"}], "links":{"pages":{"next":"http://example.com/v2/snapshots/?page=2"}}}`) fmt.Fprint(w, `{"snapshots": [{"id":"1"},{"id":"2"}], "links":{"pages":{"next":"http://example.com/v2/snapshots/?page=2"}}}`)
}) })
@ -117,7 +117,7 @@ func TestSnapshots_RetrievePageByNumber(t *testing.T) {
}` }`
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -136,7 +136,7 @@ func TestSnapshots_GetSnapshotByID(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"snapshot":{"id":"12345"}}`) fmt.Fprint(w, `{"snapshot":{"id":"12345"}}`)
}) })
@ -157,7 +157,7 @@ func TestSnapshots_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots/12345", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots/12345", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
ctx := context.Background() ctx := context.Background()

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"time" "time"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -94,7 +96,7 @@ func (svc *StorageServiceOp) ListVolumes(ctx context.Context, params *ListVolume
} }
} }
req, err := svc.client.NewRequest(ctx, "GET", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -116,7 +118,7 @@ func (svc *StorageServiceOp) ListVolumes(ctx context.Context, params *ListVolume
func (svc *StorageServiceOp) CreateVolume(ctx context.Context, createRequest *VolumeCreateRequest) (*Volume, *Response, error) { func (svc *StorageServiceOp) CreateVolume(ctx context.Context, createRequest *VolumeCreateRequest) (*Volume, *Response, error) {
path := storageAllocPath path := storageAllocPath
req, err := svc.client.NewRequest(ctx, "POST", path, createRequest) req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -133,7 +135,7 @@ func (svc *StorageServiceOp) CreateVolume(ctx context.Context, createRequest *Vo
func (svc *StorageServiceOp) GetVolume(ctx context.Context, id string) (*Volume, *Response, error) { func (svc *StorageServiceOp) GetVolume(ctx context.Context, id string) (*Volume, *Response, error) {
path := fmt.Sprintf("%s/%s", storageAllocPath, id) path := fmt.Sprintf("%s/%s", storageAllocPath, id)
req, err := svc.client.NewRequest(ctx, "GET", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -151,7 +153,7 @@ func (svc *StorageServiceOp) GetVolume(ctx context.Context, id string) (*Volume,
func (svc *StorageServiceOp) DeleteVolume(ctx context.Context, id string) (*Response, error) { func (svc *StorageServiceOp) DeleteVolume(ctx context.Context, id string) (*Response, error) {
path := fmt.Sprintf("%s/%s", storageAllocPath, id) path := fmt.Sprintf("%s/%s", storageAllocPath, id)
req, err := svc.client.NewRequest(ctx, "DELETE", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -174,7 +176,7 @@ func (svc *StorageServiceOp) ListSnapshots(ctx context.Context, volumeID string,
return nil, nil, err return nil, nil, err
} }
req, err := svc.client.NewRequest(ctx, "GET", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -196,7 +198,7 @@ func (svc *StorageServiceOp) ListSnapshots(ctx context.Context, volumeID string,
func (svc *StorageServiceOp) CreateSnapshot(ctx context.Context, createRequest *SnapshotCreateRequest) (*Snapshot, *Response, error) { func (svc *StorageServiceOp) CreateSnapshot(ctx context.Context, createRequest *SnapshotCreateRequest) (*Snapshot, *Response, error) {
path := fmt.Sprintf("%s/%s/snapshots", storageAllocPath, createRequest.VolumeID) path := fmt.Sprintf("%s/%s/snapshots", storageAllocPath, createRequest.VolumeID)
req, err := svc.client.NewRequest(ctx, "POST", path, createRequest) req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -213,7 +215,7 @@ func (svc *StorageServiceOp) CreateSnapshot(ctx context.Context, createRequest *
func (svc *StorageServiceOp) GetSnapshot(ctx context.Context, id string) (*Snapshot, *Response, error) { func (svc *StorageServiceOp) GetSnapshot(ctx context.Context, id string) (*Snapshot, *Response, error) {
path := fmt.Sprintf("%s/%s", storageSnapPath, id) path := fmt.Sprintf("%s/%s", storageSnapPath, id)
req, err := svc.client.NewRequest(ctx, "GET", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -231,7 +233,7 @@ func (svc *StorageServiceOp) GetSnapshot(ctx context.Context, id string) (*Snaps
func (svc *StorageServiceOp) DeleteSnapshot(ctx context.Context, id string) (*Response, error) { func (svc *StorageServiceOp) DeleteSnapshot(ctx context.Context, id string) (*Response, error) {
path := fmt.Sprintf("%s/%s", storageSnapPath, id) path := fmt.Sprintf("%s/%s", storageSnapPath, id)
req, err := svc.client.NewRequest(ctx, "DELETE", path, nil) req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -77,7 +78,7 @@ func (s *StorageActionsServiceOp) Resize(ctx context.Context, volumeID string, s
func (s *StorageActionsServiceOp) doAction(ctx context.Context, volumeID string, request *ActionRequest) (*Action, *Response, error) { func (s *StorageActionsServiceOp) doAction(ctx context.Context, volumeID string, request *ActionRequest) (*Action, *Response, error) {
path := storageAllocationActionPath(volumeID) path := storageAllocationActionPath(volumeID)
req, err := s.client.NewRequest(ctx, "POST", path, request) req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -92,7 +93,7 @@ func (s *StorageActionsServiceOp) doAction(ctx context.Context, volumeID string,
} }
func (s *StorageActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) { func (s *StorageActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -107,7 +108,7 @@ func (s *StorageActionsServiceOp) get(ctx context.Context, path string) (*Action
} }
func (s *StorageActionsServiceOp) list(ctx context.Context, path string) ([]Action, *Response, error) { func (s *StorageActionsServiceOp) list(ctx context.Context, path string) ([]Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -28,7 +28,7 @@ func TestStoragesActions_Attach(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, attachRequest) { if !reflect.DeepEqual(v, attachRequest) {
t.Errorf("want=%#v", attachRequest) t.Errorf("want=%#v", attachRequest)
t.Errorf("got=%#v", v) t.Errorf("got=%#v", v)
@ -60,7 +60,7 @@ func TestStoragesActions_DetachByDropletID(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, detachByDropletIDRequest) { if !reflect.DeepEqual(v, detachByDropletIDRequest) {
t.Errorf("want=%#v", detachByDropletIDRequest) t.Errorf("want=%#v", detachByDropletIDRequest)
t.Errorf("got=%#v", v) t.Errorf("got=%#v", v)
@ -80,7 +80,7 @@ func TestStorageActions_Get(t *testing.T) {
volumeID := "98d414c6-295e-4e3a-ac58-eb9456c1e1d1" volumeID := "98d414c6-295e-4e3a-ac58-eb9456c1e1d1"
mux.HandleFunc("/v2/volumes/"+volumeID+"/actions/456", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/"+volumeID+"/actions/456", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`) fmt.Fprintf(w, `{"action":{"status":"in-progress"}}`)
}) })
@ -101,7 +101,7 @@ func TestStorageActions_List(t *testing.T) {
volumeID := "98d414c6-295e-4e3a-ac58-eb9456c1e1d1" volumeID := "98d414c6-295e-4e3a-ac58-eb9456c1e1d1"
mux.HandleFunc("/v2/volumes/"+volumeID+"/actions", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/"+volumeID+"/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `{"actions":[{"status":"in-progress"}]}`) fmt.Fprintf(w, `{"actions":[{"status":"in-progress"}]}`)
}) })
@ -134,7 +134,7 @@ func TestStoragesActions_Resize(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, resizeRequest) { if !reflect.DeepEqual(v, resizeRequest) {
t.Errorf("want=%#v", resizeRequest) t.Errorf("want=%#v", resizeRequest)
t.Errorf("got=%#v", v) t.Errorf("got=%#v", v)

View File

@ -48,7 +48,7 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
}` }`
mux.HandleFunc("/v2/volumes/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -114,7 +114,7 @@ func TestStorageVolumes_Get(t *testing.T) {
}` }`
mux.HandleFunc("/v2/volumes/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -166,7 +166,7 @@ func TestStorageVolumes_ListVolumesByName(t *testing.T) {
if r.URL.Query().Get("name") != "myvolume" || r.URL.Query().Get("region") != "nyc3" { if r.URL.Query().Get("name") != "myvolume" || r.URL.Query().Get("region") != "nyc3" {
t.Errorf("Storage.GetVolumeByName did not request the correct name or region") t.Errorf("Storage.GetVolumeByName did not request the correct name or region")
} }
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -222,7 +222,7 @@ func TestStorageVolumes_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -277,7 +277,7 @@ func TestStorageVolumes_CreateFromSnapshot(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -299,7 +299,7 @@ func TestStorageVolumes_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/volumes/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Storage.DeleteVolume(ctx, "80d414c6-295e-4e3a-ac58-eb9456c1e1d1") _, err := client.Storage.DeleteVolume(ctx, "80d414c6-295e-4e3a-ac58-eb9456c1e1d1")
@ -342,7 +342,7 @@ func TestStorageSnapshots_ListStorageSnapshots(t *testing.T) {
}` }`
mux.HandleFunc("/v2/volumes/98d414c6-295e-4e3a-ac58-eb9456c1e1d1/snapshots", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/volumes/98d414c6-295e-4e3a-ac58-eb9456c1e1d1/snapshots", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -402,7 +402,7 @@ func TestStorageSnapshots_Get(t *testing.T) {
}` }`
mux.HandleFunc("/v2/snapshots/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob) fmt.Fprint(w, jBlob)
}) })
@ -459,7 +459,7 @@ func TestStorageSnapshots_Create(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -481,7 +481,7 @@ func TestStorageSnapshots_Destroy(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/snapshots/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/snapshots/80d414c6-295e-4e3a-ac58-eb9456c1e1d1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Storage.DeleteSnapshot(ctx, "80d414c6-295e-4e3a-ac58-eb9456c1e1d1") _, err := client.Storage.DeleteSnapshot(ctx, "80d414c6-295e-4e3a-ac58-eb9456c1e1d1")

13
tags.go
View File

@ -2,6 +2,7 @@ package godo
import ( import (
"fmt" "fmt"
"net/http"
"github.com/digitalocean/godo/context" "github.com/digitalocean/godo/context"
) )
@ -93,7 +94,7 @@ func (s *TagsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Tag, *Res
return nil, nil, err return nil, nil, err
} }
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -114,7 +115,7 @@ func (s *TagsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Tag, *Res
func (s *TagsServiceOp) Get(ctx context.Context, name string) (*Tag, *Response, error) { func (s *TagsServiceOp) Get(ctx context.Context, name string) (*Tag, *Response, error) {
path := fmt.Sprintf("%s/%s", tagsBasePath, name) path := fmt.Sprintf("%s/%s", tagsBasePath, name)
req, err := s.client.NewRequest(ctx, "GET", path, nil) req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -134,7 +135,7 @@ func (s *TagsServiceOp) Create(ctx context.Context, createRequest *TagCreateRequ
return nil, nil, NewArgError("createRequest", "cannot be nil") return nil, nil, NewArgError("createRequest", "cannot be nil")
} }
req, err := s.client.NewRequest(ctx, "POST", tagsBasePath, createRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, tagsBasePath, createRequest)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -155,7 +156,7 @@ func (s *TagsServiceOp) Delete(ctx context.Context, name string) (*Response, err
} }
path := fmt.Sprintf("%s/%s", tagsBasePath, name) path := fmt.Sprintf("%s/%s", tagsBasePath, name)
req, err := s.client.NewRequest(ctx, "DELETE", path, nil) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -176,7 +177,7 @@ func (s *TagsServiceOp) TagResources(ctx context.Context, name string, tagReques
} }
path := fmt.Sprintf("%s/%s/resources", tagsBasePath, name) path := fmt.Sprintf("%s/%s/resources", tagsBasePath, name)
req, err := s.client.NewRequest(ctx, "POST", path, tagRequest) req, err := s.client.NewRequest(ctx, http.MethodPost, path, tagRequest)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -197,7 +198,7 @@ func (s *TagsServiceOp) UntagResources(ctx context.Context, name string, untagRe
} }
path := fmt.Sprintf("%s/%s/resources", tagsBasePath, name) path := fmt.Sprintf("%s/%s/resources", tagsBasePath, name)
req, err := s.client.NewRequest(ctx, "DELETE", path, untagRequest) req, err := s.client.NewRequest(ctx, http.MethodDelete, path, untagRequest)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -169,7 +169,7 @@ func TestTags_List(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, listJSON) fmt.Fprint(w, listJSON)
}) })
@ -190,7 +190,7 @@ func TestTags_ListEmpty(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, listEmptyJSON) fmt.Fprint(w, listEmptyJSON)
}) })
@ -210,7 +210,7 @@ func TestTags_ListPaging(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, listJSON) fmt.Fprint(w, listJSON)
}) })
@ -226,7 +226,7 @@ func TestTags_Get(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, http.MethodGet)
fmt.Fprint(w, getJSON) fmt.Fprint(w, getJSON)
}) })
@ -263,7 +263,7 @@ func TestTags_Create(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) { if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest) t.Errorf("Request body = %+v, expected %+v", v, createRequest)
} }
@ -287,7 +287,7 @@ func TestTags_Delete(t *testing.T) {
defer teardown() defer teardown()
mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/v2/tags/testing-1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
}) })
_, err := client.Tags.Delete(ctx, "testing-1") _, err := client.Tags.Delete(ctx, "testing-1")
@ -312,7 +312,7 @@ func TestTags_TagResource(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "POST") testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, tagResourcesRequest) { if !reflect.DeepEqual(v, tagResourcesRequest) {
t.Errorf("Request body = %+v, expected %+v", v, tagResourcesRequest) t.Errorf("Request body = %+v, expected %+v", v, tagResourcesRequest)
} }
@ -341,7 +341,7 @@ func TestTags_UntagResource(t *testing.T) {
t.Fatalf("decode json: %v", err) t.Fatalf("decode json: %v", err)
} }
testMethod(t, r, "DELETE") testMethod(t, r, http.MethodDelete)
if !reflect.DeepEqual(v, untagResourcesRequest) { if !reflect.DeepEqual(v, untagResourcesRequest) {
t.Errorf("Request body = %+v, expected %+v", v, untagResourcesRequest) t.Errorf("Request body = %+v, expected %+v", v, untagResourcesRequest)
} }