Skip to content

Commit

Permalink
Changing the User Agent doesn't work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
tbalthazar committed Jun 14, 2016
1 parent df6258c commit cb325e7
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 @@ -230,7 +230,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 @@ -140,6 +140,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 cb325e7

Please sign in to comment.