diff --git a/options.go b/options.go index 7f8a75d1..6413a6a8 100644 --- a/options.go +++ b/options.go @@ -1,6 +1,9 @@ package goshopify -import "fmt" +import ( + "fmt" + "net/http" +) // Option is used to configure client with options type Option func(c *Client) @@ -28,3 +31,10 @@ func WithLogger(logger LeveledLoggerInterface) Option { c.log = logger } } + +// WithHTTPClient is used to set a custom http client +func WithHTTPClient(client *http.Client) Option { + return func(c *Client) { + c.Client = client + } +} diff --git a/options_test.go b/options_test.go index 64e00e25..f9763e22 100644 --- a/options_test.go +++ b/options_test.go @@ -2,7 +2,9 @@ package goshopify import ( "fmt" + "net/http" "testing" + "time" ) func TestWithVersion(t *testing.T) { @@ -61,3 +63,12 @@ func TestWithUnstableVersion(t *testing.T) { t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected) } } + +func TestWithHTTPClient(t *testing.T) { + c := NewClient(app, "fooshop", "abcd", WithHTTPClient(&http.Client{Timeout: 30 * time.Second})) + expected := 30 * time.Second + + if c.Client.Timeout.String() != expected.String() { + t.Errorf("WithVersion client.Client = %s, expected %s", c.Client.Timeout, expected) + } +}