From d6c25450b0aa9bfd5e3a301f61aedb63d4384e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 20 Jun 2023 09:02:55 +0200 Subject: [PATCH 1/3] Use GetStatus function to retrieve status from partials in creation of summary for overall result --- result/overall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/result/overall.go b/result/overall.go index 8f02c2c..357b10e 100644 --- a/result/overall.go +++ b/result/overall.go @@ -196,7 +196,7 @@ func (o *Overall) GetSummary() string { ) for _, sc := range o.PartialResults { - switch sc.state { + switch sc.GetStatus() { case check.Critical: criticals++ case check.Warning: From 76433fed5c1ba28dec6990924a9e629fe9da5550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 20 Jun 2023 09:06:04 +0200 Subject: [PATCH 2/3] Remove leftovers in tests --- result/overall_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/result/overall_test.go b/result/overall_test.go index 916003c..8468bf4 100644 --- a/result/overall_test.go +++ b/result/overall_test.go @@ -338,22 +338,19 @@ func TestOverall_withSubchecks_PartialResultStatus(t *testing.T) { var overall Overall subcheck := PartialResult{ - stateSetExplicitely: true, - Output: "Subcheck", + Output: "Subcheck", } subcheck.SetState(check.OK) subsubcheck := PartialResult{ - stateSetExplicitely: true, - Output: "SubSubcheck", + Output: "SubSubcheck", } subsubcheck.SetState(check.Warning) subsubsubcheck := PartialResult{ - stateSetExplicitely: true, - Output: "SubSubSubcheck", + Output: "SubSubSubcheck", } subsubsubcheck.SetState(check.Critical) From 18c27470f17549828fc40e365fab467aa8df294d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 20 Jun 2023 09:11:08 +0200 Subject: [PATCH 3/3] Add tests for changes --- result/overall_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/result/overall_test.go b/result/overall_test.go index 8468bf4..ad3a1fa 100644 --- a/result/overall_test.go +++ b/result/overall_test.go @@ -442,3 +442,29 @@ func TestDefaultStates3(t *testing.T) { assert.Equal(t, check.Warning, overall.GetStatus()) } + +func TestOverallOutputWithMultiLayerPartials(t *testing.T) { + var overall Overall + + subcheck1 := PartialResult{} + subcheck1.SetState(check.Warning) + + subcheck2 := PartialResult{} + + subcheck2_1 := PartialResult{} + subcheck2_1.SetState(check.OK) + + subcheck2_2 := PartialResult{} + subcheck2_2.SetState(check.Critical) + + subcheck2.AddSubcheck(subcheck2_1) + subcheck2.AddSubcheck(subcheck2_2) + + overall.AddSubcheck(subcheck1) + overall.AddSubcheck(subcheck2) + + resultString := "states: critical=1 warning=1\n\\_ [WARNING] \n\\_ [CRITICAL] \n \\_ [OK] \n \\_ [CRITICAL] \n" + + assert.Equal(t, resultString, overall.GetOutput()) + assert.Equal(t, check.Critical, overall.GetStatus()) +}