From 65503387b1323f37fa7c91e6cf6e0616a5f76e43 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 8 May 2017 14:05:28 +0800 Subject: [PATCH 1/2] remove sqlite tag when integration test with mysql/postgres and recreate database when init integration test --- Makefile | 5 +++-- integrations/integration_test.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d078b87842320..f2477f7c4cc0f 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,8 @@ test-vendor: govendor status || exit 1 .PHONY: test-sqlite -test-sqlite: integrations.test +test-sqlite: + go test -c code.gitea.io/gitea/integrations -tags 'sqlite' GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.test .PHONY: test-mysql @@ -108,7 +109,7 @@ test-pgsql: integrations.test GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test integrations.test: $(SOURCES) - go test -c code.gitea.io/gitea/integrations -tags 'sqlite' + go test -c code.gitea.io/gitea/integrations .PHONY: check check: test diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 4a809403bda24..3bcf65feac562 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -79,6 +79,9 @@ func initIntegrationTest() { if err != nil { log.Fatalf("sql.Open: %v", err) } + if _, err = db.Exec("DROP DATABASE testgitea"); err != nil { + log.Fatalf("db.drop db: %v", err) + } if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS testgitea"); err != nil { log.Fatalf("db.Exec: %v", err) } @@ -96,11 +99,14 @@ func initIntegrationTest() { } defer rows.Close() - if !rows.Next() { - if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil { - log.Fatalf("db.Exec: %v", err) + if rows.Next() { + if _, err = db.Exec("DROP DATABASE testgitea"); err != nil { + log.Fatalf("db.drop db: %v", err) } } + if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil { + log.Fatalf("db.Exec: %v", err) + } } routers.GlobalInit() } From 7a2511e797ebe68b7ba58e8d9df2baddc993c7c9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 8 May 2017 14:28:46 +0800 Subject: [PATCH 2/2] fix test-mysql --- integrations/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 3bcf65feac562..1bac2c196420f 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -79,7 +79,7 @@ func initIntegrationTest() { if err != nil { log.Fatalf("sql.Open: %v", err) } - if _, err = db.Exec("DROP DATABASE testgitea"); err != nil { + if _, err = db.Exec("DROP DATABASE IF EXISTS testgitea"); err != nil { log.Fatalf("db.drop db: %v", err) } if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS testgitea"); err != nil {