Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sentinel error to indicate a check has not run yet #57

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gosundheit

import (
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -75,10 +74,10 @@ func (h *health) RegisterCheck(check Check, opts ...CheckOption) error {
// checks are initially failing by default, but we allow overrides...
var initialErr error
if !cfg.initiallyPassing {
initialErr = fmt.Errorf(initialResultMsg)
initialErr = ErrNotRunYet
}

result := h.updateResult(check.Name(), initialResultMsg, 0, initialErr, time.Now())
result := h.updateResult(check.Name(), ErrNotRunYet.Error(), 0, initialErr, time.Now())
h.checksListener.OnCheckRegistered(check.Name(), result)
h.scheduleCheck(h.createCheckTask(check, cfg.executionTimeout), cfg.initialDelay, cfg.executionPeriod)
return nil
Expand Down
2 changes: 2 additions & 0 deletions health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func TestRegisterDeregister(t *testing.T) {
assert.False(t, failingCheck.IsHealthy(), "check initially fails until first execution by default")
assert.True(t, initiallyPassingCheck.IsHealthy(), "check should initially pass")
assert.Contains(t, passingCheck.String(), "didn't run yet", "initial details")
assert.EqualError(t, passingCheck.Error, gosundheit.ErrNotRunYet.Error(), "initial details")
assert.Contains(t, failingCheck.String(), "didn't run yet", "initial details")
assert.EqualError(t, failingCheck.Error, gosundheit.ErrNotRunYet.Error(), "initial details")
assert.Contains(t, initiallyPassingCheck.String(), "didn't run yet", "initial details")

// await first execution
Expand Down
5 changes: 4 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (

const (
maxExpectedChecks = 16
initialResultMsg = "didn't run yet"
// ValAllChecks is the value used for the check tags when tagging all tests
ValAllChecks = "all_checks"
)

var (
ErrNotRunYet = errors.New("didn't run yet")
)

// Result represents the output of a health check execution.
type Result struct {
// the details of task Result - may be nil
Expand Down
Loading