(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func Test_CheckAuth(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | env map[string]string |
| 16 | cfgStubs func(*testing.T, gh.Config) |
| 17 | expected bool |
| 18 | }{ |
| 19 | { |
| 20 | name: "no known hosts, no env auth token", |
| 21 | expected: false, |
| 22 | }, |
| 23 | { |
| 24 | name: "no known hosts, env auth token", |
| 25 | env: map[string]string{"GITHUB_TOKEN": "token"}, |
| 26 | expected: true, |
| 27 | }, |
| 28 | { |
| 29 | name: "known host", |
| 30 | cfgStubs: func(t *testing.T, c gh.Config) { |
| 31 | _, err := c.Authentication().Login("github.com", "test-user", "test-token", "https", false) |
| 32 | require.NoError(t, err) |
| 33 | }, |
| 34 | expected: true, |
| 35 | }, |
| 36 | { |
| 37 | name: "enterprise token", |
| 38 | env: map[string]string{"GH_ENTERPRISE_TOKEN": "token"}, |
| 39 | expected: true, |
| 40 | }, |
| 41 | } |
| 42 | |
| 43 | for _, tt := range tests { |
| 44 | t.Run(tt.name, func(t *testing.T) { |
| 45 | cfg, _ := config.NewIsolatedTestConfig(t) |
| 46 | if tt.cfgStubs != nil { |
| 47 | tt.cfgStubs(t, cfg) |
| 48 | } |
| 49 | |
| 50 | for k, v := range tt.env { |
| 51 | t.Setenv(k, v) |
| 52 | } |
| 53 | |
| 54 | require.Equal(t, tt.expected, CheckAuth(cfg)) |
| 55 | }) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func Test_IsAuthCheckEnabled(t *testing.T) { |
| 60 | tests := []struct { |
nothing calls this directly
no test coverage detected