Skip to content

Commit

Permalink
Merge pull request #44 from InVisionApp/emptyok
Browse files Browse the repository at this point in the history
Do not error on empty check config list
  • Loading branch information
talpert authored Jul 25, 2018
2 parents 08eeb4f + 7bac852 commit 67b4fbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 5 additions & 4 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ func (h *Health) AddChecks(cfgs []*Config) error {
return ErrNoAddCfgWhenActive
}

if len(cfgs) == 0 {
return ErrEmptyConfigs
}

h.configs = append(h.configs, cfgs...)

return nil
Expand All @@ -180,6 +176,11 @@ func (h *Health) Start() error {
return ErrAlreadyRunning
}

// if there are no check configs, this is a noop
if len(h.configs) < 1 {
return nil
}

for _, c := range h.configs {
h.Logger.WithFields(log.Fields{"name": c.Name}).Debug("Starting checker")
ticker := time.NewTicker(c.Interval)
Expand Down
16 changes: 13 additions & 3 deletions health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ func TestAddChecks(t *testing.T) {
Expect(err).To(Equal(ErrNoAddCfgWhenActive))
})

t.Run("Should error if passed in empty config slice", func(t *testing.T) {
t.Run("Should not error if passed in empty config slice", func(t *testing.T) {
h := setupNewTestHealth()
err := h.AddChecks([]*Config{})

Expect(err).To(HaveOccurred())
Expect(err).To(Equal(ErrEmptyConfigs))
Expect(err).ToNot(HaveOccurred())
})
}

Expand Down Expand Up @@ -420,6 +419,17 @@ func TestStartRunner(t *testing.T) {
Expect(h.failed.val()).To(BeFalse())
})

t.Run("Happy path - no checkers is noop", func(t *testing.T) {
h := New()

Expect(h).ToNot(BeNil())

err := h.Start()
Expect(err).ToNot(HaveOccurred())

Expect(h.active.val()).To(BeFalse())
})

t.Run("Happy path - 1 checker fails (non-fatal)", func(t *testing.T) {
checker1 := &fakes.FakeICheckable{}
checker2 := &fakes.FakeICheckable{}
Expand Down

0 comments on commit 67b4fbf

Please sign in to comment.