From 6cfc38caabefbab27a67fdcc6cdebab581fb0b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:17:47 +0100 Subject: [PATCH] Resolve states of partial results recursively and now correctly (#107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes a bug which causes PartialResults to show "wrong" states, when the state is derived from other PartialResults inside. The problem was a small piece of code which was forgotten, when the "explicit state" logic was introduced. Co-authored-by: Lorenz Kästle --- result/overall.go | 2 +- result/overall_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/result/overall.go b/result/overall.go index ad4ec9b..de7ccad 100644 --- a/result/overall.go +++ b/result/overall.go @@ -324,7 +324,7 @@ func (s *PartialResult) GetStatus() int { states := make([]int, len(s.PartialResults)) for i := range s.PartialResults { - states[i] = s.PartialResults[i].state + states[i] = s.PartialResults[i].GetStatus() } return WorstState(states...) diff --git a/result/overall_test.go b/result/overall_test.go index ff443e1..ab84109 100644 --- a/result/overall_test.go +++ b/result/overall_test.go @@ -323,15 +323,15 @@ func TestOverall_withSubchecks_PartialResult(t *testing.T) { overall.AddSubcheck(subcheck) - res := `states: ok=1 -\_ [OK] PartialResult + res := `states: critical=1 +\_ [CRITICAL] PartialResult \_ [CRITICAL] SubSubcheck \_ [CRITICAL] SubSubSubcheck |foo=3 bar=300% baz=23B ` assert.Equal(t, res, overall.GetOutput()) - assert.Equal(t, 0, overall.GetStatus()) + assert.Equal(t, check.Critical, overall.GetStatus()) } func TestOverall_withSubchecks_PartialResultStatus(t *testing.T) {