Skip to content

Commit 377cd1a

Browse files
lafrikslunny
authored andcommitted
Allow changing integration test database connection using env variables (#2484)
1 parent 005900b commit 377cd1a

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ _testmain.go
5252
/integrations/gitea-integration-mysql
5353
/integrations/gitea-integration-pgsql
5454
/integrations/gitea-integration-sqlite
55+
/integrations/mysql.ini
56+
/integrations/pgsql.ini

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ TAGS ?=
3232

3333
TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
3434

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+
3544
ifeq ($(OS), Windows_NT)
3645
EXECUTABLE := gitea.exe
3746
else
@@ -54,7 +63,7 @@ all: build
5463
.PHONY: clean
5564
clean:
5665
$(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
5867

5968
required-gofmt-version:
6069
@$(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
161170

162171
.PHONY: test-mysql
163172
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
164178
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
165179

166180
.PHONY: test-pgsql
167181
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
168187
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
169188

170-
171189
.PHONY: bench-sqlite
172190
bench-sqlite: integrations.sqlite.test
173191
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.bench .

integrations/mysql.ini renamed to integrations/mysql.ini.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ RUN_MODE = prod
33

44
[database]
55
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}}
1010
SSL_MODE = disable
1111
PATH = data/gitea.db
1212

integrations/pgsql.ini renamed to integrations/pgsql.ini.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ RUN_MODE = prod
33

44
[database]
55
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}}
1010
SSL_MODE = disable
1111
PATH = data/gitea.db
1212

0 commit comments

Comments
 (0)