Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): non-interactive should not run daily version check #462

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

@dmurray-lacework dmurray-lacework Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a different task than what this ticket intended. I think it's correct(non-interactive when --json flag is set), but i'd maybe consider either adding more tests for this use case or moving it out of this PR.

}

// 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")
}