Skip to content

Commit c0c4b33

Browse files
edit threshold message log (#328)
* edit threshold message log
1 parent 67ff9a3 commit c0c4b33

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

internal/commands/scan.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const (
3333
failedDeleting = "Failed deleting a scan"
3434
failedCanceling = "Failed canceling a scan"
3535
failedGettingAll = "Failed listing"
36-
thresholdLog = "Threshold %s: Limit = %d, Current = %v"
36+
thresholdLog = "%s: Limit = %d, Current = %v"
37+
thresholdMsgLog = "Threshold check finished with status %s : %s"
3738
mbBytes = 1024.0 * 1024.0
3839
resolverFilePerm = 0644
3940
)
@@ -1023,20 +1024,28 @@ func applyThreshold(cmd *cobra.Command, resultsWrapper wrappers.ResultsWrapper,
10231024
}
10241025

10251026
var errorBuilder strings.Builder
1027+
var messageBuilder strings.Builder
10261028
for key, thresholdLimit := range thresholdMap {
10271029
currentValue := summaryMap[key]
10281030
failed := currentValue >= thresholdLimit
10291031
logMessage := fmt.Sprintf(thresholdLog, key, thresholdLimit, currentValue)
1030-
log.Println(logMessage)
1032+
PrintIfVerbose(logMessage)
10311033

10321034
if failed {
10331035
errorBuilder.WriteString(fmt.Sprintf("%s | ", logMessage))
1036+
} else {
1037+
messageBuilder.WriteString(fmt.Sprintf("%s | ", logMessage))
10341038
}
10351039
}
10361040

10371041
errorMessage := errorBuilder.String()
10381042
if errorMessage != "" {
1039-
return errors.Errorf("%s", errorMessage)
1043+
return errors.Errorf(thresholdMsgLog, "Failed", errorMessage)
1044+
}
1045+
1046+
successMessage := messageBuilder.String()
1047+
if successMessage != "" {
1048+
log.Printf(thresholdMsgLog, "Success", successMessage)
10401049
}
10411050

10421051
return nil

test/integration/scan_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestScanCreateWithThreshold(t *testing.T) {
130130
}
131131

132132
err, _ := executeCommand(t, args...)
133-
assertError(t, err, "Threshold sast-low: Limit = 1")
133+
assertError(t, err, "Threshold check finished with status Failed")
134134
}
135135

136136
// Create a scan ignoring the exclusion of the .git directory

0 commit comments

Comments
 (0)