(t *testing.T)
| 54 | } |
| 55 | |
| 56 | func 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 | } |
nothing calls this directly
no test coverage detected