From bc01eb28ada22b7413fd2452b1260c0787b79388 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 2 Jun 2020 00:24:16 +0800 Subject: [PATCH] Fix tests script --- tests/main_test.go | 5 +++++ tests/migrate_test.go | 2 +- tests/tests.go | 4 +--- tests/tests_all.sh | 10 ++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/main_test.go b/tests/main_test.go index 095588a2..60cc4611 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -6,6 +6,11 @@ import ( . "github.com/jinzhu/gorm/tests" ) +func TestMain(m *testing.M) { + RunMigrations() + m.Run() +} + func TestExceptionsWithInvalidSql(t *testing.T) { var columns []string if DB.Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil { diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 957db8d6..e786b1cc 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -25,7 +25,7 @@ func TestMigrate(t *testing.T) { for _, m := range allModels { if !DB.Migrator().HasTable(m) { - t.Fatalf("Failed to create table for %#v", m) + t.Fatalf("Failed to create table for %#v---", m) } } } diff --git a/tests/tests.go b/tests/tests.go index d9257898..fa8ac836 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -19,9 +19,7 @@ var DB *gorm.DB func init() { var err error - if DB, err = OpenTestConnection(); err == nil { - RunMigrations() - } else { + if DB, err = OpenTestConnection(); err != nil { log.Printf("failed to connect database, got error %v\n", err) os.Exit(1) } diff --git a/tests/tests_all.sh b/tests/tests_all.sh index 243af787..3a1b45c8 100755 --- a/tests/tests_all.sh +++ b/tests/tests_all.sh @@ -9,11 +9,17 @@ for dialect in "${dialects[@]}" ; do then echo "testing ${dialect}..." + race="" if [ "$GORM_VERBOSE" = "" ] then - DEBUG=false GORM_DIALECT=${dialect} go test -race -count=1 ./... + race="-race" + fi + + if [ "$GORM_VERBOSE" = "" ] + then + DEBUG=false GORM_DIALECT=${dialect} go test $race -count=1 ./... else - DEBUG=false GORM_DIALECT=${dialect} go test -race -count=1 -v ./... + DEBUG=false GORM_DIALECT=${dialect} go test $race -count=1 -v ./... fi fi done