Skip to content

Commit f0b9322

Browse files
committed
chore: rename the updated atomic to make more sense
1 parent dc27ddd commit f0b9322

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

pkg/commands/app.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,8 @@ func NewRootCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
243243
}
244244
},
245245
PersistentPostRun: func(_ *cobra.Command, _ []string) {
246-
if globalFlags.Quiet.Value() || globalFlags.NoNotices.Value() {
247-
// don't show alerts during quiet mode
248-
// or if the user has disabled notices
249-
return
250-
}
246+
// if the check hasn't run then it will
247+
// return immediately and won't print anything
251248
update.NotifyUpdates(os.Stderr)
252249
},
253250
}

pkg/update/check.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ type updateResponse struct {
3232
}
3333

3434
var (
35-
updatesApi = "https://api.trivy.cloud/check"
36-
updated atomic.Bool
37-
currentVersion string
38-
latestVersion updateResponse
35+
updatesApi = "https://api.trivy.cloud/check"
36+
responseRecieved atomic.Bool
37+
currentVersion string
38+
latestVersion updateResponse
3939
)
4040

4141
// CheckUpdate makes a best efforts request to determine the
@@ -73,19 +73,15 @@ func CheckUpdate(ctx context.Context, version string, args []string) {
7373
log.Warnf("Failed to decode the response: %v", err)
7474
return
7575
}
76-
updated.Store(true)
76+
responseRecieved.Store(true)
7777
log.Debug("[version] Details ready for printing")
7878
}()
7979
}
8080

8181
// NotifyUpdates prints any announcements or warnings
8282
// to the output writer, most likely stderr
8383
func NotifyUpdates(output io.Writer) {
84-
if !updated.Load() {
85-
// the update check didn't happen in time
86-
// or it had an error but we don't want to make noise
87-
// about it
88-
log.Debug("[version] Update check failed or didn't happen in time, check logs for more details")
84+
if !responseRecieved.Load() {
8985
return
9086
}
9187

pkg/update/check_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ func TestNotifyUpdates(t *testing.T) {
5858
for _, tt := range tests {
5959
t.Run(tt.name, func(t *testing.T) {
6060
// reset the updated flag
61-
updated.Store(false)
61+
responseRecieved.Store(false)
6262
server := httptest.NewServer(http.HandlerFunc(createHandler(t, tt.latestVersion, tt.announcements)))
6363
defer server.Close()
6464
updatesApi = server.URL
6565

6666
CheckUpdate(t.Context(), tt.currentVersion, nil)
67-
require.Eventually(t, updated.Load, time.Second*5, 500)
67+
require.Eventually(t, responseRecieved.Load, time.Second*5, 500)
6868

6969
sb := bytes.NewBufferString("")
7070
NotifyUpdates(sb)
@@ -102,14 +102,14 @@ func TestCheckUpdate(t *testing.T) {
102102
for _, tt := range tests {
103103
t.Run(tt.name, func(t *testing.T) {
104104
// reset the updated flag
105-
updated.Store(false)
105+
responseRecieved.Store(false)
106106

107107
server := httptest.NewServer(http.HandlerFunc(createHandler(t, tt.expectedVersion, tt.expectedAnnouncements)))
108108
defer server.Close()
109109
updatesApi = server.URL
110110

111111
CheckUpdate(t.Context(), tt.currentVersion, nil)
112-
require.Eventually(t, updated.Load, time.Second*2, 500)
112+
require.Eventually(t, responseRecieved.Load, time.Second*2, 500)
113113
assert.Equal(t, tt.expectedVersion, latestVersion.Trivy.LatestVersion)
114114
assert.ElementsMatch(t, tt.expectedAnnouncements, latestVersion.Announcements)
115115

0 commit comments

Comments
 (0)