Browse Source

Allow changing integration test database connection using env variables (#2484)

Lauris BH 2 years ago
parent
commit
377cd1ae38
4 changed files with 30 additions and 10 deletions
  1. 2 0
      .gitignore
  2. 20 2
      Makefile
  3. 4 4
      integrations/mysql.ini
  4. 4 4
      integrations/pgsql.ini

+ 2 - 0
.gitignore

@@ -52,3 +52,5 @@ _testmain.go
52 52
 /integrations/gitea-integration-mysql
53 53
 /integrations/gitea-integration-pgsql
54 54
 /integrations/gitea-integration-sqlite
55
+/integrations/mysql.ini
56
+/integrations/pgsql.ini

+ 20 - 2
Makefile

@@ -32,6 +32,15 @@ TAGS ?=
32 32
 
33 33
 TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
34 34
 
35
+TEST_MYSQL_HOST ?= mysql:3306
36
+TEST_MYSQL_DBNAME ?= testgitea
37
+TEST_MYSQL_USERNAME ?= root
38
+TEST_MYSQL_PASSWORD ?=
39
+TEST_PGSQL_HOST ?= pgsql:5432
40
+TEST_PGSQL_DBNAME ?= testgitea
41
+TEST_PGSQL_USERNAME ?= postgres
42
+TEST_PGSQL_PASSWORD ?= postgres
43
+
35 44
 ifeq ($(OS), Windows_NT)
36 45
 	EXECUTABLE := gitea.exe
37 46
 else
@@ -54,7 +63,7 @@ all: build
54 63
 .PHONY: clean
55 64
 clean:
56 65
 	$(GO) clean -i ./...
57
-	rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) integrations*.test integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/
66
+	rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) integrations*.test integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ integrations/mysql.ini integrations/pgsql.ini
58 67
 
59 68
 required-gofmt-version:
60 69
 	@$(GO) version  | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
@@ -161,13 +170,22 @@ test-sqlite: integrations.sqlite.test
161 170
 
162 171
 .PHONY: test-mysql
163 172
 test-mysql: integrations.mysql.test
173
+	sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
174
+	    -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
175
+	    -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
176
+	    -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
177
+		  integrations/mysql.ini.tmpl > integrations/mysql.ini
164 178
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
165 179
 
166 180
 .PHONY: test-pgsql
167 181
 test-pgsql: integrations.pgsql.test
182
+	sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
183
+	    -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
184
+	    -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
185
+	    -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
186
+		  integrations/pgsql.ini.tmpl > integrations/pgsql.ini
168 187
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
169 188
 
170
-
171 189
 .PHONY: bench-sqlite
172 190
 bench-sqlite: integrations.sqlite.test
173 191
 	GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.bench .

+ 4 - 4
integrations/mysql.ini

@@ -3,10 +3,10 @@ RUN_MODE = prod
3 3
 
4 4
 [database]
5 5
 DB_TYPE  = mysql
6
-HOST     = mysql:3306
7
-NAME     = testgitea
8
-USER     = root
9
-PASSWD   =
6
+HOST     = {{TEST_MYSQL_HOST}}
7
+NAME     = {{TEST_MYSQL_DBNAME}}
8
+USER     = {{TEST_MYSQL_USERNAME}}
9
+PASSWD   = {{TEST_MYSQL_PASSWORD}}
10 10
 SSL_MODE = disable
11 11
 PATH     = data/gitea.db
12 12
 

+ 4 - 4
integrations/pgsql.ini

@@ -3,10 +3,10 @@ RUN_MODE = prod
3 3
 
4 4
 [database]
5 5
 DB_TYPE  = postgres
6
-HOST     = pgsql:5432
7
-NAME     = testgitea
8
-USER     = postgres
9
-PASSWD   = postgres
6
+HOST     = {{TEST_PGSQL_HOST}}
7
+NAME     = {{TEST_PGSQL_DBNAME}}
8
+USER     = {{TEST_PGSQL_USERNAME}}
9
+PASSWD   = {{TEST_PGSQL_PASSWORD}}
10 10
 SSL_MODE = disable
11 11
 PATH     = data/gitea.db
12 12