(t *testing.T)
| 365 | } |
| 366 | |
| 367 | func Test_logoutRun_nontty(t *testing.T) { |
| 368 | tests := []struct { |
| 369 | name string |
| 370 | opts *LogoutOptions |
| 371 | cfgHosts []hostUsers |
| 372 | secureStorage bool |
| 373 | wantHosts string |
| 374 | assertToken tokenAssertion |
| 375 | wantErrOut *regexp.Regexp |
| 376 | wantErr string |
| 377 | }{ |
| 378 | { |
| 379 | name: "logs out specified user when one known host", |
| 380 | opts: &LogoutOptions{ |
| 381 | Hostname: "github.com", |
| 382 | Username: "monalisa", |
| 383 | }, |
| 384 | cfgHosts: []hostUsers{ |
| 385 | {"github.com", []user{ |
| 386 | {"monalisa", "abc123"}, |
| 387 | }}, |
| 388 | }, |
| 389 | wantHosts: "{}\n", |
| 390 | assertToken: hasNoToken("github.com"), |
| 391 | wantErrOut: regexp.MustCompile(`Logged out of github.com account monalisa`), |
| 392 | }, |
| 393 | { |
| 394 | name: "logs out specified user when multiple known hosts", |
| 395 | opts: &LogoutOptions{ |
| 396 | Hostname: "github.com", |
| 397 | Username: "monalisa", |
| 398 | }, |
| 399 | cfgHosts: []hostUsers{ |
| 400 | {"github.com", []user{ |
| 401 | {"monalisa", "abc123"}, |
| 402 | }}, |
| 403 | {"ghe.io", []user{ |
| 404 | {"monalisa-ghe", "abc123"}, |
| 405 | }}, |
| 406 | }, |
| 407 | wantHosts: "ghe.io:\n users:\n monalisa-ghe:\n oauth_token: abc123\n git_protocol: ssh\n oauth_token: abc123\n user: monalisa-ghe\n", |
| 408 | assertToken: hasNoToken("github.com"), |
| 409 | wantErrOut: regexp.MustCompile(`Logged out of github.com account monalisa`), |
| 410 | }, |
| 411 | { |
| 412 | name: "logs out specified user that is using secure storage", |
| 413 | secureStorage: true, |
| 414 | opts: &LogoutOptions{ |
| 415 | Hostname: "github.com", |
| 416 | Username: "monalisa", |
| 417 | }, |
| 418 | cfgHosts: []hostUsers{ |
| 419 | {"github.com", []user{ |
| 420 | {"monalisa", "abc123"}, |
| 421 | }}, |
| 422 | }, |
| 423 | wantHosts: "{}\n", |
| 424 | assertToken: hasNoToken("github.com"), |
nothing calls this directly
no test coverage detected