Skip to content

Commit

Permalink
Merge pull request #13 from hellofresh/hotfix/defaults
Browse files Browse the repository at this point in the history
Fix for rabbit config defaults
  • Loading branch information
vgarvardt committed Mar 21, 2018
2 parents 8606da5 + 11b0109 commit 8b73daf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions checks/rabbitmq/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const (
defaultExchange = "health_check"
)

var (
defaultConsumeTimeout = time.Second * 3
)

type (
// Config is the RabbitMQ checker configuration settings container.
Config struct {
Expand Down Expand Up @@ -44,7 +48,7 @@ type (
// - publishing a message to the exchange with the defined routing key
// - consuming published message
func New(config Config) func() error {
config.defaults()
(&config).defaults()

return func() error {
conn, err := amqp.Dial(config.DSN)
Expand Down Expand Up @@ -117,7 +121,7 @@ func New(config Config) func() error {
}
}

func (c Config) defaults() {
func (c *Config) defaults() {
if c.LogFunc == nil {
c.LogFunc = func(err error, details string, extra ...interface{}) {}
}
Expand All @@ -139,6 +143,6 @@ func (c Config) defaults() {
}

if c.ConsumeTimeout == 0 {
c.ConsumeTimeout = time.Second * 3
c.ConsumeTimeout = defaultConsumeTimeout
}
}
16 changes: 16 additions & 0 deletions checks/rabbitmq/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ func TestNew(t *testing.T) {
t.Fatalf("RabbitMQ check failed: %s", err.Error())
}
}

func TestConfig(t *testing.T) {
conf := &Config{
DSN: os.Getenv(mqDSNEnv),
}

conf.defaults()

if conf.Exchange != defaultExchange {
t.Fatal("Invalid default conf exchange value")
}

if conf.ConsumeTimeout != defaultConsumeTimeout {
t.Fatal("Invalid default conf exchange value")
}
}

0 comments on commit 8b73daf

Please sign in to comment.