(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestWriteTokensCreatesParentDirectory(t *testing.T) { |
| 117 | authFile := filepath.Join(t.TempDir(), "nested", "auth.json") |
| 118 | expiry := time.Now().Add(time.Hour).UTC() |
| 119 | want := TokenMap{ |
| 120 | "": { |
| 121 | tokenPersonal: { |
| 122 | AccessToken: "personal-token", |
| 123 | RefreshToken: "refresh-token", |
| 124 | TokenType: "Bearer", |
| 125 | Expiry: &expiry, |
| 126 | AppKey: "app-key", |
| 127 | }, |
| 128 | }, |
| 129 | "api.example.com": { |
| 130 | tokenTeamAccess: { |
| 131 | AccessToken: "team-access-token", |
| 132 | }, |
| 133 | }, |
| 134 | } |
| 135 | |
| 136 | if err := writeTokens(authFile, want); err != nil { |
| 137 | t.Fatal(err) |
| 138 | } |
| 139 | |
| 140 | got, err := readTokens(authFile) |
| 141 | if err != nil { |
| 142 | t.Fatal(err) |
| 143 | } |
| 144 | |
| 145 | if got[""][tokenPersonal].AccessToken != want[""][tokenPersonal].AccessToken { |
| 146 | t.Fatalf("expected personal token %q, got %q", want[""][tokenPersonal].AccessToken, got[""][tokenPersonal].AccessToken) |
| 147 | } |
| 148 | if got["api.example.com"][tokenTeamAccess].AccessToken != want["api.example.com"][tokenTeamAccess].AccessToken { |
| 149 | t.Fatalf("expected team access token %q, got %q", want["api.example.com"][tokenTeamAccess].AccessToken, got["api.example.com"][tokenTeamAccess].AccessToken) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func restoreOAuthCredentials(t *testing.T) { |
| 154 | t.Helper() |
nothing calls this directly
no test coverage detected