Skip to content

Commit

Permalink
Add option to support custom http client (#130)
Browse files Browse the repository at this point in the history
- add WithHTTPClient as an option

Co-authored-by: Fidel Ruiz <[email protected]>
  • Loading branch information
fidel-ruiz and Fidel Ruiz authored Dec 9, 2020
1 parent e292691 commit 786f65e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
}
}
11 changes: 11 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package goshopify

import (
"fmt"
"net/http"
"testing"
"time"
)

func TestWithVersion(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 786f65e

Please sign in to comment.