Skip to content

Commit

Permalink
Merge pull request digitalocean#100 from tbalthazar/issue-99
Browse files Browse the repository at this point in the history
Changing the User Agent doesn't work as expected
  • Loading branch information
bryanl authored Jun 14, 2016
2 parents 1d54c91 + cb325e7 commit cacf7fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ

req.Header.Add("Content-Type", mediaType)
req.Header.Add("Accept", mediaType)
req.Header.Add("User-Agent", userAgent)
req.Header.Add("User-Agent", c.UserAgent)
return req, nil
}

Expand Down
16 changes: 16 additions & 0 deletions godo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ func TestNewRequest_badURL(t *testing.T) {
testURLParseError(t, err)
}

func TestNewRequest_withCustomUserAgent(t *testing.T) {
ua := "testing"
c, err := New(nil, SetUserAgent(ua))

if err != nil {
t.Fatalf("New() unexpected error: %v", err)
}

req, _ := c.NewRequest("GET", "/foo", nil)

expected := fmt.Sprintf("%s+%s", ua, userAgent)
if got := req.Header.Get("User-Agent"); got != expected {
t.Errorf("New() UserAgent = %s; expected %s", got, expected)
}
}

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

0 comments on commit cacf7fa

Please sign in to comment.