mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-08-27 00:37:20 +00:00
Accumulate all longhorn pass results
If there are any error or warning results then return those. Otherwise return a single healthy pass result.
This commit is contained in:
+23
-1
@@ -131,7 +131,7 @@ func longhorn(analyzer *troubleshootv1beta2.LonghornAnalyze, getCollectedFileCon
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
return simplifyLonghornResults(results), nil
|
||||
}
|
||||
|
||||
func analyzeLonghornNodeSchedulable(node *longhornv1beta1.Node) *AnalyzeResult {
|
||||
@@ -243,3 +243,25 @@ func analyzeLonghornReplicaChecksums(volumeName string, checksums []map[string]s
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Keep warn/error results. Return a single pass result if there are no warn/errors.
|
||||
func simplifyLonghornResults(results []*AnalyzeResult) []*AnalyzeResult {
|
||||
out := []*AnalyzeResult{}
|
||||
|
||||
for _, result := range results {
|
||||
if result.IsPass {
|
||||
continue
|
||||
}
|
||||
out = append(out, result)
|
||||
}
|
||||
|
||||
if len(out) == 0 {
|
||||
out = append(out, &AnalyzeResult{
|
||||
Title: "Longhorn Health Status",
|
||||
IsPass: true,
|
||||
Message: "Longhorn is healthy",
|
||||
})
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -382,3 +382,78 @@ func TestAnalyzeLonghornReplicaChecksums(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimplifyLonghornResults(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []*AnalyzeResult
|
||||
expect []*AnalyzeResult
|
||||
}{
|
||||
{
|
||||
name: "All pass",
|
||||
input: []*AnalyzeResult{
|
||||
{
|
||||
Title: "Replica 1",
|
||||
IsPass: true,
|
||||
Message: "Replica 1 ok",
|
||||
},
|
||||
{
|
||||
Title: "Node 1",
|
||||
IsPass: true,
|
||||
Message: "Node 1 ok",
|
||||
},
|
||||
},
|
||||
expect: []*AnalyzeResult{
|
||||
{
|
||||
Title: "Longhorn Health Status",
|
||||
IsPass: true,
|
||||
Message: "Longhorn is healthy",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Mixed results",
|
||||
input: []*AnalyzeResult{
|
||||
{
|
||||
Title: "Replica 1",
|
||||
IsPass: true,
|
||||
Message: "Replica 1 ok",
|
||||
},
|
||||
{
|
||||
Title: "Replica 2",
|
||||
IsWarn: true,
|
||||
Message: "Replica 1 is down",
|
||||
},
|
||||
{
|
||||
Title: "Node 1",
|
||||
IsPass: true,
|
||||
Message: "Node 1 ok",
|
||||
},
|
||||
{
|
||||
Title: "Node 2",
|
||||
IsFail: true,
|
||||
Message: "Node 2 is down",
|
||||
},
|
||||
},
|
||||
expect: []*AnalyzeResult{
|
||||
{
|
||||
Title: "Replica 2",
|
||||
IsWarn: true,
|
||||
Message: "Replica 1 is down",
|
||||
},
|
||||
{
|
||||
Title: "Node 2",
|
||||
IsFail: true,
|
||||
Message: "Node 2 is down",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := simplifyLonghornResults(test.input)
|
||||
|
||||
assert.Equal(t, test.expect, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user