Skip to content

Commit

Permalink
fix(cli): non-interactive should not run daily version check (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
afiune authored Jul 2, 2021
1 parent 2ad47f7 commit 4bb7e9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/cmd/cli_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *cliState) NewClient() error {

// InteractiveMode returns true if the cli is running in interactive mode
func (c *cliState) InteractiveMode() bool {
return !c.nonInteractive && !c.csvOutput
return !c.nonInteractive && !c.csvOutput && !c.jsonOutput
}

// NonInteractive turns off interactive mode, that is, no progress bars and spinners
Expand Down
4 changes: 4 additions & 0 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func dailyVersionCheck() error {
return nil
}

if !cli.InteractiveMode() {
return nil
}

cacheDir, err := versionCacheDir()
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions integration/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,22 @@ func TestVersionCommand(t *testing.T) {
"version update message should be displayed",
)
}

func TestDailyVersionCheckShouldNotRunWhenInNonInteractiveMode(t *testing.T) {
enableTestingUpdaterEnv()
defer disableTestingUpdaterEnv()

home := createTOMLConfigFromCIvars()
defer os.RemoveAll(home)

out, err, exitcode := LaceworkCLIWithHome(home, "configure", "list", "--noninteractive")
assert.Empty(t, err.String())
assert.Equal(t, 0, exitcode)
assert.NotContains(t, out.String(),
"A newer version of the Lacework CLI is available! The latest version is v",
"we shouldn't see this daily version check message",
)

versionCacheFile := path.Join(home, ".config", "lacework", "version_cache")
assert.NoFileExists(t, versionCacheFile, "the version_cache file is missing")
}

0 comments on commit 4bb7e9f

Please sign in to comment.