From 5f38d02b12eed5347ea7e3952009a6d5b0e9f5df Mon Sep 17 00:00:00 2001 From: Vladimir Garvardt Date: Wed, 21 Mar 2018 15:58:59 +0100 Subject: [PATCH 1/2] Fix for rabbit config defaults --- checks/rabbitmq/check.go | 6 +++++- checks/rabbitmq/check_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/checks/rabbitmq/check.go b/checks/rabbitmq/check.go index e18cc6a..c21308a 100644 --- a/checks/rabbitmq/check.go +++ b/checks/rabbitmq/check.go @@ -12,6 +12,10 @@ const ( defaultExchange = "health_check" ) +var ( + defaultConsumeTimeout = time.Second * 3 +) + type ( // Config is the RabbitMQ checker configuration settings container. Config struct { @@ -139,6 +143,6 @@ func (c Config) defaults() { } if c.ConsumeTimeout == 0 { - c.ConsumeTimeout = time.Second * 3 + c.ConsumeTimeout = defaultConsumeTimeout } } diff --git a/checks/rabbitmq/check_test.go b/checks/rabbitmq/check_test.go index 8101942..29fa682 100644 --- a/checks/rabbitmq/check_test.go +++ b/checks/rabbitmq/check_test.go @@ -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") + } +} From 11b01097a98178aa8835013a637bb3247b2dc9d9 Mon Sep 17 00:00:00 2001 From: Vladimir Garvardt Date: Wed, 21 Mar 2018 16:11:14 +0100 Subject: [PATCH 2/2] Fixed rabbit config defaults --- checks/rabbitmq/check.go | 4 ++-- checks/rabbitmq/check_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/checks/rabbitmq/check.go b/checks/rabbitmq/check.go index c21308a..5ab5f03 100644 --- a/checks/rabbitmq/check.go +++ b/checks/rabbitmq/check.go @@ -48,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) @@ -121,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{}) {} } diff --git a/checks/rabbitmq/check_test.go b/checks/rabbitmq/check_test.go index 29fa682..de77143 100644 --- a/checks/rabbitmq/check_test.go +++ b/checks/rabbitmq/check_test.go @@ -22,7 +22,7 @@ func TestNew(t *testing.T) { } func TestConfig(t *testing.T) { - conf := Config{ + conf := &Config{ DSN: os.Getenv(mqDSNEnv), }