Skip to content

Commit

Permalink
Code review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
viola committed Feb 17, 2017
1 parent befaf62 commit 566f702
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
16 changes: 7 additions & 9 deletions certificates.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package godo

import (
"fmt"
)
import "path"

const certificatesBasePath = "/v2/certificates"

Expand Down Expand Up @@ -50,9 +48,9 @@ var _ CertificatesService = &CertificatesServiceOp{}

// Get an existing certificate by its identifier.
func (c *CertificatesServiceOp) Get(cID string) (*Certificate, *Response, error) {
path := fmt.Sprintf("%s/%s", certificatesBasePath, cID)
urlStr := path.Join(certificatesBasePath, cID)

req, err := c.client.NewRequest("GET", path, nil)
req, err := c.client.NewRequest("GET", urlStr, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -68,12 +66,12 @@ func (c *CertificatesServiceOp) Get(cID string) (*Certificate, *Response, error)

// List all certificates.
func (c *CertificatesServiceOp) List(opt *ListOptions) ([]Certificate, *Response, error) {
path, err := addOptions(certificatesBasePath, opt)
urlStr, err := addOptions(certificatesBasePath, opt)
if err != nil {
return nil, nil, err
}

req, err := c.client.NewRequest("GET", path, nil)
req, err := c.client.NewRequest("GET", urlStr, nil)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -108,9 +106,9 @@ func (c *CertificatesServiceOp) Create(cr *CertificateRequest) (*Certificate, *R

// Delete a certificate by its identifier.
func (c *CertificatesServiceOp) Delete(cID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", certificatesBasePath, cID)
urlStr := path.Join(certificatesBasePath, cID)

req, err := c.client.NewRequest("DELETE", path, nil)
req, err := c.client.NewRequest("DELETE", urlStr, nil)
if err != nil {
return nil, err
}
Expand Down
21 changes: 11 additions & 10 deletions certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"path"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -50,10 +51,10 @@ func TestCertificates_Get(t *testing.T) {
setup()
defer teardown()

path := "/v2/certificates"
urlStr := "/v2/certificates"
cID := "892071a0-bb95-49bc-8021-3afd67a210bf"
path = fmt.Sprintf("%s/%s", path, cID)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, certJSONResponse)
})
Expand All @@ -78,8 +79,8 @@ func TestCertificates_List(t *testing.T) {
setup()
defer teardown()

path := "/v2/certificates"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
urlStr := "/v2/certificates"
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, certsJSONResponse)
})
Expand Down Expand Up @@ -121,8 +122,8 @@ func TestCertificates_Create(t *testing.T) {
CertificateChain: "-----BEGIN CERTIFICATE-----",
}

path := "/v2/certificates"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
urlStr := "/v2/certificates"
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
v := new(CertificateRequest)
err := json.NewDecoder(r.Body).Decode(v)
if err != nil {
Expand Down Expand Up @@ -156,9 +157,9 @@ func TestCertificates_Delete(t *testing.T) {
defer teardown()

cID := "892071a0-bb95-49bc-8021-3afd67a210bf"
path := "/v2/certificates"
path = fmt.Sprintf("%s/%s", path, cID)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
urlStr := "/v2/certificates"
urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})

Expand Down

0 comments on commit 566f702

Please sign in to comment.