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

Function TestLoginWritesCredentials

cmd/login_test.go:53–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func 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
81func TestLoginWritesSelectedTokenType(t *testing.T) {
82 authFile := filepath.Join(t.TempDir(), "auth.json")

Callers

nothing calls this directly

Calls 4

mockAuthorizationFunction · 0.85
newLoginTestCommandFunction · 0.85
loginFunction · 0.85
readTokensFunction · 0.85

Tested by

no test coverage detected