Skip to content

Commit 79bdda3

Browse files
committed
Move all integrations tests to a standalone sub package (#1635)
Fix vet Remove unused files Move all integrations tests to a standalone sub package Reviewed-on: https://gitea.com/xorm/xorm/pulls/1635
1 parent 2ac051f commit 79bdda3

40 files changed

+503
-478
lines changed

.drone.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ kind: pipeline
33
name: testing
44
steps:
55
- name: test-vet
6-
image: golang:1.11
6+
image: golang:1.11 # The lowest golang requirement
77
environment:
88
GO111MODULE: "on"
99
GOPROXY: "https://goproxy.cn"
1010
commands:
11-
- go vet
11+
- make vet
12+
- make test
1213
when:
1314
event:
1415
- push
@@ -23,10 +24,6 @@ steps:
2324
- make test-sqlite
2425
- TEST_CACHE_ENABLE=true make test-sqlite
2526
- TEST_QUOTE_POLICY=reserved make test-sqlite
26-
- go test ./caches/... ./contexts/... ./convert/... ./core/... ./dialects/... \
27-
./log/... ./migrate/... ./names/... ./schemas/... ./tags/... \
28-
./internal/json/... ./internal/statements/... ./internal/utils/... \
29-
3027
when:
3128
event:
3229
- push

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ test.db.sql
3434
.idea/
3535

3636
*coverage.out
37+
test.db
38+
integrations/*.sql

Makefile

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ TAGS ?=
77
SED_INPLACE := sed -i
88

99
GOFILES := $(shell find . -name "*.go" -type f)
10-
11-
PACKAGES ?= $(shell GO111MODULE=on $(GO) list ./...)
10+
INTEGRATION_PACKAGES := xorm.io/xorm/integrations
11+
PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
1212

1313
TEST_COCKROACH_HOST ?= cockroach:26257
1414
TEST_COCKROACH_SCHEMA ?=
@@ -46,12 +46,12 @@ all: build
4646

4747
.PHONY: build
4848
build: go-check $(GO_SOURCES)
49-
$(GO) build
49+
$(GO) build $(PACKAGES)
5050

5151
.PHONY: clean
5252
clean:
5353
$(GO) clean -i ./...
54-
rm -rf *.sql *.log test.db *coverage.out coverage.all
54+
rm -rf *.sql *.log test.db *coverage.out coverage.all integrations/*.sql
5555

5656
.PHONY: coverage
5757
coverage:
@@ -92,7 +92,12 @@ help:
9292
@echo " - lint run code linter revive"
9393
@echo " - misspell check if a word is written wrong"
9494
@echo " - test run default unit test"
95-
@echo " - test-sqlite run unit test for sqlite"
95+
@echo " - test-cockroach run integration tests for cockroach"
96+
@echo " - test-mysql run integration tests for mysql"
97+
@echo " - test-mssql run integration tests for mssql"
98+
@echo " - test-postgres run integration tests for postgres"
99+
@echo " - test-sqlite run integration tests for sqlite"
100+
@echo " - test-tidb run integration tests for tidb"
96101
@echo " - vet examines Go source code and reports suspicious constructs"
97102

98103
.PHONY: lint
@@ -120,95 +125,96 @@ misspell-check:
120125
misspell -error -i unknwon,destory $(GOFILES)
121126

122127
.PHONY: test
123-
test: test-sqlite
128+
test: go-check
129+
$(GO) test $(PACKAGES)
124130

125131
.PNONY: test-cockroach
126132
test-cockroach: go-check
127-
$(GO) test -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
133+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
128134
-conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
129135
-ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
130136

131137
.PHONY: test-cockroach\#%
132138
test-cockroach\#%: go-check
133-
$(GO) test -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
139+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
134140
-conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
135141
-ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
136142

137143
.PNONY: test-mssql
138144
test-mssql: go-check
139-
$(GO) test -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
145+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
140146
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
141147
-coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
142148

143149
.PNONY: test-mssql\#%
144150
test-mssql\#%: go-check
145-
$(GO) test -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
151+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
146152
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
147153
-coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
148154

149155
.PNONY: test-mymysql
150156
test-mymysql: go-check
151-
$(GO) test -v -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
157+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
152158
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
153159
-coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
154160

155161
.PNONY: test-mymysql\#%
156162
test-mymysql\#%: go-check
157-
$(GO) test -v -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
163+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
158164
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
159165
-coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
160166

161167
.PNONY: test-mysql
162168
test-mysql: go-check
163-
$(GO) test -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
169+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
164170
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
165171
-coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
166172

167173
.PHONY: test-mysql\#%
168174
test-mysql\#%: go-check
169-
$(GO) test -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
175+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
170176
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
171177
-coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
172178

173179
.PNONY: test-postgres
174180
test-postgres: go-check
175-
$(GO) test -v -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
181+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
176182
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
177183
-quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
178184

179185
.PHONY: test-postgres\#%
180186
test-postgres\#%: go-check
181-
$(GO) test -v -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
187+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
182188
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
183189
-quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
184190

185191
.PHONY: test-sqlite
186192
test-sqlite: go-check
187-
$(GO) test -v -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
193+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
188194
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
189195

190196
.PHONY: test-sqlite-schema
191197
test-sqlite-schema: go-check
192-
$(GO) test -v -race -schema=xorm -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
198+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -schema=xorm -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
193199
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
194200

195201
.PHONY: test-sqlite\#%
196202
test-sqlite\#%: go-check
197-
$(GO) test -v -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
203+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
198204
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
199205

200206
.PNONY: test-tidb
201207
test-tidb: go-check
202-
$(GO) test -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
208+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
203209
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
204210
-quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
205211

206212
.PHONY: test-tidb\#%
207213
test-tidb\#%: go-check
208-
$(GO) test -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
214+
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
209215
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
210216
-quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
211217

212218
.PHONY: vet
213219
vet:
214-
$(GO) vet $(PACKAGES)
220+
$(GO) vet $(shell $(GO) list ./...)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Drivers for Go's sql package which currently support database/sql includes:
6767

6868
* Create Engine
6969

70+
Firstly, we should new an engine for a database.
71+
7072
```Go
7173
engine, err := xorm.NewEngine(driverName, dataSourceName)
7274
```

convert.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -284,56 +284,6 @@ func asKind(vv reflect.Value, tp reflect.Type) (interface{}, error) {
284284
return nil, fmt.Errorf("unsupported primary key type: %v, %v", tp, vv)
285285
}
286286

287-
func convertFloat(v interface{}) (float64, error) {
288-
switch v.(type) {
289-
case float32:
290-
return float64(v.(float32)), nil
291-
case float64:
292-
return v.(float64), nil
293-
case string:
294-
i, err := strconv.ParseFloat(v.(string), 64)
295-
if err != nil {
296-
return 0, err
297-
}
298-
return i, nil
299-
case []byte:
300-
i, err := strconv.ParseFloat(string(v.([]byte)), 64)
301-
if err != nil {
302-
return 0, err
303-
}
304-
return i, nil
305-
}
306-
return 0, fmt.Errorf("unsupported type: %v", v)
307-
}
308-
309-
func convertInt(v interface{}) (int64, error) {
310-
switch v.(type) {
311-
case int:
312-
return int64(v.(int)), nil
313-
case int8:
314-
return int64(v.(int8)), nil
315-
case int16:
316-
return int64(v.(int16)), nil
317-
case int32:
318-
return int64(v.(int32)), nil
319-
case int64:
320-
return v.(int64), nil
321-
case []byte:
322-
i, err := strconv.ParseInt(string(v.([]byte)), 10, 64)
323-
if err != nil {
324-
return 0, err
325-
}
326-
return i, nil
327-
case string:
328-
i, err := strconv.ParseInt(v.(string), 10, 64)
329-
if err != nil {
330-
return 0, err
331-
}
332-
return i, nil
333-
}
334-
return 0, fmt.Errorf("unsupported type: %v", v)
335-
}
336-
337287
func asBool(bs []byte) (bool, error) {
338288
if len(bs) == 0 {
339289
return false, nil

dialects/mssql.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ var (
205205
"PROC": true,
206206
}
207207

208-
mssqlQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
208+
mssqlQuoter = schemas.Quoter{
209+
Prefix: '[',
210+
Suffix: ']',
211+
IsReserved: schemas.AlwaysReserve,
212+
}
209213
)
210214

211215
type mssql struct {

dialects/mysql.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ var (
162162
"ZEROFILL": true,
163163
}
164164

165-
mysqlQuoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
165+
mysqlQuoter = schemas.Quoter{
166+
Prefix: '`',
167+
Suffix: '`',
168+
IsReserved: schemas.AlwaysReserve,
169+
}
166170
)
167171

168172
type mysql struct {

dialects/oracle.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ var (
499499
"ZONE": true,
500500
}
501501

502-
oracleQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
502+
oracleQuoter = schemas.Quoter{
503+
Prefix: '[',
504+
Suffix: ']',
505+
IsReserved: schemas.AlwaysReserve,
506+
}
503507
)
504508

505509
type oracle struct {

dialects/postgres.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,11 @@ var (
767767
"ZONE": true,
768768
}
769769

770-
postgresQuoter = schemas.Quoter{'"', '"', schemas.AlwaysReserve}
770+
postgresQuoter = schemas.Quoter{
771+
Prefix: '"',
772+
Suffix: '"',
773+
IsReserved: schemas.AlwaysReserve,
774+
}
771775
)
772776

773777
var (

dialects/sqlite3.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ var (
144144
"WITHOUT": true,
145145
}
146146

147-
sqlite3Quoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
147+
sqlite3Quoter = schemas.Quoter{
148+
Prefix: '`',
149+
Suffix: '`',
150+
IsReserved: schemas.AlwaysReserve,
151+
}
148152
)
149153

150154
type sqlite3 struct {

0 commit comments

Comments
 (0)