| 191 | } |
| 192 | |
| 193 | func TestTokenRunSecureStorage(t *testing.T) { |
| 194 | tests := []struct { |
| 195 | name string |
| 196 | opts TokenOptions |
| 197 | cfgStubs func(*testing.T, gh.Config) |
| 198 | wantStdout string |
| 199 | wantErr bool |
| 200 | wantErrMsg string |
| 201 | }{ |
| 202 | { |
| 203 | name: "token", |
| 204 | opts: TokenOptions{}, |
| 205 | cfgStubs: func(t *testing.T, cfg gh.Config) { |
| 206 | login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true) |
| 207 | }, |
| 208 | wantStdout: "gho_ABCDEFG\n", |
| 209 | }, |
| 210 | { |
| 211 | name: "token by hostname", |
| 212 | opts: TokenOptions{ |
| 213 | Hostname: "mycompany.com", |
| 214 | }, |
| 215 | cfgStubs: func(t *testing.T, cfg gh.Config) { |
| 216 | login(t, cfg, "mycompany.com", "test-user", "gho_1234567", "https", true) |
| 217 | }, |
| 218 | wantStdout: "gho_1234567\n", |
| 219 | }, |
| 220 | { |
| 221 | name: "no token", |
| 222 | opts: TokenOptions{}, |
| 223 | wantErr: true, |
| 224 | wantErrMsg: "no oauth token found for github.com", |
| 225 | }, |
| 226 | { |
| 227 | name: "no token for hostname user", |
| 228 | opts: TokenOptions{ |
| 229 | Hostname: "ghe.io", |
| 230 | Username: "test-user", |
| 231 | }, |
| 232 | wantErr: true, |
| 233 | wantErrMsg: "no oauth token found for ghe.io account test-user", |
| 234 | }, |
| 235 | { |
| 236 | name: "token for user", |
| 237 | opts: TokenOptions{ |
| 238 | Hostname: "github.com", |
| 239 | Username: "test-user", |
| 240 | }, |
| 241 | cfgStubs: func(t *testing.T, cfg gh.Config) { |
| 242 | login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true) |
| 243 | login(t, cfg, "github.com", "test-user-2", "gho_1234567", "https", true) |
| 244 | }, |
| 245 | wantStdout: "gho_ABCDEFG\n", |
| 246 | }, |
| 247 | } |
| 248 | |
| 249 | for _, tt := range tests { |
| 250 | t.Run(tt.name, func(t *testing.T) { |