(t *testing.T)
| 570 | } |
| 571 | |
| 572 | func TestInitDbxUsesAuthFileEnv(t *testing.T) { |
| 573 | origConfig := config |
| 574 | defer func() { config = origConfig }() |
| 575 | stubUsersClient(t, &mockUsersClient{ |
| 576 | getCurrentAccountFn: func() (*users.FullAccount, error) { |
| 577 | return testRootFullAccount(common.NewTeamRootInfo("team-root", "home-ns", "/Member")), nil |
| 578 | }, |
| 579 | }) |
| 580 | |
| 581 | authFile := filepath.Join(t.TempDir(), "custom-auth.json") |
| 582 | if err := os.WriteFile(authFile, []byte(`{"api.example.com":{"personal":"file-token"}}`), 0600); err != nil { |
| 583 | t.Fatal(err) |
| 584 | } |
| 585 | |
| 586 | t.Setenv(envAccessToken, "") |
| 587 | t.Setenv(envAuthFile, authFile) |
| 588 | |
| 589 | cmd := newAuthTestCommand() |
| 590 | if err := cmd.Flags().Set("domain", "api.example.com"); err != nil { |
| 591 | t.Fatal(err) |
| 592 | } |
| 593 | |
| 594 | if err := initDbx(cmd, nil); err != nil { |
| 595 | t.Fatal(err) |
| 596 | } |
| 597 | |
| 598 | if config.Token != "file-token" { |
| 599 | t.Fatalf("expected token from %s, got %q", envAuthFile, config.Token) |
| 600 | } |
| 601 | if config.Domain != "api.example.com" { |
| 602 | t.Fatalf("expected domain from flag, got %q", config.Domain) |
| 603 | } |
| 604 | if config.PathRoot != `{".tag": "root", "root": "team-root"}` { |
| 605 | t.Fatalf("expected path root from saved token account, got %q", config.PathRoot) |
| 606 | } |
| 607 | assertCurrentAuthContext(t, authSourceSaved, false, authFileCustom) |
| 608 | } |
| 609 | |
| 610 | func TestInitDbxRecordsSavedRefreshableAuthContext(t *testing.T) { |
| 611 | origConfig := config |
nothing calls this directly
no test coverage detected