MCPcopy Create free account
hub / github.com/cli/cli / TestTokenRun

Function TestTokenRun

pkg/cmd/auth/token/token_test.go:106–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestTokenRun(t *testing.T) {
107 tests := []struct {
108 name string
109 opts TokenOptions
110 env map[string]string
111 cfgStubs func(*testing.T, gh.Config)
112 wantStdout string
113 wantErr bool
114 wantErrMsg string
115 wantStderrContains string
116 wantStderrOmits string
117 }{
118 {
119 name: "token",
120 opts: TokenOptions{},
121 cfgStubs: func(t *testing.T, cfg gh.Config) {
122 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false)
123 },
124 wantStdout: "gho_ABCDEFG\n",
125 wantStderrOmits: "This token will expire",
126 },
127 {
128 name: "token by hostname",
129 opts: TokenOptions{
130 Hostname: "github.mycompany.com",
131 },
132 cfgStubs: func(t *testing.T, cfg gh.Config) {
133 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false)
134 login(t, cfg, "github.mycompany.com", "test-user", "gho_1234567", "https", false)
135 },
136 wantStdout: "gho_1234567\n",
137 },
138 {
139 name: "no token",
140 opts: TokenOptions{},
141 wantErr: true,
142 wantErrMsg: "no oauth token found for github.com",
143 },
144 {
145 name: "no token for hostname user",
146 opts: TokenOptions{
147 Hostname: "ghe.io",
148 Username: "test-user",
149 },
150 wantErr: true,
151 wantErrMsg: "no oauth token found for ghe.io account test-user",
152 },
153 {
154 name: "uses default host when one is not provided",
155 opts: TokenOptions{},
156 cfgStubs: func(t *testing.T, cfg gh.Config) {
157 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false)
158 login(t, cfg, "github.mycompany.com", "test-user", "gho_1234567", "https", false)
159 },
160 env: map[string]string{"GH_HOST": "github.mycompany.com"},
161 wantStdout: "gho_1234567\n",
162 },
163 {

Callers

nothing calls this directly

Calls 10

TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
tokenRunFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
loginFunction · 0.70
loginRefreshableFunction · 0.70
RunMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected