MCPcopy Create free account
hub / github.com/ProspectOne/perfops-cli / TestNewClient

Function TestNewClient

perfops/client_test.go:32–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func 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
55type roundTripper interface {
56 RoundTrip(req *http.Request) (*http.Response, error)

Callers

nothing calls this directly

Calls 3

WithAPIKeyFunction · 0.85
WithHTTPClientFunction · 0.85
NewClientFunction · 0.85

Tested by

no test coverage detected