Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo Robles committed Jul 1, 2021
2 parents 9cff41d + 4e3a1b0 commit 2287ca0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 17 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ type Client struct {
// with the given credential
// for the given testrail domain
func NewClient(url, username, password string, useBetaApi ...bool) (c *Client) {
_useBetaApi := false
if len(useBetaApi) > 0 {
_useBetaApi = useBetaApi[0]
}
return NewCustomClient(url, username, password, nil, _useBetaApi)
}

// NewClient returns a new client with
// with the given credential
// for the given testrail domain
// and custom http Client
func NewCustomClient(url, username, password string, customHttpClient *http.Client, useBetaApi ...bool) (c *Client) {
c = &Client{}
c.username = username
c.password = password
Expand All @@ -36,7 +48,11 @@ func NewClient(url, username, password string, useBetaApi ...bool) (c *Client) {
}
c.url += "index.php?/api/v2/"

c.httpClient = &http.Client{}
if customHttpClient != nil {
c.httpClient = customHttpClient
} else {
c.httpClient = &http.Client{}
}

if len(useBetaApi) > 0 {
c.useBetaApi = useBetaApi[0]
Expand Down
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func newResponse(body string) *http.Response {
func TestSendRequest(t *testing.T) {
testClient(t)

c := NewClient("http://example.com", "testUsername", "testPassword")
c.httpClient = NewTestClient(newResponse(`{ "status_id": 1 }`), nil)
c := NewCustomClient("http://example.com", "testUsername", "testPassword", NewTestClient(newResponse(`{ "status_id": 1 }`), nil))

testValidGetRequest(t, c)
testInvalidGetRequest(t, c)
Expand Down

0 comments on commit 2287ca0

Please sign in to comment.