MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestWriteTokensCreatesParentDirectory

Function TestWriteTokensCreatesParentDirectory

cmd/auth_test.go:116–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

114}
115
116func 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
153func restoreOAuthCredentials(t *testing.T) {
154 t.Helper()

Callers

nothing calls this directly

Calls 2

writeTokensFunction · 0.85
readTokensFunction · 0.85

Tested by

no test coverage detected