change global fail to return result
@@ -6,15 +6,17 @@ import (
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
)
-var failed = false
-
func showStdoutResults(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
fmt.Printf("\n=== TEST %s\n", preflightName)
for _, analyzeResult := range analyzeResults {
fmt.Printf("=== RUN: %s\n", analyzeResult.Title)
}
+ var failed bool
for _, analyzeResult := range analyzeResults {
- outputResult(analyzeResult)
+ testResultfailed := outputResult(analyzeResult)
+ if testResultfailed {
+ failed = true
+ }
}
if failed {
fmt.Printf("--- FAIL %s\n", preflightName)
@@ -26,7 +28,7 @@ func showStdoutResults(preflightName string, analyzeResults []*analyzerunner.Ana
return nil
}
-func outputResult(analyzeResult *analyzerunner.AnalyzeResult) {
+func outputResult(analyzeResult *analyzerunner.AnalyzeResult) bool {
if analyzeResult.IsPass {
fmt.Printf(" --- PASS %s\n", analyzeResult.Title)
fmt.Printf(" --- %s\n", analyzeResult.Message)
@@ -34,8 +36,9 @@ func outputResult(analyzeResult *analyzerunner.AnalyzeResult) {
fmt.Printf(" --- WARN: %s\n", analyzeResult.Title)
fmt.Printf(" --- %s\n", analyzeResult.Message)
} else if analyzeResult.IsFail {
- failed = true
fmt.Printf(" --- FAIL: %s\n", analyzeResult.Title)
fmt.Printf(" --- %s\n", analyzeResult.Message)
+ return true
}
+ return false
}
