(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestLoginWritesCredentials(t *testing.T) { |
| 54 | authFile := filepath.Join(t.TempDir(), "auth.json") |
| 55 | t.Setenv(envAuthFile, authFile) |
| 56 | mockAuthorization(t, "auth-code", "login-token") |
| 57 | |
| 58 | cmd := newLoginTestCommand() |
| 59 | var out bytes.Buffer |
| 60 | cmd.SetOut(&out) |
| 61 | |
| 62 | if err := login(cmd, nil); err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | |
| 66 | tokens, err := readTokens(authFile) |
| 67 | if err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | if tokens[""][tokenPersonal].AccessToken != "login-token" { |
| 71 | t.Fatalf("expected login token to be saved, got %q", tokens[""][tokenPersonal].AccessToken) |
| 72 | } |
| 73 | if tokens[""][tokenPersonal].RefreshToken == "" { |
| 74 | t.Fatal("expected login credentials to include a refresh token") |
| 75 | } |
| 76 | if out.String() != "Credentials saved to "+authFile+"\n" { |
| 77 | t.Fatalf("unexpected output: %q", out.String()) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestLoginWritesSelectedTokenType(t *testing.T) { |
| 82 | authFile := filepath.Join(t.TempDir(), "auth.json") |
nothing calls this directly
no test coverage detected