Skip to content

remove sqlite tag when integration test with mysql/postgres and recreate database when init integration test #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func initIntegrationTest() {
if err != nil {
log.Fatalf("sql.Open: %v", err)
}
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 {
log.Fatalf("db.Exec: %v", err)
}
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When run on drone it's no need. But when run make test-mysql local, it will failed when you run twice because the old data didn't cleanup. This change will drop the old database and load data from *.yml file.

log.Fatalf("db.drop db: %v", err)
}
}
if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
log.Fatalf("db.Exec: %v", err)
}
}
routers.GlobalInit()
}
Expand Down