Skip to content

Commit b59a65c

Browse files
benjivesterbyghostsquad
authored andcommitted
feat: Replace http.Client with interface for extensibility
Setting up the NewClient method to accept an interface that gives access to the Do method of the http.Client rather than using a hard http.Client so that an interface can be passed for mocking and other non-standard clients can be used with go-jira.
1 parent 9ca8940 commit b59a65c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

jira.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ import (
1515
"github.com/pkg/errors"
1616
)
1717

18+
// httpClient defines an interface for an http.Client implementation so that alternative
19+
// http Clients can be passed in for making requests
20+
type httpClient interface {
21+
Do(request *http.Request) (response *http.Response, err error)
22+
}
23+
1824
// A Client manages communication with the JIRA API.
1925
type Client struct {
2026
// HTTP client used to communicate with the API.
21-
client *http.Client
27+
client httpClient
2228

2329
// Base URL for API requests.
2430
baseURL *url.URL
2531

26-
// Session storage if the user authentificate with a Session cookie
32+
// Session storage if the user authenticates with a Session cookie
2733
session *Session
2834

2935
// Services used for talking to different parts of the JIRA API.
@@ -52,7 +58,7 @@ type Client struct {
5258
// As an alternative you can use Session Cookie based authentication provided by this package as well.
5359
// See https://docs.atlassian.com/jira/REST/latest/#authentication
5460
// baseURL is the HTTP endpoint of your JIRA instance and should always be specified with a trailing slash.
55-
func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
61+
func NewClient(httpClient httpClient, baseURL string) (*Client, error) {
5662
if httpClient == nil {
5763
httpClient = http.DefaultClient
5864
}

0 commit comments

Comments
 (0)