Skip tests requiring a DB connection with the '-short' flag

- go-test target for local testing
This commit is contained in:
David Campbell 2016-10-23 14:56:37 -07:00
parent ce1b59bb81
commit 9a558eed89
6 changed files with 44 additions and 3 deletions

View File

@ -1,14 +1,22 @@
TESTFLAGS?=
IMAGE=mattes/migrate IMAGE=mattes/migrate
DCR=docker-compose run --rm 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 all: release
clean: clean:
rm -f migrate rm -f migrate
test: fmt:
$(DCR) go-test @gofmt -s -w `go list -f {{.Dir}} ./... | grep -v "/vendor/"`
test: fmt
$(DCR) $(GOTEST)
go-test: fmt
@$(GOTEST)
build: build:
$(DCR) go-build $(DCR) go-build

View File

@ -13,6 +13,10 @@ import (
) )
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
var session *gocql.Session var session *gocql.Session
host := os.Getenv("CASSANDRA_PORT_9042_TCP_ADDR") host := os.Getenv("CASSANDRA_PORT_9042_TCP_ADDR")

View File

@ -14,6 +14,9 @@ import (
// TestMigrate runs some additional tests on Migrate(). // TestMigrate runs some additional tests on Migrate().
// Basic testing is already done in migrate/migrate_test.go // Basic testing is already done in migrate/migrate_test.go
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
host := os.Getenv("MYSQL_PORT_3306_TCP_ADDR") host := os.Getenv("MYSQL_PORT_3306_TCP_ADDR")
port := os.Getenv("MYSQL_PORT_3306_TCP_PORT") port := os.Getenv("MYSQL_PORT_3306_TCP_PORT")
driverUrl := "mysql://root@tcp(" + host + ":" + port + ")/migratetest" driverUrl := "mysql://root@tcp(" + host + ":" + port + ")/migratetest"

View File

@ -13,6 +13,10 @@ import (
// TestMigrate runs some additional tests on Migrate(). // TestMigrate runs some additional tests on Migrate().
// Basic testing is already done in migrate/migrate_test.go // Basic testing is already done in migrate/migrate_test.go
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
host := os.Getenv("POSTGRES_PORT_5432_TCP_ADDR") host := os.Getenv("POSTGRES_PORT_5432_TCP_ADDR")
port := os.Getenv("POSTGRES_PORT_5432_TCP_PORT") port := os.Getenv("POSTGRES_PORT_5432_TCP_PORT")
driverUrl := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable" driverUrl := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable"

View File

@ -12,6 +12,10 @@ import (
// TestMigrate runs some additional tests on Migrate() // TestMigrate runs some additional tests on Migrate()
// Basic testing is already done in migrate/migrate_test.go // Basic testing is already done in migrate/migrate_test.go
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
driverFile := ":memory:" driverFile := ":memory:"
driverUrl := "sqlite3://" + driverFile driverUrl := "sqlite3://" + driverFile

View File

@ -16,6 +16,9 @@ var driverUrls = []string{
} }
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
@ -57,6 +60,9 @@ func TestCreate(t *testing.T) {
} }
func TestReset(t *testing.T) { func TestReset(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/", "migrate-test") tmpdir, err := ioutil.TempDir("/", "migrate-test")
@ -82,6 +88,9 @@ func TestReset(t *testing.T) {
} }
func TestDown(t *testing.T) { func TestDown(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
@ -119,6 +128,9 @@ func TestDown(t *testing.T) {
} }
func TestUp(t *testing.T) { func TestUp(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
@ -156,6 +168,9 @@ func TestUp(t *testing.T) {
} }
func TestRedo(t *testing.T) { func TestRedo(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
@ -193,6 +208,9 @@ func TestRedo(t *testing.T) {
} }
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
for _, driverUrl := range driverUrls { for _, driverUrl := range driverUrls {
t.Logf("Test driver: %s", driverUrl) t.Logf("Test driver: %s", driverUrl)
tmpdir, err := ioutil.TempDir("/tmp", "migrate-test") tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")