MCPcopy Index your code
hub / github.com/devopsctl/gitlabctl / TestGitlabNewClient

Function TestGitlabNewClient

cmd/gitlab_client_test.go:56–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestGitlabNewClient(t *testing.T) {
57 tt := []struct {
58 name string
59 setEnv func()
60 negativeTest bool
61 }{
62 {"BASIC_AUTH_OK", setBasicAuthEnvs, false},
63 {"OAUTH_TOKEN_OK", setOAuthTokenEnvs, false},
64 {"PRIVATE_TOKEN_OK", setPrivateTokenEnvs, false},
65 {"MISSING_ENVS_FAILS", unsetAuthEnvs, true},
66 }
67
68 for _, tc := range tt {
69 // Setup before each test case
70 unsetAuthEnvs()
71 tc.setEnv()
72
73 // Run the test
74 t.Run(tc.name, func(t *testing.T) {
75 gitlabClient, err := newGitlabClient()
76 if err != nil && !tc.negativeTest {
77 t.Fatalf("gitlab client test is expected to pass: %+v", err)
78 }
79 if err == nil && tc.negativeTest {
80 t.Fatalf("gitlab client test is expected to fail: %+v", err)
81 }
82 if !tc.negativeTest {
83 _, _, err = gitlabClient.Users.ListUsers(&gitlab.ListUsersOptions{})
84 if err != nil {
85 t.Fatalf("gitlab client test is expected to pass: %+v", err)
86 }
87 }
88 })
89 }
90}

Callers

nothing calls this directly

Calls 2

unsetAuthEnvsFunction · 0.85
newGitlabClientFunction · 0.85

Tested by

no test coverage detected