aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/integration_test.go
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/integration_test.go
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/integration_test.go')
-rw-r--r--integrations/integration_test.go52
1 files changed, 45 insertions, 7 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"))