Browse Source

MySQL, Postgres integration tests in drone (#1638)

* MySQL, Postgres integration tests in drone

* Fix .drone.yml

* sign drone

* resign drone
Ethan Koenig 2 years ago
parent
commit
66c803fae2

+ 2 - 2
.drone.yml

@@ -44,7 +44,7 @@ pipeline:
44 44
       TAGS: bindata
45 45
       GOPATH: /srv/app
46 46
     commands:
47
-      - echo make test-mysql # Not ready yet
47
+      - make test-mysql
48 48
     when:
49 49
       event: [ push, tag, pull_request ]
50 50
 
@@ -55,7 +55,7 @@ pipeline:
55 55
       TAGS: bindata
56 56
       GOPATH: /srv/app
57 57
     commands:
58
-      - echo make test-pqsql # Not ready yet
58
+      - make test-pgsql
59 59
     when:
60 60
       event: [ push, tag, pull_request ]
61 61
 

File diff suppressed because it is too large
+ 1 - 1
.drone.yml.sig


+ 0 - 1
Makefile

@@ -90,7 +90,6 @@ test-sqlite: integrations.test
90 90
 
91 91
 .PHONY: test-mysql
92 92
 test-mysql: integrations.test
93
-	echo "CREATE DATABASE IF NOT EXISTS testgitea" | mysql -u root
94 93
 	GITEA_CONF=integrations/mysql.ini ./integrations.test
95 94
 
96 95
 .PHONY: test-pgsql

+ 45 - 7
integrations/integration_test.go

@@ -6,8 +6,10 @@ package integrations
6 6
 
7 7
 import (
8 8
 	"bytes"
9
+	"database/sql"
9 10
 	"fmt"
10 11
 	"io"
12
+	"log"
11 13
 	"net/http"
12 14
 	"os"
13 15
 	"testing"
@@ -26,13 +28,7 @@ import (
26 28
 var mac *macaron.Macaron
27 29
 
28 30
 func TestMain(m *testing.M) {
29
-	appIniPath := os.Getenv("GITEA_CONF")
30
-	if appIniPath == "" {
31
-		fmt.Println("Environment variable $GITEA_CONF not set")
32
-		os.Exit(1)
33
-	}
34
-	setting.CustomConf = appIniPath
35
-	routers.GlobalInit()
31
+	initIntegrationTest()
36 32
 	mac = routes.NewMacaron()
37 33
 	routes.RegisterRoutes(mac)
38 34
 
@@ -59,6 +55,48 @@ func TestMain(m *testing.M) {
59 55
 	os.Exit(m.Run())
60 56
 }
61 57
 
58
+func initIntegrationTest() {
59
+	if setting.CustomConf = os.Getenv("GITEA_CONF"); setting.CustomConf == "" {
60
+		fmt.Println("Environment variable $GITEA_CONF not set")
61
+		os.Exit(1)
62
+	}
63
+
64
+	setting.NewContext()
65
+	models.LoadConfigs()
66
+
67
+	switch {
68
+	case setting.UseMySQL:
69
+		db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
70
+			models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host))
71
+		defer db.Close()
72
+		if err != nil {
73
+			log.Fatalf("sql.Open: %v", err)
74
+		}
75
+		if _, err = db.Exec("CREATE DATABASE IF NOT EXISTS testgitea"); err != nil {
76
+			log.Fatalf("db.Exec: %v", err)
77
+		}
78
+	case setting.UsePostgreSQL:
79
+		db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
80
+			models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host, models.DbCfg.SSLMode))
81
+		defer db.Close()
82
+		if err != nil {
83
+			log.Fatalf("sql.Open: %v", err)
84
+		}
85
+		rows, err := db.Query(fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s'",
86
+			models.DbCfg.Name))
87
+		if err != nil {
88
+			log.Fatalf("db.Query: %v", err)
89
+		}
90
+		if rows.Next() {
91
+			break // database already exists
92
+		}
93
+		if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
94
+			log.Fatalf("db.Exec: %v", err)
95
+		}
96
+	}
97
+	routers.GlobalInit()
98
+}
99
+
62 100
 func prepareTestEnv(t *testing.T) {
63 101
 	assert.NoError(t, models.LoadFixtures())
64 102
 	assert.NoError(t, os.RemoveAll("integrations/gitea-integration"))

+ 3 - 3
integrations/mysql.ini

@@ -42,14 +42,14 @@ ENABLE_FEDERATED_AVATAR = false
42 42
 PROVIDER = file
43 43
 
44 44
 [log]
45
-MODE = console,file
45
+MODE      = console,file
46
+ROOT_PATH = mysql-log
46 47
 
47 48
 [log.console]
48 49
 LEVEL = Warn
49 50
 
50 51
 [log.file]
51
-LEVEL     = Info
52
-ROOT_PATH = log
52
+LEVEL = Info
53 53
 
54 54
 [security]
55 55
 INSTALL_LOCK = true

+ 1 - 1
integrations/pgsql.ini

@@ -43,13 +43,13 @@ PROVIDER = file
43 43
 
44 44
 [log]
45 45
 MODE = console,file
46
+ROOT_PATH = pgsql-log
46 47
 
47 48
 [log.console]
48 49
 LEVEL = Warn
49 50
 
50 51
 [log.file]
51 52
 LEVEL     = Info
52
-ROOT_PATH = log
53 53
 
54 54
 [security]
55 55
 INSTALL_LOCK = true

+ 3 - 3
models/attachment_test.go

@@ -13,7 +13,7 @@ import (
13 13
 func TestIncreaseDownloadCount(t *testing.T) {
14 14
 	assert.NoError(t, PrepareTestDatabase())
15 15
 
16
-	attachment, err := GetAttachmentByUUID("1234567890")
16
+	attachment, err := GetAttachmentByUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
17 17
 	assert.NoError(t, err)
18 18
 	assert.Equal(t, int64(0), attachment.DownloadCount)
19 19
 
@@ -21,7 +21,7 @@ func TestIncreaseDownloadCount(t *testing.T) {
21 21
 	err = attachment.IncreaseDownloadCount()
22 22
 	assert.NoError(t, err)
23 23
 
24
-	attachment, err = GetAttachmentByUUID("1234567890")
24
+	attachment, err = GetAttachmentByUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
25 25
 	assert.NoError(t, err)
26 26
 	assert.Equal(t, int64(1), attachment.DownloadCount)
27 27
 }
@@ -53,7 +53,7 @@ func TestDeleteAttachments(t *testing.T) {
53 53
 	err = DeleteAttachment(&Attachment{ID: 8}, false)
54 54
 	assert.NoError(t, err)
55 55
 
56
-	attachment, err := GetAttachmentByUUID("test-12345")
56
+	attachment, err := GetAttachmentByUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18")
57 57
 	assert.Error(t, err)
58 58
 	assert.True(t, IsErrAttachmentNotExist(err))
59 59
 	assert.Nil(t, attachment)

+ 8 - 8
models/fixtures/attachment.yml

@@ -1,6 +1,6 @@
1 1
 -
2 2
   id: 1
3
-  uuid: 1234567890
3
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
4 4
   issue_id: 1
5 5
   comment_id: 0
6 6
   name: attach1
@@ -9,7 +9,7 @@
9 9
 
10 10
 -
11 11
   id: 2
12
-  uuid: 1122334455
12
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12
13 13
   issue_id: 1
14 14
   comment_id: 0
15 15
   name: attach2
@@ -18,7 +18,7 @@
18 18
 
19 19
 -
20 20
   id: 3
21
-  uuid: comment-id-1
21
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a13
22 22
   issue_id: 2
23 23
   comment_id: 1
24 24
   name: attach1
@@ -27,7 +27,7 @@
27 27
 
28 28
 -
29 29
   id: 4
30
-  uuid: comment-id-2
30
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14
31 31
   issue_id: 3
32 32
   comment_id: 1
33 33
   name: attach2
@@ -36,7 +36,7 @@
36 36
 
37 37
 -
38 38
   id: 5
39
-  uuid: comment-id-3
39
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a15
40 40
   issue_id: 4
41 41
   comment_id: 0
42 42
   name: attach1
@@ -45,7 +45,7 @@
45 45
 
46 46
 -
47 47
   id: 6
48
-  uuid: comment-id-4
48
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a16
49 49
   issue_id: 5
50 50
   comment_id: 2
51 51
   name: attach1
@@ -54,7 +54,7 @@
54 54
 
55 55
 -
56 56
   id: 7
57
-  uuid: comment-id-5
57
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17
58 58
   issue_id: 5
59 59
   comment_id: 2
60 60
   name: attach1
@@ -63,7 +63,7 @@
63 63
 
64 64
 -
65 65
   id: 8
66
-  uuid: test-12345
66
+  uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18
67 67
   issue_id: 6
68 68
   comment_id: 0
69 69
   name: attach1

+ 1 - 1
models/fixtures/pull_request.yml

@@ -16,7 +16,7 @@
16 16
 -
17 17
   id: 2
18 18
   type: 0 # gitea pull request
19
-  status: 1 # checking
19
+  status: 2 # mergable
20 20
   issue_id: 3
21 21
   index: 3
22 22
   head_repo_id: 1