From 9a558eed89c0842953ce89dfd4d74a66c25c7a45 Mon Sep 17 00:00:00 2001 From: David Campbell Date: Sun, 23 Oct 2016 14:56:37 -0700 Subject: [PATCH] Skip tests requiring a DB connection with the '-short' flag - go-test target for local testing --- Makefile | 14 +++++++++++--- driver/cassandra/cassandra_test.go | 4 ++++ driver/mysql/mysql_test.go | 3 +++ driver/postgres/postgres_test.go | 4 ++++ driver/sqlite3/sqlite3_test.go | 4 ++++ migrate/migrate_test.go | 18 ++++++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9cee255..8e46968 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,22 @@ +TESTFLAGS?= IMAGE=mattes/migrate DCR=docker-compose run --rm -.PHONY: clean test build release docker-build docker-push run +GOTEST=go test $(TESTFLAGS) `go list ./... | grep -v "/vendor/"` +.PHONY: clean test build release docker-build docker-push run all: release clean: rm -f migrate -test: - $(DCR) go-test +fmt: + @gofmt -s -w `go list -f {{.Dir}} ./... | grep -v "/vendor/"` + +test: fmt + $(DCR) $(GOTEST) + +go-test: fmt + @$(GOTEST) build: $(DCR) go-build diff --git a/driver/cassandra/cassandra_test.go b/driver/cassandra/cassandra_test.go index ea73794..c068431 100644 --- a/driver/cassandra/cassandra_test.go +++ b/driver/cassandra/cassandra_test.go @@ -13,6 +13,10 @@ import ( ) func TestMigrate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + var session *gocql.Session host := os.Getenv("CASSANDRA_PORT_9042_TCP_ADDR") diff --git a/driver/mysql/mysql_test.go b/driver/mysql/mysql_test.go index 51cf552..ec19271 100644 --- a/driver/mysql/mysql_test.go +++ b/driver/mysql/mysql_test.go @@ -14,6 +14,9 @@ import ( // TestMigrate runs some additional tests on Migrate(). // Basic testing is already done in migrate/migrate_test.go func TestMigrate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } host := os.Getenv("MYSQL_PORT_3306_TCP_ADDR") port := os.Getenv("MYSQL_PORT_3306_TCP_PORT") driverUrl := "mysql://root@tcp(" + host + ":" + port + ")/migratetest" diff --git a/driver/postgres/postgres_test.go b/driver/postgres/postgres_test.go index ec91b35..a1c0495 100644 --- a/driver/postgres/postgres_test.go +++ b/driver/postgres/postgres_test.go @@ -13,6 +13,10 @@ import ( // TestMigrate runs some additional tests on Migrate(). // Basic testing is already done in migrate/migrate_test.go func TestMigrate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + host := os.Getenv("POSTGRES_PORT_5432_TCP_ADDR") port := os.Getenv("POSTGRES_PORT_5432_TCP_PORT") driverUrl := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable" diff --git a/driver/sqlite3/sqlite3_test.go b/driver/sqlite3/sqlite3_test.go index 8d51a7d..7f50095 100644 --- a/driver/sqlite3/sqlite3_test.go +++ b/driver/sqlite3/sqlite3_test.go @@ -12,6 +12,10 @@ import ( // TestMigrate runs some additional tests on Migrate() // Basic testing is already done in migrate/migrate_test.go func TestMigrate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + driverFile := ":memory:" driverUrl := "sqlite3://" + driverFile diff --git a/migrate/migrate_test.go b/migrate/migrate_test.go index 7d2a622..8549268 100644 --- a/migrate/migrate_test.go +++ b/migrate/migrate_test.go @@ -16,6 +16,9 @@ var driverUrls = []string{ } func TestCreate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") @@ -57,6 +60,9 @@ func TestCreate(t *testing.T) { } func TestReset(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/", "migrate-test") @@ -82,6 +88,9 @@ func TestReset(t *testing.T) { } func TestDown(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") @@ -119,6 +128,9 @@ func TestDown(t *testing.T) { } func TestUp(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") @@ -156,6 +168,9 @@ func TestUp(t *testing.T) { } func TestRedo(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") @@ -193,6 +208,9 @@ func TestRedo(t *testing.T) { } func TestMigrate(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } for _, driverUrl := range driverUrls { t.Logf("Test driver: %s", driverUrl) tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")