Browse Source

Move all integrations tests to a standalone sub package (#1635)

Fix vet

Remove unused files

Move all integrations tests to a standalone sub package

Reviewed-on: #1635
tags/godror
Lunny Xiao 2 months ago
parent
commit
79bdda3cf1
40 changed files with 503 additions and 478 deletions
  1. +3
    -6
      .drone.yml
  2. +2
    -0
      .gitignore
  3. +28
    -22
      Makefile
  4. +2
    -0
      README.md
  5. +0
    -50
      convert.go
  6. +5
    -1
      dialects/mssql.go
  7. +5
    -1
      dialects/mysql.go
  8. +5
    -1
      dialects/oracle.go
  9. +5
    -1
      dialects/postgres.go
  10. +5
    -1
      dialects/sqlite3.go
  11. +1
    -1
      doc.go
  12. +54
    -0
      engine.go
  13. +4
    -4
      integrations/cache_test.go
  14. +7
    -5
      integrations/engine_group_test.go
  15. +33
    -11
      integrations/engine_test.go
  16. +13
    -0
      integrations/main_test.go
  17. +13
    -11
      integrations/processors_test.go
  18. +4
    -4
      integrations/rows_test.go
  19. +4
    -4
      integrations/session_cols_test.go
  20. +4
    -4
      integrations/session_cond_test.go
  21. +5
    -5
      integrations/session_delete_test.go
  22. +4
    -4
      integrations/session_exist_test.go
  23. +35
    -44
      integrations/session_find_test.go
  24. +67
    -15
      integrations/session_get_test.go
  25. +28
    -26
      integrations/session_insert_test.go
  26. +3
    -3
      integrations/session_iterate_test.go
  27. +17
    -17
      integrations/session_pk_test.go
  28. +10
    -10
      integrations/session_query_test.go
  29. +2
    -2
      integrations/session_raw_test.go
  30. +16
    -16
      integrations/session_schema_test.go
  31. +9
    -9
      integrations/session_stats_test.go
  32. +4
    -4
      integrations/session_test.go
  33. +5
    -5
      integrations/session_tx_test.go
  34. +30
    -29
      integrations/session_update_test.go
  35. +32
    -32
      integrations/tags_test.go
  36. +9
    -19
      integrations/tests.go
  37. +12
    -12
      integrations/time_test.go
  38. +10
    -10
      integrations/types_null_test.go
  39. +8
    -7
      integrations/types_test.go
  40. +0
    -82
      xorm.go

+ 3
- 6
.drone.yml View File

@@ -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
- 0
.gitignore View File

@@ -34,3 +34,5 @@ test.db.sql
.idea/

*coverage.out
test.db
integrations/*.sql

+ 28
- 22
Makefile View File

@@ -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 ./...)

+ 2
- 0
README.md View File

@@ -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)
```


+ 0
- 50
convert.go View File

@@ -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


+ 5
- 1
dialects/mssql.go View File

@@ -205,7 +205,11 @@ var (
"PROC": true,
}

mssqlQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
mssqlQuoter = schemas.Quoter{
Prefix: '[',
Suffix: ']',
IsReserved: schemas.AlwaysReserve,
}
)

type mssql struct {


+ 5
- 1
dialects/mysql.go View File

@@ -162,7 +162,11 @@ var (
"ZEROFILL": true,
}

mysqlQuoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
mysqlQuoter = schemas.Quoter{
Prefix: '`',
Suffix: '`',
IsReserved: schemas.AlwaysReserve,
}
)

type mysql struct {


+ 5
- 1
dialects/oracle.go View File

@@ -499,7 +499,11 @@ var (
"ZONE": true,
}

oracleQuoter = schemas.Quoter{'[', ']', schemas.AlwaysReserve}
oracleQuoter = schemas.Quoter{
Prefix: '[',
Suffix: ']',
IsReserved: schemas.AlwaysReserve,
}
)

type oracle struct {


+ 5
- 1
dialects/postgres.go View File

@@ -767,7 +767,11 @@ var (
"ZONE": true,
}

postgresQuoter = schemas.Quoter{'"', '"', schemas.AlwaysReserve}
postgresQuoter = schemas.Quoter{
Prefix: '"',
Suffix: '"',
IsReserved: schemas.AlwaysReserve,
}
)

var (


+ 5
- 1
dialects/sqlite3.go View File

@@ -144,7 +144,11 @@ var (
"WITHOUT": true,
}

sqlite3Quoter = schemas.Quoter{'`', '`', schemas.AlwaysReserve}
sqlite3Quoter = schemas.Quoter{
Prefix: '`',
Suffix: '`',
IsReserved: schemas.AlwaysReserve,
}
)

type sqlite3 struct {


+ 1
- 1
doc.go View File

@@ -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
- 0
engine.go View File

@@ -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


cache_test.go → integrations/cache_test.go View File

@@ -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

engine_group_test.go → integrations/engine_group_test.go View File

@@ -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)

engine_test.go → integrations/engine_test.go View File

@@ -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
- 0
integrations/main_test.go View 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)
}

processors_test.go → integrations/processors_test.go View File

@@ -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))


rows_test.go → integrations/rows_test.go View File

@@ -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{

session_cols_test.go → integrations/session_cols_test.go View File

@@ -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"`

session_cond_test.go → integrations/session_cond_test.go View File

@@ -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

session_delete_test.go → integrations/session_delete_test.go View File

@@ -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

session_exist_test.go → integrations/session_exist_test.go View File

@@ -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"})

session_find_test.go → integrations/session_find_test.go View File

@@ -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{

session_get_test.go → integrations/session_get_test.go View File

@@ -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 (

session_insert_test.go → integrations/session_insert_test.go View File

@@ -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)

session_iterate_test.go → integrations/session_iterate_test.go View File

@@ -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

session_pk_test.go → integrations/session_pk_test.go View File

@@ -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{

session_query_test.go → integrations/session_query_test.go View File

@@ -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"