Skip to content

Commit

Permalink
Merge pull request #57 from dmarkhas/err_not_run_yet
Browse files Browse the repository at this point in the history
Add sentinel error to indicate a check has not run yet
  • Loading branch information
dmarkhas authored Jun 25, 2024
2 parents 2e0044a + 45b6bcd commit dc9ea3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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

0 comments on commit dc9ea3a

Please sign in to comment.