(t *testing.T)
| 924 | } |
| 925 | |
| 926 | func TestNewClient(t *testing.T) { |
| 927 | t.Parallel() |
| 928 | |
| 929 | for _, tt := range []struct { |
| 930 | name string |
| 931 | opts []ClientOptionsFunc |
| 932 | wantErr string |
| 933 | }{ |
| 934 | { |
| 935 | name: "no_options", |
| 936 | opts: []ClientOptionsFunc{}, |
| 937 | wantErr: "", |
| 938 | }, |
| 939 | { |
| 940 | name: "with_options", |
| 941 | opts: []ClientOptionsFunc{ |
| 942 | WithHTTPClient(&http.Client{Timeout: 10 * time.Second}), |
| 943 | }, |
| 944 | wantErr: "", |
| 945 | }, |
| 946 | { |
| 947 | name: "with_bad_options", |
| 948 | opts: []ClientOptionsFunc{ |
| 949 | func(_ *clientOptions) error { |
| 950 | return errors.New("bad option error") |
| 951 | }, |
| 952 | }, |
| 953 | wantErr: "bad option error", |
| 954 | }, |
| 955 | } { |
| 956 | t.Run(tt.name, func(t *testing.T) { |
| 957 | t.Parallel() |
| 958 | |
| 959 | c, err := NewClient(tt.opts...) |
| 960 | if err != nil { |
| 961 | if tt.wantErr == "" { |
| 962 | t.Fatalf("NewClient returned unexpected error: %v", err) |
| 963 | } |
| 964 | if !strings.Contains(err.Error(), tt.wantErr) { |
| 965 | t.Fatalf("error does not contain expected string %q: %v", tt.wantErr, err) |
| 966 | } |
| 967 | return |
| 968 | } |
| 969 | if tt.wantErr != "" { |
| 970 | t.Fatalf("NewClient did not return expected error containing %q", tt.wantErr) |
| 971 | } |
| 972 | |
| 973 | if c.client == nil { |
| 974 | t.Error("NewClient client is not initialized") |
| 975 | } |
| 976 | }) |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | func Test_newClient(t *testing.T) { |
| 981 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…