diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-09-25 20:13:18 +0800 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-09-25 14:13:18 +0200 |
commit | a8c024043ca7a762c29e3ed97b791df541b219d9 (patch) | |
tree | cae62a5a902695acf9cd82b5981c381850872c20 /integrations | |
parent | c05b89a5aaea7c3a7db9b602693556cde725a30f (diff) | |
download | gitea-a8c024043ca7a762c29e3ed97b791df541b219d9.tar.gz gitea-a8c024043ca7a762c29e3ed97b791df541b219d9.zip |
Improve integration tests (#8276)
* improve integration tests
* fix Makefile
* improve makefile and integration docs
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/README.md | 34 | ||||
-rw-r--r-- | integrations/README_ZH.md | 35 | ||||
-rw-r--r-- | integrations/integration_test.go | 6 | ||||
-rw-r--r-- | integrations/mssql.ini.tmpl | 2 | ||||
-rw-r--r-- | integrations/mysql.ini.tmpl | 2 | ||||
-rw-r--r-- | integrations/mysql8.ini.tmpl | 2 | ||||
-rw-r--r-- | integrations/pgsql.ini.tmpl | 2 |
7 files changed, 56 insertions, 27 deletions
diff --git a/integrations/README.md b/integrations/README.md index a88cec6e4f..6ffd76815c 100644 --- a/integrations/README.md +++ b/integrations/README.md @@ -27,31 +27,45 @@ make test-sqlite ## Run mysql integrations tests Setup a mysql database inside docker ``` -docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" --rm --name mysql mysql:5.7 #(just ctrl-c to stop db and clean the container) +docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -p 3306:3306 --rm --name mysql mysql:5.7 #(just ctrl-c to stop db and clean the container) ``` Start tests based on the database container ``` -TEST_MYSQL_HOST="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql):3306" TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql +TEST_MYSQL_HOST=localhost:3306 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql ``` ## Run pgsql integrations tests Setup a pgsql database inside docker ``` -docker run -e "POSTGRES_DB=test" --rm --name pgsql postgres:9.5 #(just ctrl-c to stop db and clean the container) +docker run -e "POSTGRES_DB=test" -p 5432:5432 --rm --name pgsql postgres:9.5 #(just ctrl-c to stop db and clean the container) ``` Start tests based on the database container ``` -TEST_PGSQL_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pgsql) TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql +TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql +``` + +## Run mssql integrations tests +Setup a mssql database inside docker +``` +docker run -e "ACCEPT_EULA=Y" -e "MSSQL_PID=Standard" -e "SA_PASSWORD=MwantsaSecurePassword1" -p 1433:1433 --rm --name mssql microsoft/mssql-server-linux:latest #(just ctrl-c to stop db and clean the container) +``` +Start tests based on the database container +``` +TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql ``` ## Running individual tests -Example command to run GPG test with sqlite backend: +Example command to run GPG test: + +For sqlite: + ``` -go test -c code.gitea.io/gitea/integrations \ - -o integrations.sqlite.test -tags 'sqlite' && - GITEA_ROOT="$GOPATH/src/code.gitea.io/gitea" \ - GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test \ - -test.v -test.run GPG +make test-sqlite#GPG ``` +For other databases(replace MSSQL to MYSQL, MYSQL8, PGSQL): + +``` +TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql#GPG +```
\ No newline at end of file diff --git a/integrations/README_ZH.md b/integrations/README_ZH.md index 62d9cccfcf..fd31764560 100644 --- a/integrations/README_ZH.md +++ b/integrations/README_ZH.md @@ -26,31 +26,46 @@ make test-sqlite ## 如何使用 mysql 数据库进行集成测试 首先在docker容器里部署一个 mysql 数据库 ``` -docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" --rm --name mysql mysql:5.7 #(just ctrl-c to stop db and clean the container) +docker run -e "MYSQL_DATABASE=test" -e "MYSQL_ALLOW_EMPTY_PASSWORD=yes" -p 3306:3306 --rm --name mysql mysql:5.7 #(just ctrl-c to stop db and clean the container) ``` 之后便可以基于这个数据库进行集成测试 ``` -TEST_MYSQL_HOST="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql):3306" TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql +TEST_MYSQL_HOST=localhost:3306 TEST_MYSQL_DBNAME=test TEST_MYSQL_USERNAME=root TEST_MYSQL_PASSWORD='' make test-mysql ``` ## 如何使用 pgsql 数据库进行集成测试 同上,首先在 docker 容器里部署一个 pgsql 数据库 ``` -docker run -e "POSTGRES_DB=test" --rm --name pgsql postgres:9.5 #(just ctrl-c to stop db and clean the container) +docker run -e "POSTGRES_DB=test" -p 5432:5432 --rm --name pgsql postgres:9.5 #(just ctrl-c to stop db and clean the container) ``` 之后便可以基于这个数据库进行集成测试 ``` -TEST_PGSQL_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pgsql) TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql +TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=test TEST_PGSQL_USERNAME=postgres TEST_PGSQL_PASSWORD=postgres make test-pgsql +``` + +## Run mssql integrations tests +同上,首先在 docker 容器里部署一个 mssql 数据库 +``` +docker run -e "ACCEPT_EULA=Y" -e "MSSQL_PID=Standard" -e "SA_PASSWORD=MwantsaSecurePassword1" -p 1433:1433 --rm --name mssql microsoft/mssql-server-linux:latest #(just ctrl-c to stop db and clean the container) +``` +之后便可以基于这个数据库进行集成测试 +``` +TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql ``` ## 如何进行自定义的集成测试 -下面的示例展示了怎样基于 sqlite 数据库进行 GPG 测试: +下面的示例展示了怎样在集成测试中只进行 GPG 测试: + +sqlite 数据库: + +``` +make test-sqlite#GPG +``` + +其它数据库(把 MSSQL 替换为 MYSQL, MYSQL8, PGSQL): + ``` -go test -c code.gitea.io/gitea/integrations \ - -o integrations.sqlite.test -tags 'sqlite' && - GITEA_ROOT="$GOPATH/src/code.gitea.io/gitea" \ - GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test \ - -test.v -test.run GPG +TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-mssql#GPG ``` diff --git a/integrations/integration_test.go b/integrations/integration_test.go index e4d506ee7d..897315f2ae 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -131,7 +131,7 @@ func initIntegrationTest() { if err != nil { log.Fatalf("sql.Open: %v", err) } - if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS testgitea"); err != nil { + if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name)); err != nil { log.Fatalf("db.Exec: %v", err) } case setting.Database.UsePostgreSQL: @@ -150,7 +150,7 @@ func initIntegrationTest() { if rows.Next() { break } - if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil { + if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name)); err != nil { log.Fatalf("db.Exec: %v", err) } case setting.Database.UseMSSQL: @@ -160,7 +160,7 @@ func initIntegrationTest() { if err != nil { log.Fatalf("sql.Open: %v", err) } - if _, err := db.Exec("If(db_id(N'gitea') IS NULL) BEGIN CREATE DATABASE gitea; END;"); err != nil { + if _, err := db.Exec(fmt.Sprintf("If(db_id(N'%s') IS NULL) BEGIN CREATE DATABASE %s; END;", setting.Database.Name, setting.Database.Name)); err != nil { log.Fatalf("db.Exec: %v", err) } defer db.Close() diff --git a/integrations/mssql.ini.tmpl b/integrations/mssql.ini.tmpl index 06d9de6107..d38d038a4e 100644 --- a/integrations/mssql.ini.tmpl +++ b/integrations/mssql.ini.tmpl @@ -62,7 +62,7 @@ PROVIDER_CONFIG = data/sessions-mssql [log] MODE = test,file -ROOT_PATH = sqlite-log +ROOT_PATH = mssql-log REDIRECT_MACARON_LOG = true ROUTER = , MACARON = , diff --git a/integrations/mysql.ini.tmpl b/integrations/mysql.ini.tmpl index 44ca51ff8b..6eed7e1578 100644 --- a/integrations/mysql.ini.tmpl +++ b/integrations/mysql.ini.tmpl @@ -62,7 +62,7 @@ PROVIDER_CONFIG = data/sessions-mysql [log] MODE = test,file -ROOT_PATH = sqlite-log +ROOT_PATH = mysql-log REDIRECT_MACARON_LOG = true ROUTER = , MACARON = , diff --git a/integrations/mysql8.ini.tmpl b/integrations/mysql8.ini.tmpl index 6db3c880ff..1e14bc1356 100644 --- a/integrations/mysql8.ini.tmpl +++ b/integrations/mysql8.ini.tmpl @@ -59,7 +59,7 @@ PROVIDER_CONFIG = data/sessions-mysql8 [log] MODE = test,file -ROOT_PATH = sqlite-log +ROOT_PATH = mysql8-log REDIRECT_MACARON_LOG = true ROUTER = , MACARON = , diff --git a/integrations/pgsql.ini.tmpl b/integrations/pgsql.ini.tmpl index e69198c868..cd5dc44ea8 100644 --- a/integrations/pgsql.ini.tmpl +++ b/integrations/pgsql.ini.tmpl @@ -62,7 +62,7 @@ PROVIDER_CONFIG = data/sessions-pgsql [log] MODE = test,file -ROOT_PATH = sqlite-log +ROOT_PATH = pgsql-log REDIRECT_MACARON_LOG = true ROUTER = , MACARON = , |