MCPcopy
hub / github.com/cli/cli / Test_CheckAuth

Function Test_CheckAuth

pkg/cmdutil/auth_check_test.go:12–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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
59func Test_IsAuthCheckEnabled(t *testing.T) {
60 tests := []struct {

Callers

nothing calls this directly

Calls 6

NewIsolatedTestConfigFunction · 0.92
CheckAuthFunction · 0.85
EqualMethod · 0.80
LoginMethod · 0.65
AuthenticationMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected