Move all integrations tests to a standalone sub package #1635
|
@ -3,12 +3,13 @@ kind: pipeline
|
|||
name: testing
|
||||
steps:
|
||||
- name: test-vet
|
||||
image: golang:1.11
|
||||
image: golang:1.11 # The lowest golang requirement
|
||||
environment:
|
||||
GO111MODULE: "on"
|
||||
GOPROXY: "https://goproxy.cn"
|
||||
commands:
|
||||
- go vet
|
||||
- make vet
|
||||
- make test
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
|
@ -23,10 +24,6 @@ steps:
|
|||
- make test-sqlite
|
||||
- TEST_CACHE_ENABLE=true make test-sqlite
|
||||
- TEST_QUOTE_POLICY=reserved make test-sqlite
|
||||
- go test ./caches/... ./contexts/... ./convert/... ./core/... ./dialects/... \
|
||||
./log/... ./migrate/... ./names/... ./schemas/... ./tags/... \
|
||||
./internal/json/... ./internal/statements/... ./internal/utils/... \
|
||||
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -34,3 +34,5 @@ test.db.sql
|
|||
.idea/
|
||||
|
||||
*coverage.out
|
||||
test.db
|
||||
integrations/*.sql
|
||||
|
|
50
Makefile
50
Makefile
|
@ -7,8 +7,8 @@ TAGS ?=
|
|||
SED_INPLACE := sed -i
|
||||
|
||||
GOFILES := $(shell find . -name "*.go" -type f)
|
||||
|
||||
PACKAGES ?= $(shell GO111MODULE=on $(GO) list ./...)
|
||||
INTEGRATION_PACKAGES := xorm.io/xorm/integrations
|
||||
PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
|
||||
|
||||
TEST_COCKROACH_HOST ?= cockroach:26257
|
||||
TEST_COCKROACH_SCHEMA ?=
|
||||
|
@ -46,12 +46,12 @@ all: build
|
|||
|
||||
.PHONY: build
|
||||
build: go-check $(GO_SOURCES)
|
||||
$(GO) build
|
||||
$(GO) build $(PACKAGES)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(GO) clean -i ./...
|
||||
rm -rf *.sql *.log test.db *coverage.out coverage.all
|
||||
rm -rf *.sql *.log test.db *coverage.out coverage.all integrations/*.sql
|
||||
|
||||
.PHONY: coverage
|
||||
coverage:
|
||||
|
@ -92,7 +92,12 @@ help:
|
|||
@echo " - lint run code linter revive"
|
||||
@echo " - misspell check if a word is written wrong"
|
||||
@echo " - test run default unit test"
|
||||
@echo " - test-sqlite run unit test for sqlite"
|
||||
@echo " - test-cockroach run integration tests for cockroach"
|
||||
@echo " - test-mysql run integration tests for mysql"
|
||||
@echo " - test-mssql run integration tests for mssql"
|
||||
@echo " - test-postgres run integration tests for postgres"
|
||||
@echo " - test-sqlite run integration tests for sqlite"
|
||||
@echo " - test-tidb run integration tests for tidb"
|
||||
@echo " - vet examines Go source code and reports suspicious constructs"
|
||||
|
||||
.PHONY: lint
|
||||
|
@ -120,95 +125,96 @@ misspell-check:
|
|||
misspell -error -i unknwon,destory $(GOFILES)
|
||||
|
||||
.PHONY: test
|
||||
test: test-sqlite
|
||||
test: go-check
|
||||
$(GO) test $(PACKAGES)
|
||||
|
||||
.PNONY: test-cockroach
|
||||
test-cockroach: go-check
|
||||
$(GO) test -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
-conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
|
||||
-ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-cockroach\#%
|
||||
test-cockroach\#%: go-check
|
||||
$(GO) test -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_COCKROACH_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
-conn_str="postgres://$(TEST_COCKROACH_USERNAME):$(TEST_COCKROACH_PASSWORD)@$(TEST_COCKROACH_HOST)/$(TEST_COCKROACH_DBNAME)?sslmode=disable&experimental_serial_normalization=sql_sequence" \
|
||||
-ignore_update_limit=true -coverprofile=cockroach.$(TEST_COCKROACH_SCHEMA).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-mssql
|
||||
test-mssql: go-check
|
||||
$(GO) test -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
|
||||
-coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-mssql\#%
|
||||
test-mssql\#%: go-check
|
||||
$(GO) test -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
|
||||
-coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-mymysql
|
||||
test-mymysql: go-check
|
||||
$(GO) test -v -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
|
||||
-coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-mymysql\#%
|
||||
test-mymysql\#%: go-check
|
||||
$(GO) test -v -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
|
||||
-coverprofile=mymysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-mysql
|
||||
test-mysql: go-check
|
||||
$(GO) test -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
|
||||
-coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-mysql\#%
|
||||
test-mysql\#%: go-check
|
||||
$(GO) test -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \
|
||||
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
|
||||
-coverprofile=mysql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-postgres
|
||||
test-postgres: go-check
|
||||
$(GO) test -v -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-postgres\#%
|
||||
test-postgres\#%: go-check
|
||||
$(GO) test -v -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
|
||||
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=postgres.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-sqlite
|
||||
test-sqlite: go-check
|
||||
$(GO) test -v -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-sqlite-schema
|
||||
test-sqlite-schema: go-check
|
||||
$(GO) test -v -race -schema=xorm -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -schema=xorm -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-sqlite\#%
|
||||
test-sqlite\#%: go-check
|
||||
$(GO) test -v -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=sqlite.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PNONY: test-tidb
|
||||
test-tidb: go-check
|
||||
$(GO) test -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
|
||||
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: test-tidb\#%
|
||||
test-tidb\#%: go-check
|
||||
$(GO) test -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
|
||||
$(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
|
||||
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
|
||||
-quote=$(TEST_QUOTE_POLICY) -coverprofile=tidb.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
|
||||
|
||||
.PHONY: vet
|
||||
vet:
|
||||
$(GO) vet $(PACKAGES)
|
||||
$(GO) vet $(shell $(GO) list ./...)
|
|
@ -67,6 +67,8 @@ Drivers for Go's sql package which currently support database/sql includes:
|
|||
|
||||
* Create Engine
|
||||
|
||||
Firstly, we should new an engine for a database.
|
||||
|
||||
```Go
|
||||
engine, err := xorm.NewEngine(driverName, dataSourceName)
|
||||
```
|
||||
|
|
50
convert.go
50
convert.go
|
@ -284,56 +284,6 @@ func asKind(vv reflect.Value, tp reflect.Type) (interface{}, error) {
|
|||
return nil, fmt.Errorf("unsupported primary key type: %v, %v", tp, vv)
|
||||
}
|
||||
|
||||
func convertFloat(v interface{}) (float64, error) {
|
||||
switch v.(type) {
|
||||
case float32:
|
||||
return float64(v.(float32)), nil
|
||||
case float64:
|
||||
return v.(float64), nil
|
||||
case string:
|
||||
i, err := strconv.ParseFloat(v.(string), 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
case []byte:
|
||||
i, err := strconv.ParseFloat(string(v.([]byte)), 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unsupported type: %v", v)
|
||||
}
|
||||
|
||||
func convertInt(v interface{}) (int64, error) {
|
||||
switch v.(type) {
|
||||
case int:
|
||||
return int64(v.(int)), nil
|
||||
case int8:
|
||||
return int64(v.(int8)), nil
|
||||
case int16:
|
||||
return int64(v.(int16)), nil
|
||||
case int32:
|
||||
return int64(v.(int32)), nil
|
||||
case int64:
|
||||
return v.(int64), nil
|
||||
case []byte:
|
||||
i, err := strconv.ParseInt(string(v.([]byte)), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
case string:
|
||||
i, err := strconv.ParseInt(v.(string), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unsupported type: %v", v)
|
||||
}
|
||||
|
||||
func asBool(bs []byte) (bool, error) {
|
||||
if len(bs) == 0 {
|
||||
return false, nil
|
||||
|
|
|
@ -205,7 +205,11 @@ var (
|
|||
"PROC": true,
|
||||
}
|
||||
|
||||
mssqlQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
|
||||
mssqlQuoter = schemas.Quoter{
|
||||
Prefix: '[',
|
||||
Suffix: ']',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
)
|
||||
|
||||
type mssql struct {
|
||||
|
|
|
@ -162,7 +162,11 @@ var (
|
|||
"ZEROFILL": true,
|
||||
}
|
||||
|
||||
mysqlQuoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
|
||||
mysqlQuoter = schemas.Quoter{
|
||||
Prefix: '`',
|
||||
Suffix: '`',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
)
|
||||
|
||||
type mysql struct {
|
||||
|
|
|
@ -499,7 +499,11 @@ var (
|
|||
"ZONE": true,
|
||||
}
|
||||
|
||||
oracleQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
|
||||
oracleQuoter = schemas.Quoter{
|
||||
Prefix: '[',
|
||||
Suffix: ']',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
)
|
||||
|
||||
type oracle struct {
|
||||
|
|
|
@ -767,7 +767,11 @@ var (
|
|||
"ZONE": true,
|
||||
}
|
||||
|
||||
postgresQuoter = schemas.Quoter{'"', '"', schemas.AlwaysReserve}
|
||||
postgresQuoter = schemas.Quoter{
|
||||
Prefix: '"',
|
||||
Suffix: '"',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -144,7 +144,11 @@ var (
|
|||
"WITHOUT": true,
|
||||
}
|
||||
|
||||
sqlite3Quoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
|
||||
sqlite3Quoter = schemas.Quoter{
|
||||
Prefix: '`',
|
||||
Suffix: '`',
|
||||
IsReserved: schemas.AlwaysReserve,
|
||||
}
|
||||
)
|
||||
|
||||
type sqlite3 struct {
|
||||
|
|
2
doc.go
2
doc.go
|
@ -8,7 +8,7 @@ Package xorm is a simple and powerful ORM for Go.
|
|||
|
||||
Installation
|
||||
|
||||
Make sure you have installed Go 1.6+ and then:
|
||||
Make sure you have installed Go 1.11+ and then:
|
||||
|
||||
go get xorm.io/xorm
|
||||
|
||||
|
|
54
engine.go
54
engine.go
|
@ -12,6 +12,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -46,6 +47,59 @@ type Engine struct {
|
|||
logSessionID bool // create session id
|
||||
}
|
||||
|
||||
// NewEngine new a db manager according to the parameter. Currently support four
|
||||
// drivers
|
||||
func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||
dialect, err := dialects.OpenDialect(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db, err := core.Open(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacherMgr := caches.NewManager()
|
||||
mapper := names.NewCacheMapper(new(names.SnakeMapper))
|
||||
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr)
|
||||
|
||||
engine := &Engine{
|
||||
dialect: dialect,
|
||||
TZLocation: time.Local,
|
||||
defaultContext: context.Background(),
|
||||
cacherMgr: cacherMgr,
|
||||
tagParser: tagParser,
|
||||
driverName: driverName,
|
||||
dataSourceName: dataSourceName,
|
||||
db: db,
|
||||
logSessionID: false,
|
||||
}
|
||||
|
||||
if dialect.URI().DBType == schemas.SQLITE {
|
||||
engine.DatabaseTZ = time.UTC
|
||||
} else {
|
||||
engine.DatabaseTZ = time.Local
|
||||
}
|
||||
|
||||
logger := log.NewSimpleLogger(os.Stdout)
|
||||
logger.SetLevel(log.LOG_INFO)
|
||||
engine.SetLogger(log.NewLoggerAdapter(logger))
|
||||
|
||||
runtime.SetFinalizer(engine, func(engine *Engine) {
|
||||
engine.Close()
|
||||
})
|
||||
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
// NewEngineWithParams new a db manager with params. The params will be passed to dialects.
|
||||
func NewEngineWithParams(driverName string, dataSourceName string, params map[string]string) (*Engine, error) {
|
||||
engine, err := NewEngine(driverName, dataSourceName)
|
||||
engine.dialect.SetParams(params)
|
||||
return engine, err
|
||||
}
|
||||
|
||||
// EnableSessionID if enable session id
|
||||
func (engine *Engine) EnableSessionID(enable bool) {
|
||||
engine.logSessionID = enable
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCacheFind(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type MailBox struct {
|
||||
Id int64 `xorm:"pk"`
|
||||
|
@ -89,7 +89,7 @@ func TestCacheFind(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCacheFind2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type MailBox2 struct {
|
||||
Id uint64 `xorm:"pk"`
|
||||
|
@ -140,7 +140,7 @@ func TestCacheFind2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCacheGet(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type MailBox3 struct {
|
||||
Id uint64
|
|
@ -2,26 +2,28 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/log"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEngineGroup(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
master := testEngine.(*Engine)
|
||||
master := testEngine.(*xorm.Engine)
|
||||
if master.Dialect().URI().DBType == schemas.SQLITE {
|
||||
t.Skip()
|
||||
return
|
||||
}
|
||||
|
||||
eg, err := NewEngineGroup(master, []*Engine{master})
|
||||
eg, err := xorm.NewEngineGroup(master, []*xorm.Engine{master})
|
||||
assert.NoError(t, err)
|
||||
|
||||
eg.SetMaxIdleConns(10)
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -11,25 +11,38 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
_ "github.com/ziutek/mymysql/godrv"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
if err := testEngine.Ping(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPingContext(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
ctx, canceled := context.WithTimeout(context.Background(), time.Nanosecond)
|
||||
defer canceled()
|
||||
|
||||
time.Sleep(time.Nanosecond)
|
||||
|
||||
err := testEngine.(*Engine).PingContext(ctx)
|
||||
err := testEngine.(*xorm.Engine).PingContext(ctx)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "context deadline exceeded")
|
||||
}
|
||||
|
||||
func TestAutoTransaction(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestTx struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -39,10 +52,10 @@ func TestAutoTransaction(t *testing.T) {
|
|||
|
||||
assert.NoError(t, testEngine.Sync2(new(TestTx)))
|
||||
|
||||
engine := testEngine.(*Engine)
|
||||
engine := testEngine.(*xorm.Engine)
|
||||
|
||||
// will success
|
||||
engine.Transaction(func(session *Session) (interface{}, error) {
|
||||
engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
_, err := session.Insert(TestTx{Msg: "hi"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -54,7 +67,7 @@ func TestAutoTransaction(t *testing.T) {
|
|||
assert.EqualValues(t, true, has)
|
||||
|
||||
// will rollback
|
||||
_, err = engine.Transaction(func(session *Session) (interface{}, error) {
|
||||
_, err = engine.Transaction(func(session *xorm.Session) (interface{}, error) {
|
||||
_, err := session.Insert(TestTx{Msg: "hello"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -67,8 +80,17 @@ func TestAutoTransaction(t *testing.T) {
|
|||
assert.EqualValues(t, false, has)
|
||||
}
|
||||
|
||||
func assertSync(t *testing.T, beans ...interface{}) {
|
||||
for _, bean := range beans {
|
||||
t.Run(testEngine.TableName(bean, true), func(t *testing.T) {
|
||||
assert.NoError(t, testEngine.DropTables(bean))
|
||||
assert.NoError(t, testEngine.Sync2(bean))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDump(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestDumpStruct struct {
|
||||
Id int64
|
||||
|
@ -89,7 +111,7 @@ func TestDump(t *testing.T) {
|
|||
os.Remove(fp)
|
||||
assert.NoError(t, testEngine.DumpAllToFile(fp))
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
sess := testEngine.NewSession()
|
||||
defer sess.Close()
|
||||
|
@ -107,7 +129,7 @@ func TestDump(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetSchema(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
if testEngine.Dialect().URI().DBType == schemas.POSTGRES {
|
||||
oldSchema := testEngine.Dialect().URI().Schema
|
13
integrations/main_test.go
Normal file
13
integrations/main_test.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2017 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
MainTest(m)
|
||||
}
|
|
@ -2,18 +2,20 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBefore_Get(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type BeforeTable struct {
|
||||
Id int64
|
||||
|
@ -40,7 +42,7 @@ func TestBefore_Get(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBefore_Find(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type BeforeTable2 struct {
|
||||
Id int64
|
||||
|
@ -101,7 +103,7 @@ func (p *ProcessorsStruct) BeforeDelete() {
|
|||
p.B4DeleteFlag = 1
|
||||
}
|
||||
|
||||
func (p *ProcessorsStruct) BeforeSet(col string, cell Cell) {
|
||||
func (p *ProcessorsStruct) BeforeSet(col string, cell xorm.Cell) {
|
||||
p.BeforeSetFlag = p.BeforeSetFlag + 1
|
||||
}
|
||||
|
||||
|
@ -117,12 +119,12 @@ func (p *ProcessorsStruct) AfterDelete() {
|
|||
p.AfterDeletedFlag = 1
|
||||
}
|
||||
|
||||
func (p *ProcessorsStruct) AfterSet(col string, cell Cell) {
|
||||
func (p *ProcessorsStruct) AfterSet(col string, cell xorm.Cell) {
|
||||
p.AfterSetFlag = p.AfterSetFlag + 1
|
||||
}
|
||||
|
||||
func TestProcessors(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&ProcessorsStruct{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -356,7 +358,7 @@ func TestProcessors(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProcessorsTx(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&ProcessorsStruct{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -830,19 +832,19 @@ type AfterLoadStructB struct {
|
|||
Err error `xorm:"-"`
|
||||
}
|
||||
|
||||
func (s *AfterLoadStructB) AfterLoad(session *Session) {
|
||||
func (s *AfterLoadStructB) AfterLoad(session *xorm.Session) {
|
||||
has, err := session.ID(s.AId).NoAutoCondition().Get(&s.A)
|
||||
if err != nil {
|
||||
s.Err = err
|
||||
return
|
||||
}
|
||||
if !has {
|
||||
s.Err = ErrNotExist
|
||||
s.Err = xorm.ErrNotExist
|
||||
}
|
||||
}
|
||||
|
||||
func TestAfterLoadProcessor(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(AfterLoadStructA), new(AfterLoadStructB))
|
||||
|
||||
|
@ -893,7 +895,7 @@ func (a *AfterInsertStruct) AfterInsert() {
|
|||
}
|
||||
|
||||
func TestAfterInsert(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(AfterInsertStruct))
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestRows(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserRows struct {
|
||||
Id int64
|
||||
|
@ -85,7 +85,7 @@ func TestRows(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRowsMyTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserRowsMyTable struct {
|
||||
Id int64
|
||||
|
@ -140,7 +140,7 @@ func (UserRowsSpecTable) TableName() string {
|
|||
}
|
||||
|
||||
func TestRowsSpecTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(UserRowsSpecTable)))
|
||||
|
||||
cnt, err := testEngine.Insert(&UserRowsSpecTable{
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSetExpr(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserExprIssue struct {
|
||||
Id int64
|
||||
|
@ -64,7 +64,7 @@ func TestSetExpr(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCols(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type ColsTable struct {
|
||||
Id int64
|
||||
|
@ -96,7 +96,7 @@ func TestCols(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMustCol(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CustomerUpdate struct {
|
||||
Id int64 `form:"id" json:"id"`
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestBuilder(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
const (
|
||||
OpEqual int = iota
|
||||
|
@ -102,7 +102,7 @@ func TestBuilder(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIn(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(Userinfo)))
|
||||
|
||||
cnt, err := testEngine.Insert([]Userinfo{
|
||||
|
@ -195,7 +195,7 @@ func TestIn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindAndCount(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type FindAndCount struct {
|
||||
Id int64
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoDelete struct {
|
||||
Uid int64 `xorm:"id pk not null autoincr"`
|
||||
|
@ -71,7 +71,7 @@ func TestDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeleted(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type Deleted struct {
|
||||
Id int64 `xorm:"pk"`
|
||||
|
@ -158,7 +158,7 @@ func TestDeleted(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCacheDelete(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
oldCacher := testEngine.GetDefaultCacher()
|
||||
cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 1000)
|
||||
|
@ -190,7 +190,7 @@ func TestCacheDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnscopeDelete(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UnscopeDeleteStruct struct {
|
||||
Id int64
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestExistStruct(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type RecordExist struct {
|
||||
Id int64
|
||||
|
@ -78,7 +78,7 @@ func TestExistStruct(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExistStructForJoin(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type Number struct {
|
||||
Id int64
|
||||
|
@ -190,7 +190,7 @@ func TestExistContext(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(ContextQueryStruct))
|
||||
|
||||
_, err := testEngine.Insert(&ContextQueryStruct{Name: "1"})
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func TestJoinLimit(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type Salary struct {
|
||||
Id int64
|
||||
|
@ -62,17 +62,8 @@ func TestJoinLimit(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func assertSync(t *testing.T, beans ...interface{}) {
|
||||
for _, bean := range beans {
|
||||
t.Run(testEngine.TableName(bean, true), func(t *testing.T) {
|
||||
assert.NoError(t, testEngine.DropTables(bean))
|
||||
assert.NoError(t, testEngine.Sync2(bean))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhere(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
|
@ -85,7 +76,7 @@ func TestWhere(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := make([]Userinfo, 0)
|
||||
|
@ -100,7 +91,7 @@ func TestFind(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFind2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
users := make([]*Userinfo, 0)
|
||||
|
||||
assertSync(t, new(Userinfo))
|
||||
|
@ -125,7 +116,7 @@ func (TeamUser) TableName() string {
|
|||
|
||||
func TestFind3(t *testing.T) {
|
||||
var teamUser = new(TeamUser)
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
err := testEngine.Sync2(new(Team), teamUser)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -179,7 +170,7 @@ func TestFind3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindMap(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
cnt, err := testEngine.Insert(&Userinfo{
|
||||
|
@ -208,7 +199,7 @@ func TestFindMap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindMap2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := make(map[int64]*Userinfo)
|
||||
|
@ -217,7 +208,7 @@ func TestFindMap2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDistinct(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
_, err := testEngine.Insert(&Userinfo{
|
||||
|
@ -242,7 +233,7 @@ func TestDistinct(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOrder(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := make([]Userinfo, 0)
|
||||
|
@ -255,7 +246,7 @@ func TestOrder(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGroupBy(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := make([]Userinfo, 0)
|
||||
|
@ -264,7 +255,7 @@ func TestGroupBy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHaving(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
users := make([]Userinfo, 0)
|
||||
|
@ -273,7 +264,7 @@ func TestHaving(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOrderSameMapper(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
testEngine.UnMapType(utils.ReflectValue(new(Userinfo)).Type())
|
||||
|
||||
mapper := testEngine.GetTableMapper()
|
||||
|
@ -296,7 +287,7 @@ func TestOrderSameMapper(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHavingSameMapper(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
testEngine.UnMapType(utils.ReflectValue(new(Userinfo)).Type())
|
||||
|
||||
mapper := testEngine.GetTableMapper()
|
||||
|
@ -313,7 +304,7 @@ func TestHavingSameMapper(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindInts(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -340,7 +331,7 @@ func TestFindInts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindStrings(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
username := testEngine.GetColumnMapper().Obj2Table("Username")
|
||||
|
@ -350,7 +341,7 @@ func TestFindStrings(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindMyString(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
username := testEngine.GetColumnMapper().Obj2Table("Username")
|
||||
|
@ -361,7 +352,7 @@ func TestFindMyString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindInterface(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -372,7 +363,7 @@ func TestFindInterface(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindSliceBytes(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -382,7 +373,7 @@ func TestFindSliceBytes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindSlicePtrString(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -392,7 +383,7 @@ func TestFindSlicePtrString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindMapBytes(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -402,7 +393,7 @@ func TestFindMapBytes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindMapPtrString(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
userinfo := testEngine.GetTableMapper().Obj2Table("Userinfo")
|
||||
|
@ -417,7 +408,7 @@ func TestFindBit(t *testing.T) {
|
|||
Msg bool `xorm:"bit"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindBitStruct))
|
||||
|
||||
cnt, err := testEngine.Insert([]FindBitStruct{
|
||||
|
@ -445,7 +436,7 @@ func TestFindMark(t *testing.T) {
|
|||
MarkA string `xorm:"VARCHAR(1)"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Mark))
|
||||
|
||||
cnt, err := testEngine.Insert([]Mark{
|
||||
|
@ -476,7 +467,7 @@ func TestFindAndCountOneFunc(t *testing.T) {
|
|||
Msg bool `xorm:"bit"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindAndCountStruct))
|
||||
|
||||
cnt, err := testEngine.Insert([]FindAndCountStruct{
|
||||
|
@ -544,7 +535,7 @@ func TestFindAndCountOneFuncWithDeleted(t *testing.T) {
|
|||
DeletedAt int64 `xorm:"deleted notnull default(0) index"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(CommentWithDeleted))
|
||||
|
||||
var comments []CommentWithDeleted
|
||||
|
@ -569,7 +560,7 @@ func TestFindAndCount2(t *testing.T) {
|
|||
CreateBy *TestFindAndCountUser `xorm:"'create_by'"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestFindAndCountUser), new(TestFindAndCountHotel))
|
||||
|
||||
var u = TestFindAndCountUser{
|
||||
|
@ -627,7 +618,7 @@ func (device *FindMapDevice) TableName() string {
|
|||
}
|
||||
|
||||
func TestFindMapStringId(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindMapDevice))
|
||||
|
||||
cnt, err := testEngine.Insert(&FindMapDevice{
|
||||
|
@ -698,7 +689,7 @@ func TestFindExtends(t *testing.T) {
|
|||
FindExtendsB `xorm:"extends"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindExtendsA))
|
||||
|
||||
cnt, err := testEngine.Insert(&FindExtendsA{
|
||||
|
@ -733,7 +724,7 @@ func TestFindExtends3(t *testing.T) {
|
|||
FindExtendsBB `xorm:"extends"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(FindExtendsAA))
|
||||
|
||||
cnt, err := testEngine.Insert(&FindExtendsAA{
|
||||
|
@ -769,7 +760,7 @@ func TestFindCacheLimit(t *testing.T) {
|
|||
Created time.Time `xorm:"created"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(InviteCode))
|
||||
|
||||
cnt, err := testEngine.Insert(&InviteCode{
|
||||
|
@ -814,7 +805,7 @@ func TestFindJoin(t *testing.T) {
|
|||
Id int64
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(SceneItem), new(DeviceUserPrivrels), new(Order))
|
||||
|
||||
var scenes []SceneItem
|
||||
|
@ -844,7 +835,7 @@ func TestJoinFindLimit(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(JoinFindLimit1), new(JoinFindLimit2))
|
||||
|
||||
var finds []JoinFindLimit1
|
||||
|
@ -876,7 +867,7 @@ func TestMoreExtends(t *testing.T) {
|
|||
Users MoreExtendsUsers `xorm:"extends" json:"users"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(MoreExtendsUsers), new(MoreExtendsBooks))
|
||||
|
||||
var books []MoreExtendsBooksExtend
|
||||
|
@ -904,7 +895,7 @@ func TestDistinctAndCols(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(DistinctAndCols))
|
||||
|
||||
cnt, err := testEngine.Insert(&DistinctAndCols{
|
|
@ -2,21 +2,73 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm/contexts"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func convertInt(v interface{}) (int64, error) {
|
||||
switch v.(type) {
|
||||
case int:
|
||||
return int64(v.(int)), nil
|
||||
case int8:
|
||||
return int64(v.(int8)), nil
|
||||
case int16:
|
||||
return int64(v.(int16)), nil
|
||||
case int32:
|
||||
return int64(v.(int32)), nil
|
||||
case int64:
|
||||
return v.(int64), nil
|
||||
case []byte:
|
||||
i, err := strconv.ParseInt(string(v.([]byte)), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
case string:
|
||||
i, err := strconv.ParseInt(v.(string), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unsupported type: %v", v)
|
||||
}
|
||||
|
||||
func convertFloat(v interface{}) (float64, error) {
|
||||
switch v.(type) {
|
||||
case float32:
|
||||
return float64(v.(float32)), nil
|
||||
case float64:
|
||||
return v.(float64), nil
|
||||
case string:
|
||||
i, err := strconv.ParseFloat(v.(string), 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
case []byte:
|
||||
i, err := strconv.ParseFloat(string(v.([]byte)), 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unsupported type: %v", v)
|
||||
}
|
||||
|
||||
func TestGetVar(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -221,7 +273,7 @@ func TestGetVar(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetStruct(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoGet struct {
|
||||
Uid int `xorm:"pk autoincr"`
|
||||
|
@ -276,7 +328,7 @@ func TestGetStruct(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetSlice(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoSlice struct {
|
||||
Uid int `xorm:"pk autoincr"`
|
||||
|
@ -292,7 +344,7 @@ func TestGetSlice(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetError(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetError struct {
|
||||
Uid int `xorm:"pk autoincr"`
|
||||
|
@ -312,7 +364,7 @@ func TestGetError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestJSONString(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type JsonString struct {
|
||||
Id int64
|
||||
|
@ -345,7 +397,7 @@ func TestJSONString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetActionMapping(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type ActionMapping struct {
|
||||
ActionId string `xorm:"pk"`
|
||||
|
@ -382,7 +434,7 @@ func TestGetStructId(t *testing.T) {
|
|||
Id int64
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestGetStruct))
|
||||
|
||||
_, err := testEngine.Insert(&TestGetStruct{})
|
||||
|
@ -409,7 +461,7 @@ func TestContextGet(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(ContextGetStruct))
|
||||
|
||||
_, err := testEngine.Insert(&ContextGetStruct{Name: "1"})
|
||||
|
@ -447,7 +499,7 @@ func TestContextGet2(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(ContextGetStruct2))
|
||||
|
||||
_, err := testEngine.Insert(&ContextGetStruct2{Name: "1"})
|
||||
|
@ -486,7 +538,7 @@ func (MyGetCustomTableImpletation) TableName() string {
|
|||
}
|
||||
|
||||
func TestGetCustomTableInterface(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Table(getCustomTableName).Sync2(new(MyGetCustomTableImpletation)))
|
||||
|
||||
exist, err := testEngine.IsTableExist(getCustomTableName)
|
||||
|
@ -511,7 +563,7 @@ func TestGetNullVar(t *testing.T) {
|
|||
Age int
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestGetNullVarStruct))
|
||||
|
||||
affected, err := testEngine.Exec("insert into " + testEngine.TableName(new(TestGetNullVarStruct), true) + " (name,age) values (null,null)")
|
||||
|
@ -596,7 +648,7 @@ func TestCustomTypes(t *testing.T) {
|
|||
Age MyInt
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestCustomizeStruct))
|
||||
|
||||
var s = TestCustomizeStruct{
|
||||
|
@ -627,7 +679,7 @@ func TestGetViaMapCond(t *testing.T) {
|
|||
Index int
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(GetViaMapCond))
|
||||
|
||||
var (
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -10,11 +10,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInsertOne(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type Test struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -31,7 +33,7 @@ func TestInsertOne(t *testing.T) {
|
|||
|
||||
func TestInsertMulti(t *testing.T) {
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
type TestMulti struct {
|
||||
Id int64 `xorm:"int(11) pk"`
|
||||
Name string `xorm:"varchar(255)"`
|
||||
|
@ -106,7 +108,7 @@ func callbackLooper(datas interface{}, step int, actionFunc func(interface{}) er
|
|||
}
|
||||
|
||||
func TestInsertOneIfPkIsPoint(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestPoint struct {
|
||||
Id *int64 `xorm:"autoincr pk notnull 'id'"`
|
||||
|
@ -122,7 +124,7 @@ func TestInsertOneIfPkIsPoint(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertOneIfPkIsPointRename(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
type ID *int64
|
||||
type TestPoint2 struct {
|
||||
Id ID `xorm:"autoincr pk notnull 'id'"`
|
||||
|
@ -138,7 +140,7 @@ func TestInsertOneIfPkIsPointRename(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
user := Userinfo{0, "xiaolunwen", "dev", "lunny", time.Now(),
|
||||
|
@ -156,7 +158,7 @@ func TestInsert(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertAutoIncr(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
// auto increment insert
|
||||
|
@ -177,7 +179,7 @@ type DefaultInsert struct {
|
|||
}
|
||||
|
||||
func TestInsertDefault(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
di := new(DefaultInsert)
|
||||
err := testEngine.Sync2(di)
|
||||
|
@ -203,7 +205,7 @@ type DefaultInsert2 struct {
|
|||
}
|
||||
|
||||
func TestInsertDefault2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
di := new(DefaultInsert2)
|
||||
err := testEngine.Sync2(di)
|
||||
|
@ -254,7 +256,7 @@ type CreatedInsert6 struct {
|
|||
}
|
||||
|
||||
func TestInsertCreated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
di := new(CreatedInsert)
|
||||
err := testEngine.Sync2(di)
|
||||
|
@ -367,7 +369,7 @@ func TestDefaultTime3(t *testing.T) {
|
|||
Mtime JSONTime `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP updated" json:"mtime"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(PrepareTask))
|
||||
|
||||
prepareTask := &PrepareTask{
|
||||
|
@ -386,7 +388,7 @@ type MyJSONTime struct {
|
|||
}
|
||||
|
||||
func TestCreatedJsonTime(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
di5 := new(MyJSONTime)
|
||||
err := testEngine.Sync2(di5)
|
||||
|
@ -407,7 +409,7 @@ func TestCreatedJsonTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertMulti2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
|
@ -434,7 +436,7 @@ func TestInsertMulti2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertMulti2Interface(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
|
@ -465,7 +467,7 @@ func TestInsertMulti2Interface(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertTwoTable(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(Userinfo), new(Userdetail))
|
||||
|
||||
|
@ -480,7 +482,7 @@ func TestInsertTwoTable(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertCreatedInt64(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestCreatedInt64 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -512,7 +514,7 @@ func (MyUserinfo) TableName() string {
|
|||
}
|
||||
|
||||
func TestInsertMulti3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
testEngine.ShowSQL(true)
|
||||
assertSync(t, new(MyUserinfo))
|
||||
|
@ -556,7 +558,7 @@ func (MyUserinfo2) TableName() string {
|
|||
}
|
||||
|
||||
func TestInsertMulti4(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
testEngine.ShowSQL(false)
|
||||
assertSync(t, new(MyUserinfo2))
|
||||
|
@ -602,7 +604,7 @@ func TestAnonymousStruct(t *testing.T) {
|
|||
} `json:"ext" xorm:"'EXT' json notnull"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(PlainFoo))
|
||||
|
||||
_, err := testEngine.Insert(&PlainFoo{
|
||||
|
@ -631,7 +633,7 @@ func TestInsertMap(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(InsertMap))
|
||||
|
||||
cnt, err := testEngine.Table(new(InsertMap)).Insert(map[string]interface{}{
|
||||
|
@ -716,7 +718,7 @@ func TestInsertWhere(t *testing.T) {
|
|||
IsTrue bool
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(InsertWhere))
|
||||
|
||||
var i = InsertWhere{
|
||||
|
@ -811,7 +813,7 @@ func TestInsertWhere(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertExpr2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type InsertExprsRelease struct {
|
||||
Id int64
|
||||
|
@ -877,7 +879,7 @@ func (NightlyRate) TableName() string {
|
|||
}
|
||||
|
||||
func TestMultipleInsertTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
tableName := `prd_nightly_rate_16`
|
||||
assert.NoError(t, testEngine.Table(tableName).Sync2(new(NightlyRate)))
|
||||
|
@ -908,7 +910,7 @@ func TestMultipleInsertTableName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertMultiWithOmit(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestMultiOmit struct {
|
||||
Id int64 `xorm:"int(11) pk"`
|
||||
|
@ -951,7 +953,7 @@ func TestInsertMultiWithOmit(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInsertTwice(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type InsertStructA struct {
|
||||
FieldA int
|
||||
|
@ -977,7 +979,7 @@ func TestInsertTwice(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
_, err = ssn.Insert(sliceA)
|
||||
assert.EqualValues(t, ErrNoElementsOnSlice, err)
|
||||
assert.EqualValues(t, xorm.ErrNoElementsOnSlice, err)
|
||||
|
||||
_, err = ssn.Insert(sliceB)
|
||||
assert.NoError(t, err)
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestIterate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserIterate struct {
|
||||
Id int64
|
||||
|
@ -39,7 +39,7 @@ func TestIterate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBufferIterate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserBufferIterate struct {
|
||||
Id int64
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
@ -66,7 +66,7 @@ type MyStringPK struct {
|
|||
}
|
||||
|
||||
func TestIntId(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&IntId{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -99,7 +99,7 @@ func TestIntId(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInt16Id(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Int16Id{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -132,7 +132,7 @@ func TestInt16Id(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInt32Id(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Int32Id{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -165,7 +165,7 @@ func TestInt32Id(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUintId(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&UintId{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -206,7 +206,7 @@ func TestUintId(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUint16Id(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Uint16Id{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -240,7 +240,7 @@ func TestUint16Id(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUint32Id(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Uint32Id{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -274,7 +274,7 @@ func TestUint32Id(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUint64Id(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Uint64Id{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -312,7 +312,7 @@ func TestUint64Id(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestStringPK(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&StringPK{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -352,7 +352,7 @@ type CompositeKey struct {
|
|||
}
|
||||
|
||||
func TestCompositeKey(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&CompositeKey{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -407,7 +407,7 @@ func TestCompositeKey(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCompositeKey2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type User struct {
|
||||
UserId string `xorm:"varchar(19) not null pk"`
|
||||
|
@ -459,7 +459,7 @@ type UserPK2 struct {
|
|||
}
|
||||
|
||||
func TestCompositeKey3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&UserPK2{})
|
||||
|
||||
|
@ -497,7 +497,7 @@ func TestCompositeKey3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMyIntId(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&MyIntPK{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -535,7 +535,7 @@ func TestMyIntId(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMyStringId(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&MyStringPK{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -576,7 +576,7 @@ func TestSingleAutoIncrColumn(t *testing.T) {
|
|||
Id int64 `xorm:"pk autoincr"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Account))
|
||||
|
||||
_, err := testEngine.Insert(&Account{})
|
||||
|
@ -591,7 +591,7 @@ func TestCompositePK(t *testing.T) {
|
|||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
tables1, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
|
@ -626,7 +626,7 @@ func TestNoPKIdQueryUpdate(t *testing.T) {
|
|||
Username string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NoPKTable))
|
||||
|
||||
cnt, err := testEngine.Insert(&NoPKTable{
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
func TestQueryString(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar2 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -48,7 +48,7 @@ func TestQueryString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryString2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar3 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -108,7 +108,7 @@ func toFloat64(i interface{}) float64 {
|
|||
}
|
||||
|
||||
func TestQueryInterface(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVarInterface struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -139,7 +139,7 @@ func TestQueryInterface(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryNoParams(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type QueryNoParams struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -188,7 +188,7 @@ func TestQueryNoParams(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryStringNoParam(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar4 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -225,7 +225,7 @@ func TestQueryStringNoParam(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQuerySliceStringNoParam(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar6 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -262,7 +262,7 @@ func TestQuerySliceStringNoParam(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryInterfaceNoParam(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type GetVar5 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -291,7 +291,7 @@ func TestQueryInterfaceNoParam(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryWithBuilder(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type QueryWithBuilder struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
||||
|
@ -336,7 +336,7 @@ func TestQueryWithBuilder(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestJoinWithSubQuery(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type JoinWithSubQuery1 struct {
|
||||
Id int64 `xorm:"autoincr pk"`
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestExecAndQuery(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoQuery struct {
|
||||
Uid int
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestStoreEngine(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.DropTables("user_store_engine"))
|
||||
|
||||
|
@ -26,7 +26,7 @@ func TestStoreEngine(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateTable(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.DropTables("user_user"))
|
||||
|
||||
|
@ -39,7 +39,7 @@ func TestCreateTable(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateMultiTables(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
session := testEngine.NewSession()
|
||||
defer session.Close()
|
||||
|
@ -94,7 +94,7 @@ func (s *SyncTable3) TableName() string {
|
|||
}
|
||||
|
||||
func TestSyncTable(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.Sync2(new(SyncTable1)))
|
||||
|
||||
|
@ -119,7 +119,7 @@ func TestSyncTable(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSyncTable2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.Table("sync_tablex").Sync2(new(SyncTable1)))
|
||||
|
||||
|
@ -144,7 +144,7 @@ func TestSyncTable2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsTableExist(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
exist, err := testEngine.IsTableExist(new(CustomTableName))
|
||||
assert.NoError(t, err)
|
||||
|
@ -158,7 +158,7 @@ func TestIsTableExist(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsTableEmpty(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type NumericEmpty struct {
|
||||
Numeric float64 `xorm:"numeric(26,2)"`
|
||||
|
@ -201,7 +201,7 @@ func (c *CustomTableName) TableName() string {
|
|||
}
|
||||
|
||||
func TestCustomTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
c := new(CustomTableName)
|
||||
assert.NoError(t, testEngine.DropTables(c))
|
||||
|
@ -220,7 +220,7 @@ type IndexOrUnique struct {
|
|||
}
|
||||
|
||||
func TestIndexAndUnique(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.CreateTables(&IndexOrUnique{}))
|
||||
|
||||
|
@ -236,7 +236,7 @@ func TestIndexAndUnique(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMetaInfo(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(CustomTableName), new(IndexOrUnique)))
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
|
@ -248,7 +248,7 @@ func TestMetaInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCharst(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables("user_charset")
|
||||
assert.NoError(t, err)
|
||||
|
@ -264,7 +264,7 @@ func TestSync2_1(t *testing.T) {
|
|||
Id_delete int8 `xorm:"null int default 1"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.DropTables("wx_test"))
|
||||
assert.NoError(t, testEngine.Sync2(new(WxTest)))
|
||||
|
@ -281,7 +281,7 @@ func TestUnique_1(t *testing.T) {
|
|||
UpdatedAt time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assert.NoError(t, testEngine.DropTables("user_unique"))
|
||||
assert.NoError(t, testEngine.Sync2(new(UserUnique)))
|
||||
|
@ -297,7 +297,7 @@ func TestSync2_2(t *testing.T) {
|
|||
UserId int64 `xorm:"index"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
var tableNames = make(map[string]bool)
|
||||
for i := 0; i < 10; i++ {
|
||||
|
@ -326,7 +326,7 @@ func TestSync2_Default(t *testing.T) {
|
|||
Name string `xorm:"default('my_name')"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestSync2Default))
|
||||
assert.NoError(t, testEngine.Sync2(new(TestSync2Default)))
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -23,7 +23,7 @@ func TestSum(t *testing.T) {
|
|||
Float float32
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(SumStruct)))
|
||||
|
||||
var (
|
||||
|
@ -82,7 +82,7 @@ func (s SumStructWithTableName) TableName() string {
|
|||
}
|
||||
|
||||
func TestSumWithTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(SumStructWithTableName)))
|
||||
|
||||
var (
|
||||
|
@ -132,7 +132,7 @@ func TestSumWithTableName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSumCustomColumn(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type SumStruct2 struct {
|
||||
Int int
|
||||
|
@ -160,7 +160,7 @@ func TestSumCustomColumn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoCount struct {
|
||||
Departname string
|
||||
|
@ -196,7 +196,7 @@ func TestCount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSQLCount(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserinfoCount2 struct {
|
||||
Id int64
|
||||
|
@ -218,7 +218,7 @@ func TestSQLCount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCountWithOthers(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CountWithOthers struct {
|
||||
Id int64
|
||||
|
@ -252,7 +252,7 @@ func (CountWithTableName) TableName() string {
|
|||
}
|
||||
|
||||
func TestWithTableName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(CountWithTableName))
|
||||
|
||||
|
@ -276,7 +276,7 @@ func TestWithTableName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCountWithSelectCols(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
assertSync(t, new(CountWithTableName))
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func TestClose(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
sess1 := testEngine.NewSession()
|
||||
sess1.Close()
|
||||
|
@ -31,7 +31,7 @@ func TestNullFloatStruct(t *testing.T) {
|
|||
Amount MyNullFloat64
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync2(new(MyNullFloatStruct)))
|
||||
|
||||
_, err := testEngine.Insert(&MyNullFloatStruct{
|
||||
|
@ -45,7 +45,7 @@ func TestNullFloatStruct(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMustLogSQL(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
testEngine.ShowSQL(false)
|
||||
defer testEngine.ShowSQL(true)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func TestTransaction(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
counter := func(t *testing.T) {
|
||||
|
@ -48,7 +48,7 @@ func TestTransaction(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCombineTransaction(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
counter := func() {
|
||||
|
@ -81,7 +81,7 @@ func TestCombineTransaction(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCombineTransactionSameMapper(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
oldMapper := testEngine.GetColumnMapper()
|
||||
testEngine.UnMapType(utils.ReflectValue(new(Userinfo)).Type())
|
||||
|
@ -124,7 +124,7 @@ func TestCombineTransactionSameMapper(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMultipleTransaction(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type MultipleTransaction struct {
|
||||
Id int64
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -11,12 +11,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
||||
func TestUpdateMap(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateTable struct {
|
||||
Id int64
|
||||
|
@ -46,7 +47,7 @@ func TestUpdateLimit(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateTable2 struct {
|
||||
Id int64
|
||||
|
@ -88,7 +89,7 @@ type ForUpdate struct {
|
|||
Name string
|
||||
}
|
||||
|
||||
func setupForUpdate(engine EngineInterface) error {
|
||||
func setupForUpdate(engine xorm.EngineInterface) error {
|
||||
v := new(ForUpdate)
|
||||
err := testEngine.DropTables(v)
|
||||
if err != nil {
|
||||
|
@ -218,7 +219,7 @@ func TestWithIn(t *testing.T) {
|
|||
Test bool `xorm:"Test"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assert.NoError(t, testEngine.Sync(new(temp3)))
|
||||
|
||||
testEngine.Insert(&[]temp3{
|
||||
|
@ -270,7 +271,7 @@ type Article struct {
|
|||
}
|
||||
|
||||
func TestUpdateMap2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(UpdateMustCols))
|
||||
|
||||
_, err := testEngine.Table("update_must_cols").Where("id =?", 1).Update(map[string]interface{}{
|
||||
|
@ -280,7 +281,7 @@ func TestUpdateMap2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdate1(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
_, err := testEngine.Insert(&Userinfo{
|
||||
|
@ -410,7 +411,7 @@ func TestUpdate1(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateIncrDecr(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
col1 := &UpdateIncr{
|
||||
Name: "test",
|
||||
|
@ -473,7 +474,7 @@ type UpdatedUpdate5 struct {
|
|||
}
|
||||
|
||||
func TestUpdateUpdated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
di := new(UpdatedUpdate)
|
||||
err := testEngine.Sync2(di)
|
||||
|
@ -568,7 +569,7 @@ func TestUpdateUpdated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateSameMapper(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
oldMapper := testEngine.GetTableMapper()
|
||||
testEngine.UnMapType(utils.ReflectValue(new(Userinfo)).Type())
|
||||
|
@ -695,7 +696,7 @@ func TestUpdateSameMapper(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUseBool(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
cnt1, err := testEngine.Count(&Userinfo{})
|
||||
|
@ -725,7 +726,7 @@ func TestUseBool(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(Userinfo))
|
||||
|
||||
_, err := testEngine.UseBool().Update(&Userinfo{IsMan: true})
|
||||
|
@ -748,7 +749,7 @@ func TestBool(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNoUpdate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type NoUpdate struct {
|
||||
Id int64
|
||||
|
@ -769,7 +770,7 @@ func TestNoUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewUpdate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TbUserInfo struct {
|
||||
Id int64 `xorm:"pk autoincr unique BIGINT" json:"id"`
|
||||
|
@ -799,7 +800,7 @@ func TestNewUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateUpdate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type PublicKeyUpdate struct {
|
||||
Id int64
|
||||
|
@ -816,7 +817,7 @@ func TestUpdateUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreatedUpdated2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CreatedUpdatedStruct struct {
|
||||
Id int64
|
||||
|
@ -860,7 +861,7 @@ func TestCreatedUpdated2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeletedUpdate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DeletedUpdatedStruct struct {
|
||||
Id int64
|
||||
|
@ -908,7 +909,7 @@ func TestDeletedUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateMapCondition(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateMapCondition struct {
|
||||
Id int64
|
||||
|
@ -939,7 +940,7 @@ func TestUpdateMapCondition(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateMapContent(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateMapContent struct {
|
||||
Id int64
|
||||
|
@ -1014,7 +1015,7 @@ func TestUpdateCondiBean(t *testing.T) {
|
|||
Name string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NeedUpdateBean))
|
||||
|
||||
cnt, err := testEngine.Insert(&NeedUpdateBean{
|
||||
|
@ -1064,7 +1065,7 @@ func TestWhereCondErrorWhenUpdate(t *testing.T) {
|
|||
RequestToken string
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(AuthRequestError))
|
||||
|
||||
_, err := testEngine.Cols("challenge_token", "request_token", "challenge_agent", "status").
|
||||
|
@ -1073,11 +1074,11 @@ func TestWhereCondErrorWhenUpdate(t *testing.T) {
|
|||
ChallengeToken: "2",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.EqualValues(t, ErrConditionType, err)
|
||||
assert.EqualValues(t, xorm.ErrConditionType, err)
|
||||
}
|
||||
|
||||
func TestUpdateDeleted(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateDeletedStruct struct {
|
||||
Id int64
|
||||
|
@ -1118,7 +1119,7 @@ func TestUpdateDeleted(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateExprs(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateExprs struct {
|
||||
Id int64
|
||||
|
@ -1149,7 +1150,7 @@ func TestUpdateExprs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateAlias(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateAlias struct {
|
||||
Id int64
|
||||
|
@ -1180,7 +1181,7 @@ func TestUpdateAlias(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateExprs2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateExprsRelease struct {
|
||||
Id int64
|
||||
|
@ -1225,7 +1226,7 @@ func TestUpdateExprs2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateMap3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UpdateMapUser struct {
|
||||
Id uint64 `xorm:"PK autoincr"`
|
||||
|
@ -1283,7 +1284,7 @@ func TestUpdateIgnoreOnlyFromDBFields(t *testing.T) {
|
|||
return &record
|
||||
|
||||
}
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestOnlyFromDBField))
|
||||
|
||||
_, err := testEngine.Insert(&TestOnlyFromDBField{
|
||||
|
@ -1311,7 +1312,7 @@ func TestUpdateMultiplePK(t *testing.T) {
|
|||
Value string `xorm:"notnull varchar(4000)" description:"值"`
|
||||
}
|
||||
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(TestUpdateMultiplePKStruct))
|
||||
|
||||
test := &TestUpdateMultiplePKStruct{
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -60,7 +60,7 @@ type UserAndDetail struct {
|
|||
}
|
||||
|
||||
func TestExtends(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&tempUser2{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -211,7 +211,7 @@ type MessageExtend4 struct {
|
|||
}
|
||||
|
||||
func TestExtends2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -272,7 +272,7 @@ func TestExtends2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExtends3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -337,7 +337,7 @@ func TestExtends3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExtends4(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&Message{}, &MessageUser{}, &MessageType{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -410,7 +410,7 @@ type Book struct {
|
|||
}
|
||||
|
||||
func TestExtends5(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
err := testEngine.DropTables(&Book{}, &Size{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@ -508,7 +508,7 @@ func TestExtends5(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCacheTag(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CacheDomain struct {
|
||||
Id int64 `xorm:"pk cache"`
|
||||
|
@ -520,7 +520,7 @@ func TestCacheTag(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNoCacheTag(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type NoCacheDomain struct {
|
||||
Id int64 `xorm:"pk nocache"`
|
||||
|
@ -536,7 +536,7 @@ type IDGonicMapper struct {
|
|||
}
|
||||
|
||||
func TestGonicMapperID(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
oldMapper := testEngine.GetColumnMapper()
|
||||
testEngine.UnMapType(utils.ReflectValue(new(IDGonicMapper)).Type())
|
||||
|
@ -573,7 +573,7 @@ type IDSameMapper struct {
|
|||
}
|
||||
|
||||
func TestSameMapperID(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
oldMapper := testEngine.GetColumnMapper()
|
||||
testEngine.UnMapType(utils.ReflectValue(new(IDSameMapper)).Type())
|
||||
|
@ -612,7 +612,7 @@ type UserCU struct {
|
|||
}
|
||||
|
||||
func TestCreatedAndUpdated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
u := new(UserCU)
|
||||
err := testEngine.DropTables(u)
|
||||
|
@ -645,7 +645,7 @@ type StrangeName struct {
|
|||
}
|
||||
|
||||
func TestStrangeName(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(new(StrangeName))
|
||||
assert.NoError(t, err)
|
||||
|
@ -662,7 +662,7 @@ func TestStrangeName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreatedUpdated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CreatedUpdated struct {
|
||||
Id int64
|
||||
|
@ -692,7 +692,7 @@ func TestCreatedUpdated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreatedUpdatedInt64(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type CreatedUpdatedInt64 struct {
|
||||
Id int64
|
||||
|
@ -726,7 +726,7 @@ type Lowercase struct {
|
|||
}
|
||||
|
||||
func TestLowerCase(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.Sync2(&Lowercase{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -743,7 +743,7 @@ func TestLowerCase(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAutoIncrTag(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestAutoIncr1 struct {
|
||||
Id int64
|
||||
|
@ -799,7 +799,7 @@ func TestAutoIncrTag(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagComment(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
// FIXME: only support mysql
|
||||
if testEngine.Dialect().URI().DBType != schemas.MYSQL {
|
||||
return
|
||||
|
@ -833,7 +833,7 @@ func TestTagComment(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct struct {
|
||||
Id int64
|
||||
|
@ -877,7 +877,7 @@ func TestTagDefault(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct2 struct {
|
||||
Id int64
|
||||
|
@ -906,7 +906,7 @@ func TestTagDefault2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct3 struct {
|
||||
Id int64
|
||||
|
@ -935,7 +935,7 @@ func TestTagDefault3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault4(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct4 struct {
|
||||
Id int64
|
||||
|
@ -967,7 +967,7 @@ func TestTagDefault4(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault5(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct5 struct {
|
||||
Id int64
|
||||
|
@ -1003,7 +1003,7 @@ func TestTagDefault5(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagDefault6(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DefaultStruct6 struct {
|
||||
Id int64
|
||||
|
@ -1037,7 +1037,7 @@ func TestTagDefault6(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagsDirection(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type OnlyFromDBStruct struct {
|
||||
Id int64
|
||||
|
@ -1099,7 +1099,7 @@ func TestTagsDirection(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagTime(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TagUTCStruct struct {
|
||||
Id int64
|
||||
|
@ -1133,7 +1133,7 @@ func TestTagTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagAutoIncr(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TagAutoIncr struct {
|
||||
Id int64
|
||||
|
@ -1158,7 +1158,7 @@ func TestTagAutoIncr(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTagPrimarykey(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
type TagPrimaryKey struct {
|
||||
Id int64 `xorm:"pk"`
|
||||
Name string `xorm:"VARCHAR(20) pk"`
|
||||
|
@ -1189,7 +1189,7 @@ type VersionS struct {
|
|||
}
|
||||
|
||||
func TestVersion1(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(new(VersionS))
|
||||
assert.NoError(t, err)
|
||||
|
@ -1220,7 +1220,7 @@ func TestVersion1(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVersion2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(new(VersionS))
|
||||
assert.NoError(t, err)
|
||||
|
@ -1247,7 +1247,7 @@ type VersionUintS struct {
|
|||
}
|
||||
|
||||
func TestVersion3(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(new(VersionUintS))
|
||||
assert.NoError(t, err)
|
||||
|
@ -1278,7 +1278,7 @@ func TestVersion3(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVersion4(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(new(VersionUintS))
|
||||
assert.NoError(t, err)
|
||||
|
@ -1298,7 +1298,7 @@ func TestVersion4(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIndexes(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TestIndexesStruct struct {
|
||||
Id int64
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2018 The Xorm Authors. All rights reserved.
|
||||
// Copyright 2017 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
@ -12,11 +12,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ziutek/mymysql/godrv"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/caches"
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/log"
|
||||
|
@ -25,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
testEngine EngineInterface
|
||||
testEngine xorm.EngineInterface
|
||||
dbType string
|
||||
connString string
|
||||
|
||||
|
@ -102,9 +98,9 @@ func createEngine(dbType, connStr string) error {
|
|||
*ignoreSelectUpdate = true
|
||||
}
|
||||
|
||||
testEngine, err = NewEngine(dbType, connStr)
|
||||
testEngine, err = xorm.NewEngine(dbType, connStr)
|
||||
} else {
|
||||
testEngine, err = NewEngineGroup(dbType, strings.Split(connStr, *splitter))
|
||||
testEngine, err = xorm.NewEngineGroup(dbType, strings.Split(connStr, *splitter))
|
||||
if dbType != "mysql" && dbType != "mymysql" {
|
||||
*ignoreSelectUpdate = true
|
||||
}
|
||||
|
@ -160,11 +156,11 @@ func createEngine(dbType, connStr string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func prepareEngine() error {
|
||||
func PrepareEngine() error {
|
||||
return createEngine(dbType, connString)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
func MainTest(m *testing.M) {
|
||||
flag.Parse()
|
||||
|
||||
dbType = *db
|
||||
|
@ -192,7 +188,7 @@ func TestMain(m *testing.M) {
|
|||
testEngine = nil
|
||||
fmt.Println("testing", dbType, connString)
|
||||
|
||||
if err := prepareEngine(); err != nil {
|
||||
if err := PrepareEngine(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
return
|
||||
|
@ -206,9 +202,3 @@ func TestMain(m *testing.M) {
|
|||
|
||||
os.Exit(res)
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
if err := testEngine.Ping(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -20,7 +20,7 @@ func formatTime(t time.Time) string {
|
|||
}
|
||||
|
||||
func TestTimeUserTime(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TimeUser struct {
|
||||
Id string
|
||||
|
@ -50,7 +50,7 @@ func TestTimeUserTime(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserTimeDiffLoc(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
testEngine.SetTZLocation(loc)
|
||||
|
@ -86,7 +86,7 @@ func TestTimeUserTimeDiffLoc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserCreated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserCreated struct {
|
||||
Id string
|
||||
|
@ -115,7 +115,7 @@ func TestTimeUserCreated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserCreatedDiffLoc(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
testEngine.SetTZLocation(loc)
|
||||
|
@ -150,7 +150,7 @@ func TestTimeUserCreatedDiffLoc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserUpdated(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserUpdated struct {
|
||||
Id string
|
||||
|
@ -201,7 +201,7 @@ func TestTimeUserUpdated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserUpdatedDiffLoc(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
testEngine.SetTZLocation(loc)
|
||||
|
@ -258,7 +258,7 @@ func TestTimeUserUpdatedDiffLoc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserDeleted(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserDeleted struct {
|
||||
Id string
|
||||
|
@ -308,7 +308,7 @@ func TestTimeUserDeleted(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTimeUserDeletedDiffLoc(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
testEngine.SetTZLocation(loc)
|
||||
|
@ -385,7 +385,7 @@ func (j *JSONDate) Unix() int64 {
|
|||
}
|
||||
|
||||
func TestCustomTimeUserDeleted(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UserDeleted3 struct {
|
||||
Id string
|
||||
|
@ -432,7 +432,7 @@ func TestCustomTimeUserDeleted(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCustomTimeUserDeletedDiffLoc(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
assert.NoError(t, err)
|
||||
testEngine.SetTZLocation(loc)
|
||||
|
@ -485,7 +485,7 @@ func TestCustomTimeUserDeletedDiffLoc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeletedInt64(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type DeletedInt64Struct struct {
|
||||
Id int64
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
@ -58,19 +58,19 @@ func (m CustomStruct) Value() (driver.Value, error) {
|
|||
}
|
||||
|
||||
func TestCreateNullStructTable(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
err := testEngine.CreateTables(new(NullType))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDropNullStructTable(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
err := testEngine.DropTables(new(NullType))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestNullStructInsert(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
item1 := new(NullType)
|
||||
|
@ -112,7 +112,7 @@ func TestNullStructInsert(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructUpdate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
_, err := testEngine.Insert([]NullType{
|
||||
|
@ -185,7 +185,7 @@ func TestNullStructUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructFind(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
_, err := testEngine.Insert([]NullType{
|
||||
|
@ -250,7 +250,7 @@ func TestNullStructFind(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructIterate(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
if true {
|
||||
|
@ -265,7 +265,7 @@ func TestNullStructIterate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructCount(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
if true {
|
||||
|
@ -276,7 +276,7 @@ func TestNullStructCount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructRows(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
item := new(NullType)
|
||||
|
@ -291,7 +291,7 @@ func TestNullStructRows(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNullStructDelete(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
assertSync(t, new(NullType))
|
||||
|
||||
item := new(NullType)
|
|
@ -2,13 +2,14 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package xorm
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
"xorm.io/xorm/internal/json"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
@ -17,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func TestArrayField(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type ArrayStruct struct {
|
||||
Id int64
|
||||
|
@ -80,7 +81,7 @@ func TestArrayField(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetBytes(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type Varbinary struct {
|
||||
Data []byte `xorm:"VARBINARY(250)"`
|
||||
|
@ -152,14 +153,14 @@ type ConvStruct struct {
|
|||
Slice SliceType
|
||||
}
|
||||
|
||||
func (c *ConvStruct) BeforeSet(name string, cell Cell) {
|
||||
func (c *ConvStruct) BeforeSet(name string, cell xorm.Cell) {
|
||||
if name == "cfg3" || name == "Cfg3" {
|
||||
c.Cfg3 = new(ConvConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConversion(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
c := new(ConvStruct)
|
||||
assert.NoError(t, testEngine.DropTables(c))
|
||||
|
@ -243,7 +244,7 @@ type MyStruct struct {
|
|||
}
|
||||
|
||||
func TestCustomType1(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
err := testEngine.DropTables(&MyStruct{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -331,7 +332,7 @@ type UserCus struct {
|
|||
}
|
||||
|
||||
func TestCustomType2(t *testing.T) {
|
||||
assert.NoError(t, prepareEngine())
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
var uc UserCus
|
||||
err := testEngine.CreateTables(&uc)
|
82
xorm.go
82
xorm.go
|
@ -1,82 +0,0 @@
|
|||
// Copyright 2015 The Xorm Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build go1.11
|
||||
|
||||
package xorm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm/caches"
|
||||
"xorm.io/xorm/core"
|
||||
"xorm.io/xorm/dialects"
|
||||
"xorm.io/xorm/log"
|
||||
"xorm.io/xorm/names"
|
||||
"xorm.io/xorm/schemas"
|
||||
"xorm.io/xorm/tags"
|
||||
)
|
||||
|
||||
func close(engine *Engine) {
|
||||
engine.Close()
|
||||
}
|
||||
|
||||
// NewEngine new a db manager according to the parameter. Currently support four
|
||||
// drivers
|
||||
func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||
dialect, err := dialects.OpenDialect(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db, err := core.Open(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacherMgr := caches.NewManager()
|
||||
mapper := names.NewCacheMapper(new(names.SnakeMapper))
|
||||
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr)
|
||||
|
||||
engine := &Engine{
|
||||
dialect: dialect,
|
||||
TZLocation: time.Local,
|
||||
defaultContext: context.Background(),
|
||||
cacherMgr: cacherMgr,
|
||||
tagParser: tagParser,
|
||||
driverName: driverName,
|
||||
dataSourceName: dataSourceName,
|
||||
db: db,
|
||||
logSessionID: false,
|
||||
}
|
||||
|
||||
if dialect.URI().DBType == schemas.SQLITE {
|
||||
engine.DatabaseTZ = time.UTC
|
||||
} else {
|
||||
engine.DatabaseTZ = time.Local
|
||||
}
|
||||
|
||||
logger := log.NewSimpleLogger(os.Stdout)
|
||||
logger.SetLevel(log.LOG_INFO)
|
||||
engine.SetLogger(log.NewLoggerAdapter(logger))
|
||||
|
||||
runtime.SetFinalizer(engine, close)
|
||||
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
// NewEngineWithParams new a db manager with params. The params will be passed to dialects.
|
||||
func NewEngineWithParams(driverName string, dataSourceName string, params map[string]string) (*Engine, error) {
|
||||
engine, err := NewEngine(driverName, dataSourceName)
|
||||
engine.dialect.SetParams(params)
|
||||
return engine, err
|
||||
}
|
||||
|
||||
// Clone clone an engine
|
||||
func (engine *Engine) Clone() (*Engine, error) {
|
||||
return NewEngine(engine.DriverName(), engine.DataSourceName())
|
||||
}
|
Loading…
Reference in New Issue
Block a user