Skip to content

Commit

Permalink
run gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
opalmer committed Jun 18, 2017
1 parent 2218433 commit 5578108
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion changes_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *ChangesService) DeleteChangeEdit(changeID, filePath string) (*Response,
// As response “204 No Content” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#publish-edit
func (s *ChangesService) PublishChangeEdit(changeID, notify string) (*Response, error) {
func (s *ChangesService) PublishChangeEdit(changeID, notify string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit:publish", changeID)

req, err := s.client.NewRequest("POST", u, map[string]string{
Expand Down
54 changes: 27 additions & 27 deletions gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,33 +221,33 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
// NewRawPutRequest creates a raw PUT request and makes no attempt to encode
// or marshal the body. Just passes it straight through.
func (c *Client) NewRawPutRequest(urlStr string, body string) (*http.Request, error) {
// Build URL for request
u, err := c.buildURLForRequest(urlStr)
if err != nil {
return nil, err
}

buf := bytes.NewBuffer([]byte(body))
req, err := http.NewRequest("PUT", u, buf)
if err != nil {
return nil, err
}

// Apply Authentication
if err := c.addAuthentication(req); err != nil {
return nil, err
}

// Request compact JSON
// See https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

// TODO: Add gzip encoding
// Accept-Encoding request header is set to gzip
// See https://gerrit-review.googlesource.com/Documentation/rest-api.html#output

return req, nil
// Build URL for request
u, err := c.buildURLForRequest(urlStr)
if err != nil {
return nil, err
}

buf := bytes.NewBuffer([]byte(body))
req, err := http.NewRequest("PUT", u, buf)
if err != nil {
return nil, err
}

// Apply Authentication
if err := c.addAuthentication(req); err != nil {
return nil, err
}

// Request compact JSON
// See https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

// TODO: Add gzip encoding
// Accept-Encoding request header is set to gzip
// See https://gerrit-review.googlesource.com/Documentation/rest-api.html#output

return req, nil
}

// Call is a combine function for Client.NewRequest and Client.Do.
Expand Down
36 changes: 18 additions & 18 deletions gerrit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,24 @@ func TestNewRequest(t *testing.T) {
}

func TestNewRawPutRequest(t *testing.T) {
c, err := gerrit.NewClient(testGerritInstanceURL, nil)
if err != nil {
t.Errorf("An error occured. Expected nil. Got %+v.", err)
}

inURL, outURL := "/foo", testGerritInstanceURL+"foo"
req, _ := c.NewRawPutRequest(inURL, "test raw PUT contents")

// Test that relative URL was expanded
if got, want := req.URL.String(), outURL; got != want {
t.Errorf("NewRequest(%q) URL is %v, want %v", inURL, got, want)
}

// Test that body was JSON encoded
body, _ := ioutil.ReadAll(req.Body)
if got, want := string(body), "test raw PUT contents"; got != want {
t.Errorf("NewRequest Body is %v, want %v", got, want)
}
c, err := gerrit.NewClient(testGerritInstanceURL, nil)
if err != nil {
t.Errorf("An error occured. Expected nil. Got %+v.", err)
}

inURL, outURL := "/foo", testGerritInstanceURL+"foo"
req, _ := c.NewRawPutRequest(inURL, "test raw PUT contents")

// Test that relative URL was expanded
if got, want := req.URL.String(), outURL; got != want {
t.Errorf("NewRequest(%q) URL is %v, want %v", inURL, got, want)
}

// Test that body was JSON encoded
body, _ := ioutil.ReadAll(req.Body)
if got, want := string(body), "test raw PUT contents"; got != want {
t.Errorf("NewRequest Body is %v, want %v", got, want)
}
}

func testURLParseError(t *testing.T, err error) {
Expand Down
2 changes: 0 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strconv"
)


// Number is a string representing a number. This type is only used in cases
// where the API being queried may return an inconsistent result.
type Number string
Expand Down Expand Up @@ -39,4 +38,3 @@ func (n *Number) UnmarshalJSON(data []byte) error {
}
return errors.New("Cannot convert data to number")
}

1 change: 1 addition & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gerrit_test
import (
"encoding/json"
"testing"

"github.com/andygrunwald/go-gerrit"
)

Expand Down

0 comments on commit 5578108

Please sign in to comment.