summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-04-30 02:30:12 -0400
committerBo-Yi Wu <appleboy.tw@gmail.com>2017-04-30 14:30:12 +0800
commit66c803fae25f966a23d012de91e281e229b62cd4 (patch)
treec021213252648b23eca65b259b666488b7759875 /integrations
parent0308d44a16d7bdcda75c1e946dc06efca48ed624 (diff)
downloadgitea-66c803fae25f966a23d012de91e281e229b62cd4.tar.gz
gitea-66c803fae25f966a23d012de91e281e229b62cd4.zip
MySQL, Postgres integration tests in drone (#1638)
* MySQL, Postgres integration tests in drone * Fix .drone.yml * sign drone * resign drone
Diffstat (limited to 'integrations')
-rw-r--r--integrations/integration_test.go52
-rw-r--r--integrations/mysql.ini6
-rw-r--r--integrations/pgsql.ini2
3 files changed, 49 insertions, 11 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index dc0d41edef..e13c3b512f 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -6,8 +6,10 @@ package integrations
import (
"bytes"
+ "database/sql"
"fmt"
"io"
+ "log"
"net/http"
"os"
"testing"
@@ -26,13 +28,7 @@ import (
var mac *macaron.Macaron
func TestMain(m *testing.M) {
- appIniPath := os.Getenv("GITEA_CONF")
- if appIniPath == "" {
- fmt.Println("Environment variable $GITEA_CONF not set")
- os.Exit(1)
- }
- setting.CustomConf = appIniPath
- routers.GlobalInit()
+ initIntegrationTest()
mac = routes.NewMacaron()
routes.RegisterRoutes(mac)
@@ -59,6 +55,48 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
+func initIntegrationTest() {
+ if setting.CustomConf = os.Getenv("GITEA_CONF"); setting.CustomConf == "" {
+ fmt.Println("Environment variable $GITEA_CONF not set")
+ os.Exit(1)
+ }
+
+ setting.NewContext()
+ models.LoadConfigs()
+
+ switch {
+ case setting.UseMySQL:
+ db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
+ models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host))
+ defer db.Close()
+ if err != nil {
+ log.Fatalf("sql.Open: %v", err)
+ }
+ if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS testgitea"); err != nil {
+ log.Fatalf("db.Exec: %v", err)
+ }
+ case setting.UsePostgreSQL:
+ db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
+ models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host, models.DbCfg.SSLMode))
+ defer db.Close()
+ if err != nil {
+ log.Fatalf("sql.Open: %v", err)
+ }
+ rows, err := db.Query(fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s'",
+ models.DbCfg.Name))
+ if err != nil {
+ log.Fatalf("db.Query: %v", err)
+ }
+ if rows.Next() {
+ break // database already exists
+ }
+ if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
+ log.Fatalf("db.Exec: %v", err)
+ }
+ }
+ routers.GlobalInit()
+}
+
func prepareTestEnv(t *testing.T) {
assert.NoError(t, models.LoadFixtures())
assert.NoError(t, os.RemoveAll("integrations/gitea-integration"))
diff --git a/integrations/mysql.ini b/integrations/mysql.ini
index 9e121ac1e6..b15588c867 100644
--- a/integrations/mysql.ini
+++ b/integrations/mysql.ini
@@ -42,14 +42,14 @@ ENABLE_FEDERATED_AVATAR = false
PROVIDER = file
[log]
-MODE = console,file
+MODE = console,file
+ROOT_PATH = mysql-log
[log.console]
LEVEL = Warn
[log.file]
-LEVEL = Info
-ROOT_PATH = log
+LEVEL = Info
[security]
INSTALL_LOCK = true
diff --git a/integrations/pgsql.ini b/integrations/pgsql.ini
index 42e29e8266..920a5190d4 100644
--- a/integrations/pgsql.ini
+++ b/integrations/pgsql.ini
@@ -43,13 +43,13 @@ PROVIDER = file
[log]
MODE = console,file
+ROOT_PATH = pgsql-log
[log.console]
LEVEL = Warn
[log.file]
LEVEL = Info
-ROOT_PATH = log
[security]
INSTALL_LOCK = true