(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestNewClient(t *testing.T) { |
| 33 | testClient := &http.Client{} |
| 34 | testCases := map[string]struct { |
| 35 | opts []func(c *Client) error |
| 36 | chk func(c *Client) (interface{}, interface{}) |
| 37 | }{ |
| 38 | "Default": {[]func(c *Client) error{}, func(c *Client) (interface{}, interface{}) { return nil, nil }}, |
| 39 | "WithAPIKey": {[]func(c *Client) error{WithAPIKey("abc")}, func(c *Client) (interface{}, interface{}) { return c.apiKey, "abc" }}, |
| 40 | "WithHTTPClient": {[]func(c *Client) error{WithHTTPClient(testClient)}, func(c *Client) (interface{}, interface{}) { return c.client, testClient }}, |
| 41 | } |
| 42 | for name, tc := range testCases { |
| 43 | t.Run(name, func(t *testing.T) { |
| 44 | c, err := NewClient(tc.opts...) |
| 45 | if err != nil { |
| 46 | t.Fatalf("unexpected error %v", err) |
| 47 | } |
| 48 | if got, exp := tc.chk(c); got != exp { |
| 49 | t.Fatalf("expected %v; got %v", exp, got) |
| 50 | } |
| 51 | }) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | type roundTripper interface { |
| 56 | RoundTrip(req *http.Request) (*http.Response, error) |
nothing calls this directly
no test coverage detected