Skip to content

Commit

Permalink
🐛 Cli option takes precedence over the YAML (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid authored and qodana-bot committed May 3, 2024
1 parent 774bc8c commit c932f22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion platform/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func RunAnalysis(options *QodanaOptions) (int, error) {
}
log.Debugf("Java executable path: %s", mountInfo.JavaPath)

thresholds := getFailureThresholds(yaml)
thresholds := getFailureThresholds(yaml, options)
var analysisResult int
if analysisResult, err = computeBaselinePrintResults(options, mountInfo, thresholds); err != nil {
ErrorMessage(err.Error())
Expand Down
6 changes: 5 additions & 1 deletion platform/thresholds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const severityModerate = "moderate"
const severityLow = "low"
const severityInfo = "info"

func getFailureThresholds(yaml *QodanaYaml) map[string]string {
func getFailureThresholds(yaml *QodanaYaml, options *QodanaOptions) map[string]string {
ret := make(map[string]string)
if yaml.FailThreshold != nil {
ret[severityAny] = strconv.Itoa(*yaml.FailThreshold)
Expand All @@ -54,6 +54,10 @@ func getFailureThresholds(yaml *QodanaYaml) map[string]string {
ret[severityInfo] = strconv.Itoa(*thresholds.Info)
}
}
if options.FailThreshold != "" { // console option overrides the behavior
ret = make(map[string]string)
ret[severityAny] = options.FailThreshold
}
return ret
}

Expand Down
22 changes: 21 additions & 1 deletion platform/thresholds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ func TestFailureThresholds(t *testing.T) {
for _, testData := range []struct {
name string
yaml string
option string
expected string
}{
{
name: "empty",
yaml: "",
option: "",
expected: "",
},
{
name: "failThreshold set to 0",
yaml: `failThreshold: 0`,
option: "",
expected: " --threshold-any=0",
},
{
Expand All @@ -50,6 +53,7 @@ func TestFailureThresholds(t *testing.T) {
low: 5
info: 6
`,
option: "",
expected: " --threshold-any=1 --threshold-critical=2 --threshold-high=3 --threshold-info=6 --threshold-low=5 --threshold-moderate=4",
},
{
Expand All @@ -64,6 +68,7 @@ func TestFailureThresholds(t *testing.T) {
info: 6
failThreshold: 123
`,
option: "",
expected: " --threshold-any=1 --threshold-critical=2 --threshold-high=3 --threshold-info=6 --threshold-low=5 --threshold-moderate=4",
},
{
Expand All @@ -77,8 +82,23 @@ failThreshold: 123
info: 6
failThreshold: 123
`,
option: "",
expected: " --threshold-any=123 --threshold-critical=2 --threshold-high=3 --threshold-info=6 --threshold-low=5 --threshold-moderate=4",
},
{
name: "cli option ovevrrides yaml settings",
yaml: `failureConditions:
severityThresholds:
any: 1
critical: 2
high: 3
moderate: 4
low: 5
info: 6
`,
option: "123",
expected: " --threshold-any=123",
},
} {
t.Run(testData.name, func(t *testing.T) {
tempDir := t.TempDir()
Expand All @@ -89,7 +109,7 @@ failThreshold: 123
}
}
yaml := LoadQodanaYaml(tempDir, "qodana.yaml")
thresholds := getFailureThresholds(yaml)
thresholds := getFailureThresholds(yaml, &QodanaOptions{FailThreshold: testData.option})
thresholdArgs := thresholdsToArgs(thresholds)
sort.Strings(thresholdArgs)
argString := ""
Expand Down

0 comments on commit c932f22

Please sign in to comment.