MCPcopy Index your code
hub / github.com/google/go-github / TestNewClient

Function TestNewClient

github/github_test.go:926–978  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

924}
925
926func 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
980func Test_newClient(t *testing.T) {
981 t.Parallel()

Callers

nothing calls this directly

Calls 4

WithHTTPClientFunction · 0.85
NewClientFunction · 0.70
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…