Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #38 from giulianob/allowing-setting-http-client
Browse files Browse the repository at this point in the history
Allowing the HTTP client to be set by the consumer.
  • Loading branch information
Khaledgarbaya authored Apr 29, 2019
2 parents a275871 + 10f9ee3 commit 5c00146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contentful.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (c *Contentful) SetOrganization(organizationID string) *Contentful {
return c
}

// SetHTTPClient sets the underlying http.Client used to make requests.
func (c *Contentful) SetHTTPClient(client *http.Client) {
c.client = client
}

func (c *Contentful) newRequest(method, path string, query url.Values, body io.Reader) (*http.Request, error) {
u, err := url.Parse(c.BaseURL)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions contentful_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ func TestContentfulSetOrganization(t *testing.T) {
assert.Equal(organizationID, cma.Headers["X-Contentful-Organization"])
}

func TestContentfulSetClient(t *testing.T) {
assert := assert.New(t)

newClient := &http.Client{}
cma := NewCMA(CMAToken)
cma.SetHTTPClient(newClient)
assert.Equal(newClient, cma.client)
}

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

0 comments on commit 5c00146

Please sign in to comment.