Mark more unit tests as 'integration' tests when they rely on external services/docker

This commit is contained in:
Cameron Sparr 2015-08-04 14:52:44 -06:00
parent 06a84def5f
commit 5259c50612
7 changed files with 75 additions and 25 deletions

View File

@ -1,12 +1,26 @@
UNAME := $(shell sh -c 'uname')
ifeq ($(UNAME), Darwin)
export ADVERTISED_HOST := $(shell sh -c 'boot2docker ip')
endif
ifeq ($(UNAME), Linux)
export ADVERTISED_HOST := localhost
endif
prepare:
go get -d -v -t ./...
docker-compose up -d --no-recreate
docker-compose:
docker-compose up -d
test: prepare docker-compose
go test -v ./...
test-short: prepare
go test -short ./...
go test -v -short ./...
test: prepare
go test ./...
test-cleanup:
docker-compose kill
update:
go get -u -v -d -t ./...

View File

@ -184,29 +184,29 @@ func init() {
## Testing
As Telegraf collects metrics from several third-party services it becomes a difficult task to mock each service as
some of them have complicated protocols which would take some time to replicate.
To overcome this situation we've decided to use docker containers to provide a fast and reproducible environment
to test those services which require it. For other situations (i.e: https://github.com/influxdb/telegraf/blob/master/plugins/redis/redis_test.go ) a simple mock will suffice.
To execute Telegraf tests follow these simple steps:
- Install docker compose following [these](https://docs.docker.com/compose/install/) instructions
- NOTE: mac users should be able to simply do `brew install boot2docker` and `brew install docker-compose`
### Execute short tests:
execute `make short-test`
### Execute long tests:
These tests requre additional docker containers, such as for kafka
Mac:
execute ``ADVERTISED_HOST=`boot2docker ip` make test``
As Telegraf collects metrics from several third-party services it becomes a
difficult task to mock each service as some of them have complicated protocols
which would take some time to replicate.
Linux:
execute `ADVERTISED_HOST=localhost make test`
To overcome this situation we've decided to use docker containers to provide a
fast and reproducible environment to test those services which require it.
For other situations
(i.e: https://github.com/influxdb/telegraf/blob/master/plugins/redis/redis_test.go )
a simple mock will suffice.
To execute Telegraf tests follow these simple steps:
- Install docker compose following [these](https://docs.docker.com/compose/install/) instructions
- NOTE: mac users should be able to simply do `brew install boot2docker`
and `brew install docker-compose`
execute `make test`
### Unit test troubleshooting:

View File

@ -19,5 +19,6 @@ test:
- golint .
- golint testutil/...
- golint cmd/...
# TODO run unit tests
# - go test -short ./...
# Run short unit tests
- go test -v -short ./...
# TODO run full unit test suite

View File

@ -9,6 +9,10 @@ import (
)
func TestMemcachedGeneratesMetrics(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
m := &Memcached{
Servers: []string{testutil.GetLocalHost()},
}

View File

@ -11,6 +11,10 @@ import (
)
func TestMysqlGeneratesMetrics(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
m := &Mysql{
Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())},
}
@ -54,6 +58,10 @@ func TestMysqlGeneratesMetrics(t *testing.T) {
}
func TestMysqlDefaultsToLocal(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
m := &Mysql{
Servers: []string{fmt.Sprintf("root@tcp(%s:3306)/", testutil.GetLocalHost())},
}

View File

@ -10,10 +10,15 @@ import (
)
func TestPostgresqlGeneratesMetrics(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
p := &Postgresql{
Servers: []*Server{
{
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()),
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
testutil.GetLocalHost()),
Databases: []string{"postgres"},
},
},
@ -55,10 +60,15 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
}
func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
p := &Postgresql{
Servers: []*Server{
{
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()),
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
testutil.GetLocalHost()),
Databases: []string{"postgres"},
},
},
@ -76,10 +86,15 @@ func TestPostgresqlTagsMetricsWithDatabaseName(t *testing.T) {
}
func TestPostgresqlDefaultsToAllDatabases(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
p := &Postgresql{
Servers: []*Server{
{
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()),
Address: fmt.Sprintf("host=%s user=postgres sslmode=disable",
testutil.GetLocalHost()),
},
},
}

View File

@ -12,6 +12,10 @@ import (
)
func TestRedisGeneratesMetrics(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
l, err := net.Listen("tcp", ":0")
require.NoError(t, err)
@ -103,6 +107,10 @@ func TestRedisGeneratesMetrics(t *testing.T) {
}
func TestRedisCanPullStatsFromMultipleServers(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
l, err := net.Listen("tcp", ":0")
require.NoError(t, err)