Skip to content

Commit 6db7dbd

Browse files
kolaentelunny
authored andcommitted
Added test environment for mssql (#4282)
* Added test environment for m$sql * Added template for test environment for m$sql * Fix password * Fix password (again) * Fix password (again again) * Fix db * Ci trigger (Looking at you drone....) * Ci trigger (Looking at you drone....) * Ci trigger (Looking at you drone....) * Ci trigger (Looking at you drone....) * Create master database for mssql integration tests Signed-off-by: Jonas Franz <[email protected]> * Create database only if master do not exist Signed-off-by: Jonas Franz <[email protected]> * Fix mssql integration tests by using custom database "gitea" Signed-off-by: Jonas Franz <[email protected]> * Moved defer * bump xorm * updated xorm * Fixed build
1 parent b1f3685 commit 6db7dbd

27 files changed

+383
-66
lines changed

.drone.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ pipeline:
176176
when:
177177
event: [ push, tag, pull_request ]
178178

179+
test-mssql:
180+
image: golang:1.10
181+
pull: true
182+
group: test
183+
environment:
184+
TAGS: bindata
185+
TEST_LDAP: "1"
186+
commands:
187+
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
188+
- apt-get install -y git-lfs
189+
- make test-mssql
190+
when:
191+
event: [ push, tag, pull_request ]
192+
179193
generate-coverage:
180194
image: golang:1.11
181195
pull: true
@@ -347,6 +361,15 @@ services:
347361
when:
348362
event: [ push, tag, pull_request ]
349363

364+
mssql:
365+
image: microsoft/mssql-server-linux:latest
366+
environment:
367+
- ACCEPT_EULA=Y
368+
- SA_PASSWORD=MwantsaSecurePassword1
369+
- MSSQL_PID=Standard
370+
when:
371+
event: [ push, tag, pull_request ]
372+
350373
ldap:
351374
image: gitea/test-openldap:latest
352375
when:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ coverage.all
5353
/integrations/gitea-integration-mysql
5454
/integrations/gitea-integration-pgsql
5555
/integrations/gitea-integration-sqlite
56+
/integrations/gitea-integration-mssql
5657
/integrations/indexers-mysql
5758
/integrations/indexers-pgsql
5859
/integrations/indexers-sqlite
60+
/integrations/indexers-mssql
5961
/integrations/mysql.ini
6062
/integrations/pgsql.ini
63+
/integrations/mssql.ini
6164
/node_modules
6265

6366

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ ignored = ["google.golang.org/appengine*"]
3838

3939
[[override]]
4040
name = "github.com/go-xorm/xorm"
41-
#version = "0.6.5"
42-
revision = "ad69f7d8f0861a29438154bb0a20b60501298480"
41+
revision = "401f4ee8ff8cbc40a4754cb12192fbe4f02f3979"
4342

4443
[[override]]
4544
name = "github.com/go-sql-driver/mysql"

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ TEST_PGSQL_HOST ?= pgsql:5432
5454
TEST_PGSQL_DBNAME ?= testgitea
5555
TEST_PGSQL_USERNAME ?= postgres
5656
TEST_PGSQL_PASSWORD ?= postgres
57+
TEST_MSSQL_HOST ?= mssql:1433
58+
TEST_MSSQL_DBNAME ?= gitea
59+
TEST_MSSQL_USERNAME ?= sa
60+
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
5761

5862
ifeq ($(OS), Windows_NT)
5963
EXECUTABLE := gitea.exe
@@ -74,9 +78,9 @@ clean:
7478
$(GO) clean -i ./...
7579
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
7680
integrations*.test \
77-
integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ \
78-
integrations/indexers-mysql/ integrations/indexers-pgsql integrations/indexers-sqlite \
79-
integrations/mysql.ini integrations/pgsql.ini
81+
integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ integrations/gitea-integration-mssql/ \
82+
integrations/indexers-mysql/ integrations/indexers-pgsql integrations/indexers-sqlite integrations/indexers-mssql \
83+
integrations/mysql.ini integrations/pgsql.ini integrations/mssql.ini
8084

8185
.PHONY: fmt
8286
fmt:
@@ -204,6 +208,11 @@ generate-ini:
204208
-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
205209
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
206210
integrations/pgsql.ini.tmpl > integrations/pgsql.ini
211+
sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
212+
-e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
213+
-e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
214+
-e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
215+
integrations/mssql.ini.tmpl > integrations/mssql.ini
207216

208217
.PHONY: test-mysql
209218
test-mysql: integrations.test generate-ini
@@ -213,6 +222,10 @@ test-mysql: integrations.test generate-ini
213222
test-pgsql: integrations.test generate-ini
214223
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
215224

225+
.PHONY: test-mssql
226+
test-mssql: integrations.test generate-ini
227+
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test
228+
216229
.PHONY: bench-sqlite
217230
bench-sqlite: integrations.sqlite.test
218231
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .

integrations/integration_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func TestMain(m *testing.M) {
4747
helper = &testfixtures.PostgreSQL{}
4848
} else if setting.UseSQLite3 {
4949
helper = &testfixtures.SQLite{}
50+
} else if setting.UseMSSQL {
51+
helper = &testfixtures.SQLServer{}
5052
} else {
5153
fmt.Println("Unsupported RDBMS for integration tests")
5254
os.Exit(1)
@@ -130,6 +132,17 @@ func initIntegrationTest() {
130132
if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
131133
log.Fatalf("db.Exec: %v", err)
132134
}
135+
case setting.UseMSSQL:
136+
host, port := models.ParseMSSQLHostPort(models.DbCfg.Host)
137+
db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
138+
host, port, "master", models.DbCfg.User, models.DbCfg.Passwd))
139+
if err != nil {
140+
log.Fatalf("sql.Open: %v", err)
141+
}
142+
if _, err := db.Exec("If(db_id(N'gitea') IS NULL) BEGIN CREATE DATABASE gitea; END;"); err != nil {
143+
log.Fatalf("db.Exec: %v", err)
144+
}
145+
defer db.Close()
133146
}
134147
routers.GlobalInit()
135148
}

integrations/mssql.ini.tmpl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
APP_NAME = Gitea: Git with a cup of tea
2+
RUN_MODE = prod
3+
4+
[database]
5+
DB_TYPE = mssql
6+
HOST = {{TEST_MSSQL_HOST}}
7+
NAME = {{TEST_MSSQL_DBNAME}}
8+
USER = {{TEST_MSSQL_USERNAME}}
9+
PASSWD = {{TEST_MSSQL_PASSWORD}}
10+
SSL_MODE = disable
11+
12+
[indexer]
13+
ISSUE_INDEXER_PATH = integrations/indexers-mssql/issues.bleve
14+
REPO_INDEXER_ENABLED = true
15+
REPO_INDEXER_PATH = integrations/indexers-mssql/repos.bleve
16+
17+
[repository]
18+
ROOT = integrations/gitea-integration-mssql/gitea-repositories
19+
20+
[repository.local]
21+
LOCAL_COPY_PATH = tmp/local-repo-mssql
22+
LOCAL_WIKI_PATH = tmp/local-wiki-mssql
23+
24+
[server]
25+
SSH_DOMAIN = localhost
26+
HTTP_PORT = 3003
27+
ROOT_URL = http://localhost:3003/
28+
DISABLE_SSH = false
29+
SSH_LISTEN_HOST = localhost
30+
SSH_PORT = 2201
31+
START_SSH_SERVER = true
32+
LFS_START_SERVER = true
33+
LFS_CONTENT_PATH = data/lfs-mssql
34+
OFFLINE_MODE = false
35+
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
36+
APP_DATA_PATH = integrations/gitea-integration-mssql/data
37+
38+
[mailer]
39+
ENABLED = false
40+
41+
[service]
42+
REGISTER_EMAIL_CONFIRM = false
43+
ENABLE_NOTIFY_MAIL = false
44+
DISABLE_REGISTRATION = false
45+
ENABLE_CAPTCHA = false
46+
REQUIRE_SIGNIN_VIEW = false
47+
DEFAULT_KEEP_EMAIL_PRIVATE = false
48+
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
49+
NO_REPLY_ADDRESS = noreply.example.org
50+
51+
[picture]
52+
DISABLE_GRAVATAR = false
53+
ENABLE_FEDERATED_AVATAR = false
54+
55+
[session]
56+
PROVIDER = file
57+
PROVIDER_CONFIG = data/sessions-mssql
58+
59+
[log]
60+
MODE = console,file
61+
ROOT_PATH = mssql-log
62+
63+
[log.console]
64+
LEVEL = Warn
65+
66+
[log.file]
67+
LEVEL = Debug
68+
69+
[security]
70+
INSTALL_LOCK = true
71+
SECRET_KEY = 9pCviYTWSb
72+
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ

models/models.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Engine interface {
3636
Count(...interface{}) (int64, error)
3737
Decr(column string, arg ...interface{}) *xorm.Session
3838
Delete(interface{}) (int64, error)
39-
Exec(string, ...interface{}) (sql.Result, error)
39+
Exec(...interface{}) (sql.Result, error)
4040
Find(interface{}, ...interface{}) error
4141
Get(interface{}) (bool, error)
4242
ID(interface{}) *xorm.Session
@@ -200,7 +200,8 @@ func getPostgreSQLConnectionString(DBHost, DBUser, DBPasswd, DBName, DBParam, DB
200200
return
201201
}
202202

203-
func parseMSSQLHostPort(info string) (string, string) {
203+
// ParseMSSQLHostPort splits the host into host and port
204+
func ParseMSSQLHostPort(info string) (string, string) {
204205
host, port := "127.0.0.1", "1433"
205206
if strings.Contains(info, ":") {
206207
host = strings.Split(info, ":")[0]
@@ -235,7 +236,7 @@ func getEngine() (*xorm.Engine, error) {
235236
case "postgres":
236237
connStr = getPostgreSQLConnectionString(DbCfg.Host, DbCfg.User, DbCfg.Passwd, DbCfg.Name, Param, DbCfg.SSLMode)
237238
case "mssql":
238-
host, port := parseMSSQLHostPort(DbCfg.Host)
239+
host, port := ParseMSSQLHostPort(DbCfg.Host)
239240
connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, DbCfg.Name, DbCfg.User, DbCfg.Passwd)
240241
case "sqlite3":
241242
if !EnableSQLite3 {

vendor/github.com/go-xorm/xorm/context_cache.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-xorm/xorm/dialect_mssql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-xorm/xorm/dialect_mysql.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-xorm/xorm/dialect_sqlite3.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-xorm/xorm/engine.go

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-xorm/xorm/engine_group.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)