From 3419aecb14f4f5c5ad0c3095c1d01904287fd49b Mon Sep 17 00:00:00 2001 From: Greg Soltis Date: Thu, 28 Apr 2022 11:28:34 -0700 Subject: [PATCH] Start plumbing through afero.Fs --- cli/cmd/turbo/main.go | 4 +- cli/internal/config/config.go | 20 +++- cli/internal/config/config_file.go | 93 ++++++++-------- cli/internal/config/config_file_test.go | 139 ++++++++++++++++++++++++ cli/internal/fs/path.go | 14 ++- cli/internal/login/login.go | 38 ++++--- cli/internal/login/login_test.go | 79 +++++++++----- cli/internal/login/logout.go | 2 +- cli/internal/login/unlink.go | 2 +- 9 files changed, 288 insertions(+), 103 deletions(-) create mode 100644 cli/internal/config/config_file_test.go diff --git a/cli/cmd/turbo/main.go b/cli/cmd/turbo/main.go index 0326634600f31..c1b14848633af 100644 --- a/cli/cmd/turbo/main.go +++ b/cli/cmd/turbo/main.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/spf13/afero" "github.com/vercel/turborepo/cli/internal/config" "github.com/vercel/turborepo/cli/internal/info" "github.com/vercel/turborepo/cli/internal/login" @@ -51,6 +52,7 @@ func main() { ui := ui.BuildColoredUi(colorMode) c := cli.NewCLI("turbo", turboVersion) + fsys := afero.NewOsFs() util.InitPrintf() @@ -59,7 +61,7 @@ func main() { c.ErrorWriter = os.Stderr // Parse and validate cmd line flags and env vars // Note that cf can be nil - cf, err := config.ParseAndValidate(c.Args, ui, turboVersion) + cf, err := config.ParseAndValidate(c.Args, fsys, ui, turboVersion) if err != nil { ui.Error(fmt.Sprintf("%s %s", uiPkg.ERROR_PREFIX, color.RedString(err.Error()))) os.Exit(1) diff --git a/cli/internal/config/config.go b/cli/internal/config/config.go index 067f6aefa10ce..9ecb165bd7a74 100644 --- a/cli/internal/config/config.go +++ b/cli/internal/config/config.go @@ -75,7 +75,7 @@ type CacheConfig struct { // ParseAndValidate parses the cmd line flags / env vars, and verifies that all required // flags have been set. Users can pass in flags when calling a subcommand, or set env vars // with the prefix 'TURBO_'. If both values are set, the env var value will be used. -func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, err error) { +func ParseAndValidate(args []string, fsys afero.Fs, ui cli.Ui, turboVersion string) (c *Config, err error) { // Special check for ./turbo invocation without any args // Return the help message @@ -111,8 +111,20 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, if err != nil { return nil, err } - userConfig, _ := ReadUserConfigFile() - partialConfig, _ := ReadConfigFile(filepath.Join(".turbo", "config.json")) + userConfig, err := ReadUserConfigFile(fsys) + if err != nil { + return nil, fmt.Errorf("reading user config file: %v", err) + } + if userConfig == nil { + userConfig = defaultUserConfig() + } + partialConfig, err := ReadRepoConfigFile(fsys, cwd) + if err != nil { + return nil, fmt.Errorf("reading repo config file: %v", err) + } + if partialConfig == nil { + partialConfig = defaultRepoConfig() + } partialConfig.Token = userConfig.Token enverr := envconfig.Process("TURBO", partialConfig) @@ -214,7 +226,7 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config, RootPackageJSON: rootPackageJSON, TurboConfigJSON: turboConfigJson, Cwd: cwd, - Fs: afero.NewOsFs(), + Fs: fsys, } c.ApiClient.SetToken(partialConfig.Token) diff --git a/cli/internal/config/config_file.go b/cli/internal/config/config_file.go index fc4cded6d532a..de9e361f84de4 100644 --- a/cli/internal/config/config_file.go +++ b/cli/internal/config/config_file.go @@ -2,7 +2,8 @@ package config import ( "encoding/json" - "io/ioutil" + "errors" + "os" "path/filepath" "github.com/adrg/xdg" @@ -24,6 +25,20 @@ type TurborepoConfig struct { TeamSlug string `json:"teamSlug,omitempty" envconfig:"team"` } +func defaultUserConfig() *TurborepoConfig { + return &TurborepoConfig{ + ApiUrl: "https://vercel.com/api", + LoginUrl: "https://vercel.com", + } +} + +func defaultRepoConfig() *TurborepoConfig { + return &TurborepoConfig{ + ApiUrl: "https://vercel.com/api", + LoginUrl: "https://vercel.com", + } +} + // writeConfigFile writes config file at a path func writeConfigFile(fsys afero.Fs, path fs.AbsolutePath, config *TurborepoConfig) error { jsonBytes, marshallError := json.Marshal(config) @@ -37,14 +52,6 @@ func writeConfigFile(fsys afero.Fs, path fs.AbsolutePath, config *TurborepoConfi return nil } -// WriteRepoConfigFileToMigrate is used to write the portion of the config file that is saved -// within the repository itself. -func WriteRepoConfigFileToMigrate(config *TurborepoConfig) error { - fs.EnsureDir(filepath.Join(".turbo", "config.json")) - path := filepath.Join(".turbo", "config.json") - return writeConfigFile(path, config) -} - // WriteRepoConfigFile is used to write the portion of the config file that is saved // within the repository itself. func WriteRepoConfigFile(fsys afero.Fs, repoRoot fs.AbsolutePath, toWrite *TurborepoConfig) error { @@ -56,44 +63,39 @@ func WriteRepoConfigFile(fsys afero.Fs, repoRoot fs.AbsolutePath, toWrite *Turbo return writeConfigFile(fsys, path, toWrite) } -// WriteUserConfigFileToMigrate writes a user config file. This may contain a token and so should -// not be saved within the repository to avoid committing sensitive data -func WriteUserConfigFileToMigrate(config *TurborepoConfig) error { +func userConfigPath(fsys afero.Fs) (fs.AbsolutePath, error) { path, err := xdg.ConfigFile(filepath.Join("turborepo", "config.json")) if err != nil { - return err + return "", err + } + absPath, err := fs.CheckedToAbsolutePath(path) + if err != nil { + return "", err } - return writeConfigFile(path, config) + return absPath, nil } func WriteUserConfigFile(fsys afero.Fs, config *TurborepoConfig) error { - path, err := xdg.ConfigFile(filepath.Join("turborepo", "config.json")) - if err != nil { - return err - } - absPath, err := fs.CheckedToAbsolutePath(path) + path, err := userConfigPath(fsys) if err != nil { return err } - return writeConfigFile(fsys, absPath, config) + return writeConfigFile(fsys, path, config) } -// ReadConfigFile reads a config file at a path -func ReadConfigFile(path string) (*TurborepoConfig, error) { - var config = &TurborepoConfig{ - Token: "", - TeamId: "", - ApiUrl: "https://vercel.com/api", - LoginUrl: "https://vercel.com", - TeamSlug: "", - } - b, err := ioutil.ReadFile(path) +// readConfigFile reads a config file at a path +func readConfigFile(fsys afero.Fs, path fs.AbsolutePath, defaults func() *TurborepoConfig) (*TurborepoConfig, error) { + b, err := fs.ReadFile(fsys, path) if err != nil { - return config, err + if errors.Is(err, os.ErrNotExist) { + return nil, nil + } + return nil, err } + config := defaults() jsonErr := json.Unmarshal(b, config) if jsonErr != nil { - return config, jsonErr + return nil, jsonErr } if config.ApiUrl == "https://api.vercel.com" { config.ApiUrl = "https://vercel.com/api" @@ -102,25 +104,24 @@ func ReadConfigFile(path string) (*TurborepoConfig, error) { } // ReadUserConfigFile reads a user config file -func ReadUserConfigFile() (*TurborepoConfig, error) { - path, err := xdg.ConfigFile(filepath.Join("turborepo", "config.json")) +func ReadUserConfigFile(fsys afero.Fs) (*TurborepoConfig, error) { + path, err := userConfigPath(fsys) if err != nil { - return &TurborepoConfig{ - Token: "", - TeamId: "", - ApiUrl: "https://vercel.com/api", - LoginUrl: "https://vercel.com", - TeamSlug: "", - }, err + return nil, err } - return ReadConfigFile(path) + return readConfigFile(fsys, path, defaultUserConfig) } -// DeleteUserConfigFileToMigrate deletes a user config file -func DeleteUserConfigFileToMigrate() error { - return WriteUserConfigFileToMigrate(&TurborepoConfig{}) +func ReadRepoConfigFile(fsys afero.Fs, repoRoot fs.AbsolutePath) (*TurborepoConfig, error) { + path := repoRoot.Join(".turbo", "config.json") + return readConfigFile(fsys, path, defaultRepoConfig) } +// DeleteUserConfigFile deletes a user config file func DeleteUserConfigFile(fsys afero.Fs) error { - return WriteUserConfigFileToMigrate(&TurborepoConfig{}) + path, err := userConfigPath(fsys) + if err != nil { + return err + } + return fs.RemoveFile(fsys, path) } diff --git a/cli/internal/config/config_file_test.go b/cli/internal/config/config_file_test.go new file mode 100644 index 0000000000000..3380bfd450e1e --- /dev/null +++ b/cli/internal/config/config_file_test.go @@ -0,0 +1,139 @@ +package config + +import ( + "encoding/json" + "os" + "testing" + + "github.com/spf13/afero" + "github.com/vercel/turborepo/cli/internal/fs" +) + +func TestReadRepoConfigWhenMissing(t *testing.T) { + fsys := afero.NewMemMapFs() + cwd, err := fs.GetCwd() + if err != nil { + t.Fatalf("getting cwd: %v", err) + } + + config, err := ReadRepoConfigFile(fsys, cwd) + if err != nil { + t.Errorf("got error reading non-existent config file: %v, want ", err) + } + if config != nil { + t.Errorf("got config value %v, wanted ", config) + } +} + +func writePartialInitialConfig(t *testing.T, fsys afero.Fs, repoRoot fs.AbsolutePath) *TurborepoConfig { + path := repoRoot.Join(".turbo", "config.json") + initial := &TurborepoConfig{ + TeamSlug: "my-team", + } + toWrite, err := json.Marshal(initial) + if err != nil { + t.Fatalf("marshal config: %v", err) + } + err = fs.WriteFile(fsys, path, toWrite, os.ModePerm) + if err != nil { + t.Fatalf("writing config file: %v", err) + } + return initial +} + +func TestRepoConfigIncludesDefaults(t *testing.T) { + fsys := afero.NewMemMapFs() + cwd, err := fs.GetCwd() + if err != nil { + t.Fatalf("getting cwd: %v", err) + } + + initial := writePartialInitialConfig(t, fsys, cwd) + + config, err := ReadRepoConfigFile(fsys, cwd) + if err != nil { + t.Errorf("ReadRepoConfigFile err got %v, want ", err) + } + defaultConfig := defaultRepoConfig() + if config.ApiUrl != defaultConfig.ApiUrl { + t.Errorf("api url got %v, want %v", config.ApiUrl, defaultConfig.ApiUrl) + } + if config.TeamSlug != initial.TeamSlug { + t.Errorf("team slug got %v, want %v", config.TeamSlug, initial.TeamSlug) + } +} + +func TestWriteRepoConfig(t *testing.T) { + fsys := afero.NewMemMapFs() + cwd, err := fs.GetCwd() + if err != nil { + t.Fatalf("getting cwd: %v", err) + } + + initial := &TurborepoConfig{} + initial.TeamSlug = "my-team" + err = WriteRepoConfigFile(fsys, cwd, initial) + if err != nil { + t.Errorf("WriteRepoConfigFile got %v, want ", err) + } + + config, err := ReadRepoConfigFile(fsys, cwd) + if err != nil { + t.Errorf("ReadRepoConfig err got %v, want ", err) + } + if config.TeamSlug != initial.TeamSlug { + t.Errorf("TeamSlug got %v want %v", config.TeamSlug, initial.TeamSlug) + } + defaultConfig := defaultRepoConfig() + if config.ApiUrl != defaultConfig.ApiUrl { + t.Errorf("ApiUrl got %v, want %v", config.ApiUrl, defaultConfig.ApiUrl) + } +} + +func TestReadUserConfigWhenMissing(t *testing.T) { + fsys := afero.NewMemMapFs() + config, err := ReadUserConfigFile(fsys) + if err != nil { + t.Errorf("ReadUserConfig err got %v, want ", err) + } + if config != nil { + t.Errorf("ReadUserConfig on non-existent file got %v, want ", config) + } +} + +func TestWriteUserConfig(t *testing.T) { + fsys := afero.NewMemMapFs() + initial := defaultUserConfig() + initial.Token = "my-token" + initial.ApiUrl = "https://api.vercel.com" // should be overridden + err := WriteUserConfigFile(fsys, initial) + if err != nil { + t.Errorf("WriteUserConfigFile err got %v, want ", err) + } + + config, err := ReadUserConfigFile(fsys) + if err != nil { + t.Errorf("ReadUserConfig err got %v, want ", err) + } + if config.Token != initial.Token { + t.Errorf("Token got %v want %v", config.Token, initial.Token) + } + // Verify that our legacy ApiUrl was upgraded + defaultConfig := defaultUserConfig() + if config.ApiUrl != defaultConfig.ApiUrl { + t.Errorf("ApiUrl got %v, want %v", config.ApiUrl, defaultConfig.ApiUrl) + } + + err = DeleteUserConfigFile(fsys) + if err != nil { + t.Errorf("DeleteUserConfigFile err got %v, want ", err) + } + + missing, err := ReadUserConfigFile(fsys) + if err != nil { + t.Errorf("ReadUserConfig err got %v, want ", err) + } + if missing != nil { + t.Errorf("reading deleted config got %v, want ", missing) + } +} diff --git a/cli/internal/fs/path.go b/cli/internal/fs/path.go index 97afca0c3b5c5..bde8d2eec8abb 100644 --- a/cli/internal/fs/path.go +++ b/cli/internal/fs/path.go @@ -53,16 +53,10 @@ func (ap AbsolutePath) Dir() AbsolutePath { func (ap AbsolutePath) MkdirAll() error { return os.MkdirAll(ap.asString(), DirPermissions) } -func (ap AbsolutePath) Remove() error { - return os.Remove(ap.asString()) -} func (ap AbsolutePath) Open() (*os.File, error) { return os.Open(ap.asString()) } -// func (ap AbsolutePath) ReadFile() ([]byte, error) { -// return ioutil.ReadFile(ap.asString()) -// } func (ap AbsolutePath) FileExists() bool { return FileExists(ap.asString()) } @@ -88,3 +82,11 @@ func EnsureDirFS(fs afero.Fs, filename AbsolutePath) error { func WriteFile(fs afero.Fs, filename AbsolutePath, toWrite []byte, mode os.FileMode) error { return afero.WriteFile(fs, filename.asString(), toWrite, mode) } + +func ReadFile(fs afero.Fs, filename AbsolutePath) ([]byte, error) { + return afero.ReadFile(fs, filename.asString()) +} + +func RemoveFile(fs afero.Fs, filename AbsolutePath) error { + return fs.Remove(filename.asString()) +} diff --git a/cli/internal/login/login.go b/cli/internal/login/login.go index f8ac895138154..0ea08d71db6c1 100644 --- a/cli/internal/login/login.go +++ b/cli/internal/login/login.go @@ -14,12 +14,14 @@ import ( "github.com/pkg/errors" "github.com/vercel/turborepo/cli/internal/client" "github.com/vercel/turborepo/cli/internal/config" + "github.com/vercel/turborepo/cli/internal/fs" "github.com/vercel/turborepo/cli/internal/ui" "github.com/vercel/turborepo/cli/internal/util" "github.com/vercel/turborepo/cli/internal/util/browser" "github.com/fatih/color" "github.com/mitchellh/cli" + "github.com/spf13/afero" "github.com/spf13/cobra" ) @@ -61,12 +63,14 @@ func (c *LoginCommand) Run(args []string) int { Short: "Login to your Vercel account", RunE: func(cmd *cobra.Command, args []string) error { login := login{ - ui: c.UI, - logger: c.Config.Logger, - openURL: browser.OpenBrowser, - client: c.Config.ApiClient, - writeUserConfig: config.WriteUserConfigFile, - writeRepoConfig: config.WriteRepoConfigFile, + ui: c.UI, + logger: c.Config.Logger, + fsys: c.Config.Fs, + repoRoot: c.Config.Cwd, + openURL: browser.OpenBrowser, + client: c.Config.ApiClient, + //writeUserConfig: config.WriteUserConfigFile, + //writeRepoConfig: config.WriteRepoConfigFile, promptEnableCaching: promptEnableCaching, } if ssoTeam != "" { @@ -112,12 +116,14 @@ type userClient interface { type configWriter = func(cf *config.TurborepoConfig) error type login struct { - ui *cli.ColoredUi - logger hclog.Logger - openURL browserClient - client userClient - writeUserConfig configWriter - writeRepoConfig configWriter + ui *cli.ColoredUi + logger hclog.Logger + fsys afero.Fs + repoRoot fs.AbsolutePath + openURL browserClient + client userClient + //writeUserConfig configWriter + //writeRepoConfig configWriter promptEnableCaching func() (bool, error) } @@ -159,9 +165,9 @@ func (l *login) run(c *config.Config) error { // Stop the spinner before we return to ensure terminal is left in a good state s.Stop("") - err = l.writeUserConfig(&config.TurborepoConfig{Token: query.Get("token")}) + err = config.WriteUserConfigFile(l.fsys, &config.TurborepoConfig{Token: query.Get("token")}) if err != nil { - return errors.Wrap(err, "failed to write user config") + return err } rawToken := query.Get("token") l.client.SetToken(rawToken) @@ -234,7 +240,7 @@ func (l *login) loginSSO(c *config.Config, ssoTeam string) error { if err != nil { return errors.Wrap(err, "could not get user information") } - err = l.writeUserConfig(&config.TurborepoConfig{Token: verifiedUser.Token}) + err = config.WriteUserConfigFile(l.fsys, &config.TurborepoConfig{Token: verifiedUser.Token}) if err != nil { return errors.Wrap(err, "failed to save auth token") } @@ -246,7 +252,7 @@ func (l *login) loginSSO(c *config.Config, ssoTeam string) error { if err != nil { return err } - err = l.writeRepoConfig(&config.TurborepoConfig{TeamId: verifiedUser.TeamID, ApiUrl: c.ApiUrl}) + err = config.WriteRepoConfigFile(l.fsys, l.repoRoot, &config.TurborepoConfig{TeamId: verifiedUser.TeamID, ApiUrl: c.ApiUrl}) if err != nil { return errors.Wrap(err, "failed to save teamId") } diff --git a/cli/internal/login/login_test.go b/cli/internal/login/login_test.go index 1e9ae42c4d43c..d905283751e4a 100644 --- a/cli/internal/login/login_test.go +++ b/cli/internal/login/login_test.go @@ -9,8 +9,10 @@ import ( "github.com/hashicorp/go-hclog" "github.com/pkg/errors" + "github.com/spf13/afero" "github.com/vercel/turborepo/cli/internal/client" "github.com/vercel/turborepo/cli/internal/config" + "github.com/vercel/turborepo/cli/internal/fs" "github.com/vercel/turborepo/cli/internal/ui" "github.com/vercel/turborepo/cli/internal/util" ) @@ -57,15 +59,32 @@ var cf = &config.Config{ } type testResult struct { + fsys afero.Fs + repoRoot fs.AbsolutePath clientErr error - userConfigWritten *config.TurborepoConfig - repoConfigWritten *config.TurborepoConfig + clientTokenWritten string openedURL string stepCh chan struct{} client dummyClient shouldEnableCaching bool } +func (tr *testResult) userConfigWritten(t *testing.T) *config.TurborepoConfig { + config, err := config.ReadUserConfigFile(tr.fsys) + if err != nil { + t.Fatalf("failed reading user config: %v", err) + } + return config +} + +func (tr *testResult) repoConfigWritten(t *testing.T) *config.TurborepoConfig { + config, err := config.ReadRepoConfigFile(tr.fsys, tr.repoRoot) + if err != nil { + t.Fatalf("failed reading repo config: %v", err) + } + return config +} + func (tr *testResult) getTestLogin() login { urlOpener := func(url string) error { tr.openedURL = url @@ -73,28 +92,29 @@ func (tr *testResult) getTestLogin() login { return nil } return login{ - ui: ui.Default(), - logger: hclog.Default(), - openURL: urlOpener, - client: &tr.client, - writeUserConfig: func(cf *config.TurborepoConfig) error { - tr.userConfigWritten = cf - return nil - }, - writeRepoConfig: func(cf *config.TurborepoConfig) error { - tr.repoConfigWritten = cf - return nil - }, + ui: ui.Default(), + logger: hclog.Default(), + fsys: tr.fsys, + repoRoot: tr.repoRoot, + openURL: urlOpener, + client: &tr.client, promptEnableCaching: func() (bool, error) { return tr.shouldEnableCaching, nil }, } } -func newTest(redirectedURL string) *testResult { +func newTest(t *testing.T, redirectedURL string) *testResult { + fsys := afero.NewMemMapFs() stepCh := make(chan struct{}, 1) + cwd, err := fs.GetCwd() + if err != nil { + t.Fatalf("getting cwd: %v", err) + } tr := &testResult{ - stepCh: stepCh, + fsys: fsys, + repoRoot: cwd, + stepCh: stepCh, } tr.client.team = &client.Team{ ID: "sso-team-id", @@ -120,7 +140,7 @@ func newTest(redirectedURL string) *testResult { } func Test_run(t *testing.T) { - test := newTest("http://127.0.0.1:9789/?token=my-token") + test := newTest(t, "http://127.0.0.1:9789/?token=my-token") login := test.getTestLogin() err := login.run(cf) if err != nil { @@ -135,8 +155,9 @@ func Test_run(t *testing.T) { t.Errorf("openedURL got %v, want %v", test.openedURL, expectedURL) } - if test.userConfigWritten.Token != "my-token" { - t.Errorf("config token got %v, want my-token", test.userConfigWritten.Token) + userConfig := test.userConfigWritten(t) + if userConfig.Token != "my-token" { + t.Errorf("config token got %v, want my-token", userConfig.Token) } if test.client.setToken != "my-token" { t.Errorf("user client token got %v, want my-token", test.client.setToken) @@ -147,7 +168,7 @@ func Test_sso(t *testing.T) { redirectParams := make(url.Values) redirectParams.Add("token", "verification-token") redirectParams.Add("email", "test@example.com") - test := newTest("http://127.0.0.1:9789/?" + redirectParams.Encode()) + test := newTest(t, "http://127.0.0.1:9789/?"+redirectParams.Encode()) login := test.getTestLogin() err := login.loginSSO(cf, "my-team") if err != nil { @@ -168,15 +189,17 @@ func Test_sso(t *testing.T) { if test.client.setToken != expectedToken { t.Errorf("user client token got %v, want %v", test.client.setToken, expectedToken) } - if test.userConfigWritten.Token != expectedToken { - t.Errorf("user config token got %v want %v", test.userConfigWritten.Token, expectedToken) + userConfigWritten := test.userConfigWritten(t) + if userConfigWritten.Token != expectedToken { + t.Errorf("user config token got %v want %v", userConfigWritten.Token, expectedToken) } + repoConfigWritten := test.repoConfigWritten(t) expectedTeamID := "sso-team-id" - if test.repoConfigWritten.TeamId != expectedTeamID { - t.Errorf("repo config team id got %v want %v", test.repoConfigWritten.TeamId, expectedTeamID) + if repoConfigWritten.TeamId != expectedTeamID { + t.Errorf("repo config team id got %v want %v", repoConfigWritten.TeamId, expectedTeamID) } - if test.repoConfigWritten.Token != "" { - t.Errorf("repo config file token, got %v want empty string", test.repoConfigWritten.Token) + if repoConfigWritten.Token != "" { + t.Errorf("repo config file token, got %v want empty string", repoConfigWritten.Token) } } @@ -184,7 +207,7 @@ func Test_ssoCachingDisabledShouldEnable(t *testing.T) { redirectParams := make(url.Values) redirectParams.Add("token", "verification-token") redirectParams.Add("email", "test@example.com") - test := newTest("http://127.0.0.1:9789/?" + redirectParams.Encode()) + test := newTest(t, "http://127.0.0.1:9789/?"+redirectParams.Encode()) test.shouldEnableCaching = true test.client.cachingStatus = util.CachingStatusDisabled login := test.getTestLogin() @@ -200,7 +223,7 @@ func Test_ssoCachingDisabledDontEnable(t *testing.T) { redirectParams := make(url.Values) redirectParams.Add("token", "verification-token") redirectParams.Add("email", "test@example.com") - test := newTest("http://127.0.0.1:9789/?" + redirectParams.Encode()) + test := newTest(t, "http://127.0.0.1:9789/?"+redirectParams.Encode()) test.shouldEnableCaching = false test.client.cachingStatus = util.CachingStatusDisabled login := test.getTestLogin() diff --git a/cli/internal/login/logout.go b/cli/internal/login/logout.go index 25334bb26ae0b..083e4fd27bb0e 100644 --- a/cli/internal/login/logout.go +++ b/cli/internal/login/logout.go @@ -36,7 +36,7 @@ Usage: turbo logout // Run executes tasks in the monorepo func (c *LogoutCommand) Run(args []string) int { - if err := config.DeleteUserConfigFileToMigrate(); err != nil { + if err := config.DeleteUserConfigFile(c.Config.Fs); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("could not logout. Something went wrong: %w", err)) return 1 } diff --git a/cli/internal/login/unlink.go b/cli/internal/login/unlink.go index b251d9857ba02..f838d9af80919 100644 --- a/cli/internal/login/unlink.go +++ b/cli/internal/login/unlink.go @@ -36,7 +36,7 @@ Usage: turbo unlink // Run executes tasks in the monorepo func (c *UnlinkCommand) Run(args []string) int { - if err := config.WriteRepoConfigFileToMigrate(&config.TurborepoConfig{}); err != nil { + if err := config.WriteRepoConfigFile(c.Config.Fs, c.Config.Cwd, &config.TurborepoConfig{}); err != nil { c.logError(c.Config.Logger, "", fmt.Errorf("could not unlink. Something went wrong: %w", err)) return 1 }