Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarPetrov committed Aug 20, 2019
1 parent e5cd43f commit 57b19a3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 100 deletions.
55 changes: 55 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config_test

import (
"fmt"
"github.com/Peripli/service-manager/pkg/health"
"testing"
"time"

Expand All @@ -44,18 +45,72 @@ var _ = Describe("config", func() {
)

Describe("Validate", func() {
var fatal bool
var failuresTreshold int64
var interval time.Duration

assertErrorDuringValidate := func() {
err = config.Validate()
Expect(err).To(HaveOccurred())
}

registerIndicatorSettings := func() {
indicatorSettings := &health.IndicatorSettings{
Fatal: fatal,
FailuresTreshold: failuresTreshold,
Interval: interval,
}

config.Health.IndicatorsSettings["test"] = indicatorSettings
}

BeforeEach(func() {
config = cfg.DefaultSettings()
config.Storage.URI = "postgres://postgres:postgres@localhost:5555/postgres?sslmode=disable"
config.API.TokenIssuerURL = "http://example.com"
config.API.ClientID = "sm"
config.API.SkipSSLValidation = true
config.Storage.EncryptionKey = "ejHjRNHbS0NaqARSRvnweVV9zcmhQEa8"

fatal = false
failuresTreshold = 1
interval = 30 * time.Second
})

Context("health indicator with negative treshold", func() {
It("should be considered invalid", func() {
failuresTreshold = -1
registerIndicatorSettings()
assertErrorDuringValidate()
})
})

Context("health indicator with 0 treshold", func() {
It("should be considered invalid", func() {
failuresTreshold = 0
registerIndicatorSettings()
assertErrorDuringValidate()
})
})

Context("health indicator with interval less than 30", func() {
It("should be considered invalid", func() {
interval = 15 * time.Second
registerIndicatorSettings()
assertErrorDuringValidate()
})
})

Context("health indicator with positive treshold and interval >= 30", func() {
It("should be considered valid", func() {
interval = 30 * time.Second
failuresTreshold = 3
registerIndicatorSettings()

err := config.Validate()

Expect(err).ShouldNot(HaveOccurred())
})
})

Context("when config is valid", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/health/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (*pingIndicator) Name() string {
}

func (*pingIndicator) Interval() time.Duration {
return 30
return 30 * time.Second
}

func (*pingIndicator) FailuresTreshold() int64 {
Expand Down
99 changes: 0 additions & 99 deletions pkg/health/settings_test.go

This file was deleted.

0 comments on commit 57b19a3

Please sign in to comment.