Skip to content

Commit

Permalink
Remove redundant log
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Sep 22, 2024
1 parent d0a1173 commit 42f2527
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
38 changes: 11 additions & 27 deletions utils/cliutils/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

// TestSetAndGetLatestVersionCheckTime tests setting and getting the LatestCliVersionCheckTime
Expand All @@ -15,20 +17,14 @@ func TestSetAndGetLatestVersionCheckTime(t *testing.T) {
// Set the timestamp
timestamp := time.Now().UnixMilli()
err := SetCliLatestVersionCheckTime(timestamp)
if err != nil {
t.Fatalf("Failed to set LatestCliVersionCheckTime: %v", err)
}
assert.NoError(t, err, "Failed to set LatestCliVersionCheckTime")

// Get the timestamp
storedTimestamp, err := GetLatestCliVersionCheckTime()
if err != nil {
t.Fatalf("Failed to get LatestCliVersionCheckTime: %v", err)
}
assert.NoError(t, err, "Failed to get LatestCliVersionCheckTime")

// Assert equality
if *storedTimestamp != timestamp {
t.Fatalf("Expected %d, got %d", timestamp, *storedTimestamp)
}
assert.Equal(t, timestamp, *storedTimestamp, "Stored timestamp does not match the set timestamp")
}

// TestSetAndGetAiTermsVersion tests setting and getting the LatestAiTermsRevision
Expand All @@ -39,20 +35,14 @@ func TestSetAndGetAiTermsVersion(t *testing.T) {
// Set the AI terms version
version := 42
err := SetLatestAiTermsRevision(version)
if err != nil {
t.Fatalf("Failed to set LatestAiTermsRevision: %v", err)
}
assert.NoError(t, err, "Failed to set LatestAiTermsRevision")

// Get the AI terms version
storedVersion, err := GetLatestAiTermsRevision()
if err != nil {
t.Fatalf("Failed to get LatestAiTermsRevision: %v", err)
}
assert.NoError(t, err, "Failed to get LatestAiTermsRevision")

// Assert equality
if *storedVersion != version {
t.Fatalf("Expected %d, got %d", version, *storedVersion)
}
assert.Equal(t, version, *storedVersion, "Stored AI terms version does not match the set version")
}

// TestPersistenceFileCreation tests if the persistence file is created when it doesn't exist
Expand All @@ -62,20 +52,14 @@ func TestPersistenceFileCreation(t *testing.T) {

// Ensure the persistence file doesn't exist
_, err := os.Stat(persistenceFilePath)
if !os.IsNotExist(err) {
t.Fatalf("Expected file to not exist, but it does: %v", err)
}
assert.ErrorIs(t, err, os.ErrNotExist, "Expected error to be os.ErrNotExist")

// Trigger file creation by setting version check time
timestamp := time.Now().UnixMilli()
err = SetCliLatestVersionCheckTime(timestamp)
if err != nil {
t.Fatalf("Failed to set LatestCliVersionCheckTime: %v", err)
}
assert.NoError(t, err, "Failed to set LatestCliVersionCheckTime")

// Verify the persistence file was created
_, err = os.Stat(persistenceFilePath)
if os.IsNotExist(err) {
t.Fatalf("Expected file to exist, but it does not: %v", err)
}
assert.False(t, os.IsNotExist(err), "Expected file to exist, but it does not")
}
3 changes: 3 additions & 0 deletions utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ func GetDetailedSummary(c *cli.Context) bool {
return c.Bool("detailed-summary") || commandsummary.ShouldRecordSummary()
}

// Check if the latest CLI version should be checked via the GitHub API to let the user know if a newer version is available.
// To avoid checking this for every run, we check only if the last check was more than 6 hours ago.
// Also, if the user set the JFROG_CLI_AVOID_NEW_VERSION_WARNING environment variable to true, we won't check.
func shouldCheckLatestCliVersion() (shouldCheck bool, err error) {
if strings.ToLower(os.Getenv(JfrogCliAvoidNewVersionWarning)) == "true" {
return
Expand Down

0 comments on commit 42f2527

Please sign in to comment.