From d2810ddc95b5400ef26a733d5fbe4a0a1f0acaea Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Mon, 6 Jul 2015 22:18:31 -0300 Subject: [PATCH] Add DOCKER_HOST support for tests This allows to run tests in environments where DOCKER_HOST is used. This is extremely helpful when using boot2docker to run docker --- plugins/memcached/memcached_test.go | 2 +- plugins/mysql/mysql_test.go | 5 +++-- plugins/postgresql/postgresql_test.go | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/memcached/memcached_test.go b/plugins/memcached/memcached_test.go index 08e696fb7..522fc7bc7 100644 --- a/plugins/memcached/memcached_test.go +++ b/plugins/memcached/memcached_test.go @@ -10,7 +10,7 @@ import ( func TestMemcachedGeneratesMetrics(t *testing.T) { m := &Memcached{ - Servers: []string{"localhost"}, + Servers: []string{testutil.GetLocalHost()}, } var acc testutil.Accumulator diff --git a/plugins/mysql/mysql_test.go b/plugins/mysql/mysql_test.go index f09c0307e..e29e2e12e 100644 --- a/plugins/mysql/mysql_test.go +++ b/plugins/mysql/mysql_test.go @@ -1,6 +1,7 @@ package mysql import ( + "fmt" "strings" "testing" @@ -11,7 +12,7 @@ import ( func TestMysqlGeneratesMetrics(t *testing.T) { m := &Mysql{ - Servers: []string{"root@tcp(localhost:3306)/"}, + Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())}, } var acc testutil.Accumulator @@ -54,7 +55,7 @@ func TestMysqlGeneratesMetrics(t *testing.T) { func TestMysqlDefaultsToLocal(t *testing.T) { m := &Mysql{ - Servers: []string{"root@tcp(localhost:3306)/"}, + Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())}, } var acc testutil.Accumulator diff --git a/plugins/postgresql/postgresql_test.go b/plugins/postgresql/postgresql_test.go index 775087700..f9fb2b98e 100644 --- a/plugins/postgresql/postgresql_test.go +++ b/plugins/postgresql/postgresql_test.go @@ -1,6 +1,7 @@ package postgresql import ( + "fmt" "testing" "github.com/influxdb/telegraf/testutil" @@ -12,7 +13,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) { p := &Postgresql{ Servers: []*Server{ { - Address: "host=localhost user=postgres sslmode=disable", + Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()), Databases: []string{"postgres"}, }, }, @@ -57,7 +58,7 @@ func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) { p := &Postgresql{ Servers: []*Server{ { - Address: "host=localhost user=postgres sslmode=disable", + Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()), Databases: []string{"postgres"}, }, }, @@ -78,7 +79,7 @@ func TestPostgresqlDefaultsToAllDatabases(t *testing.T) { p := &Postgresql{ Servers: []*Server{ { - Address: "host=localhost user=postgres sslmode=disable", + Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()), }, }, }