Skip to content

Refactor result package#152

Open
RincewindsHat wants to merge 12 commits into
mainfrom
refactor_result
Open

Refactor result package#152
RincewindsHat wants to merge 12 commits into
mainfrom
refactor_result

Conversation

@RincewindsHat

@RincewindsHat RincewindsHat commented Jun 15, 2026

Copy link
Copy Markdown
Member

This patch removes some parts of the overall object in favor of putting everything into subcheck objects.

See #151

This patch removes some parts of the overall object in favor
of putting everything into subcheck objects.

@martialblog martialblog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

Note:

	if state < check.OK || state > check.Unknown {
		return errors.New("Default State is not a valid result state. Got " + state.String() + " which is not valid")
	}

We can probably remove this, since we now have proper types.

Comment thread result/overall.go Outdated
@martialblog martialblog added this to the v1.0.0 milestone Jun 15, 2026
@RincewindsHat

Copy link
Copy Markdown
Member Author

Very nice.

Note:

	if state < check.OK || state > check.Unknown {
		return errors.New("Default State is not a valid result state. Got " + state.String() + " which is not valid")
	}

We can probably remove this, since we now have proper types.

done

@RincewindsHat

Copy link
Copy Markdown
Member Author

sadly this conflicts with the recent changes on main which I did not have at that time. Gotta do an ugly merge now.

@martialblog martialblog marked this pull request as ready for review June 15, 2026 12:30
Lorenz Kästle added 4 commits June 15, 2026 15:27
This patch removes the "Summary" attribute from the overall
object and replaces the functionality with a generated
summary.
If the overall state is OK, the summary is either a user given
string from a new "OKSummary" attribute or auto generated
(as previously) with just a small statistics over the states
of all PartialResults.

If the overall state is NOT OK, the summary is fetched
from the worst-deepest-first PartialResult Output.
Comment thread status.go
}
}

func Compare(a Status, b Status) int {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the idea.

Needs godoc and a why doesn't it return a Status?

Also the function should be fully unittested and have an Example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should it return a Status?
I thought of the classic C style compare functions you can throw into qsort (3).

Yes, more tests and an example are a good idea.

Comment thread result/overall.go
// String returns the status and output of the PartialResult
func (s *PartialResult) String() string {
return fmt.Sprintf("[%s] %s", s.GetStatus(), s.Output)
OKSummary string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a small comment what the OKSummary is and what it does

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

Comment thread result/overall.go Outdated
}

func (o *Overall) getGenericSummary() string {
// OK state, but no Ok_summary set

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the comment is trying to say.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, leftover from moving stuff around

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gone

Comment thread result/overall.go
result := ""

for _, partRes := range s.PartialResults {
if check.Compare(worstState, partRes.GetStatus()) > 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the other way around?

func TestGetSummary_Worststate(t *testing.T) {
	o := Overall{}
	o.Add(check.Warning, "WARN1") 
	o.Add(check.Critical, "CRIT")
	o.Add(check.Warning, "WARN2")

	output := o.GetOutput() // Should be CRIT

	t.Log(output)
}

=== RUN   TestGetSummary_Worststate
    overall_test.go:528: WARN2
        \_ [WARNING] WARN1
        \_ [CRITICAL] CRIT
        \_ [WARNING] WARN2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need more unittests here as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an example you just invented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants