Merge branch 'master'
This commit is contained in:
commit
0c82bad52b
|
@ -35,7 +35,7 @@ test.db.sql
|
||||||
|
|
||||||
*coverage.out
|
*coverage.out
|
||||||
test.db
|
test.db
|
||||||
integrations/*.sql
|
tests/*.sql
|
||||||
integrations/test_sqlite*
|
tests/test_sqlite*
|
||||||
cover.out
|
cover.out
|
||||||
cover.html
|
cover.html
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ SED_INPLACE := sed -i
|
||||||
GO_DIRS := caches contexts integrations core dialects internal log migrate names schemas tags
|
GO_DIRS := caches contexts integrations core dialects internal log migrate names schemas tags
|
||||||
GOFILES := $(wildcard *.go)
|
GOFILES := $(wildcard *.go)
|
||||||
GOFILES += $(shell find $(GO_DIRS) -name "*.go" -type f)
|
GOFILES += $(shell find $(GO_DIRS) -name "*.go" -type f)
|
||||||
INTEGRATION_PACKAGES := xorm.io/xorm/integrations
|
INTEGRATION_PACKAGES := xorm.io/xorm/tests
|
||||||
PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
|
PACKAGES ?= $(filter-out $(INTEGRATION_PACKAGES),$(shell $(GO) list ./...))
|
||||||
|
|
||||||
TEST_COCKROACH_HOST ?= cockroach:26257
|
TEST_COCKROACH_HOST ?= cockroach:26257
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -28,7 +28,7 @@ func TestCacheFind(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(MailBox)))
|
assert.NoError(t, testEngine.Sync(new(MailBox)))
|
||||||
|
|
||||||
var inserts = []*MailBox{
|
inserts := []*MailBox{
|
||||||
{
|
{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
Username: "user1",
|
Username: "user1",
|
||||||
|
@ -105,7 +105,7 @@ func TestCacheFind2(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(MailBox2)))
|
assert.NoError(t, testEngine.Sync(new(MailBox2)))
|
||||||
|
|
||||||
var inserts = []*MailBox2{
|
inserts := []*MailBox2{
|
||||||
{
|
{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
Username: "user1",
|
Username: "user1",
|
||||||
|
@ -156,7 +156,7 @@ func TestCacheGet(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(MailBox3)))
|
assert.NoError(t, testEngine.Sync(new(MailBox3)))
|
||||||
|
|
||||||
var inserts = []*MailBox3{
|
inserts := []*MailBox3{
|
||||||
{
|
{
|
||||||
Username: "user1",
|
Username: "user1",
|
||||||
Password: "pass1",
|
Password: "pass1",
|
|
@ -5,7 +5,7 @@
|
||||||
//go:build dm
|
//go:build dm
|
||||||
// +build dm
|
// +build dm
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import "xorm.io/xorm/schemas"
|
import "xorm.io/xorm/schemas"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -23,7 +23,7 @@ func BenchmarkGetVars(b *testing.B) {
|
||||||
|
|
||||||
assert.NoError(b, testEngine.Sync(new(BenchmarkGetVars)))
|
assert.NoError(b, testEngine.Sync(new(BenchmarkGetVars)))
|
||||||
|
|
||||||
var v = BenchmarkGetVars{
|
v := BenchmarkGetVars{
|
||||||
Name: "myname",
|
Name: "myname",
|
||||||
}
|
}
|
||||||
_, err := testEngine.Insert(&v)
|
_, err := testEngine.Insert(&v)
|
||||||
|
@ -54,7 +54,7 @@ func BenchmarkGetStruct(b *testing.B) {
|
||||||
|
|
||||||
assert.NoError(b, testEngine.Sync(new(BenchmarkGetStruct)))
|
assert.NoError(b, testEngine.Sync(new(BenchmarkGetStruct)))
|
||||||
|
|
||||||
var v = BenchmarkGetStruct{
|
v := BenchmarkGetStruct{
|
||||||
Name: "myname",
|
Name: "myname",
|
||||||
}
|
}
|
||||||
_, err := testEngine.Insert(&v)
|
_, err := testEngine.Insert(&v)
|
||||||
|
@ -86,13 +86,13 @@ func BenchmarkFindStruct(b *testing.B) {
|
||||||
|
|
||||||
assert.NoError(b, testEngine.Sync(new(BenchmarkFindStruct)))
|
assert.NoError(b, testEngine.Sync(new(BenchmarkFindStruct)))
|
||||||
|
|
||||||
var v = BenchmarkFindStruct{
|
v := BenchmarkFindStruct{
|
||||||
Name: "myname",
|
Name: "myname",
|
||||||
}
|
}
|
||||||
_, err := testEngine.Insert(&v)
|
_, err := testEngine.Insert(&v)
|
||||||
assert.NoError(b, err)
|
assert.NoError(b, err)
|
||||||
|
|
||||||
var mynames = make([]BenchmarkFindStruct, 0, 1)
|
mynames := make([]BenchmarkFindStruct, 0, 1)
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
err := testEngine.Find(&mynames)
|
err := testEngine.Find(&mynames)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -200,7 +200,7 @@ func TestProcessors(t *testing.T) {
|
||||||
// --
|
// --
|
||||||
|
|
||||||
// test find map processors
|
// test find map processors
|
||||||
var p2FindMap = make(map[int64]*ProcessorsStruct)
|
p2FindMap := make(map[int64]*ProcessorsStruct)
|
||||||
err = testEngine.Find(&p2FindMap)
|
err = testEngine.Find(&p2FindMap)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -848,13 +848,13 @@ func TestAfterLoadProcessor(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(AfterLoadStructA), new(AfterLoadStructB))
|
assertSync(t, new(AfterLoadStructA), new(AfterLoadStructB))
|
||||||
|
|
||||||
var a = AfterLoadStructA{
|
a := AfterLoadStructA{
|
||||||
Content: "testa",
|
Content: "testa",
|
||||||
}
|
}
|
||||||
_, err := testEngine.Insert(&a)
|
_, err := testEngine.Insert(&a)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var b = AfterLoadStructB{
|
b := AfterLoadStructB{
|
||||||
Content: "testb",
|
Content: "testb",
|
||||||
AId: a.Id,
|
AId: a.Id,
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -22,7 +22,7 @@ func TestSetExpr(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(UserExprIssue)))
|
assert.NoError(t, testEngine.Sync(new(UserExprIssue)))
|
||||||
|
|
||||||
var issue = UserExprIssue{
|
issue := UserExprIssue{
|
||||||
Title: "my issue",
|
Title: "my issue",
|
||||||
}
|
}
|
||||||
cnt, err := testEngine.Insert(&issue)
|
cnt, err := testEngine.Insert(&issue)
|
||||||
|
@ -44,7 +44,7 @@ func TestSetExpr(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
|
||||||
var not = "NOT"
|
not := "NOT"
|
||||||
if testEngine.Dialect().URI().DBType == schemas.MSSQL || testEngine.Dialect().URI().DBType == schemas.DAMENG {
|
if testEngine.Dialect().URI().DBType == schemas.MSSQL || testEngine.Dialect().URI().DBType == schemas.DAMENG {
|
||||||
not = "~"
|
not = "~"
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ func TestMustCol(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(CustomerUpdate))
|
assertSync(t, new(CustomerUpdate))
|
||||||
|
|
||||||
var customer = CustomerUpdate{
|
customer := CustomerUpdate{
|
||||||
ParentId: 1,
|
ParentId: 1,
|
||||||
}
|
}
|
||||||
cnt, err := testEngine.Insert(&customer)
|
cnt, err := testEngine.Insert(&customer)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -37,7 +37,7 @@ func TestBuilder(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var cond Condition
|
var cond Condition
|
||||||
var q = testEngine.Quote
|
q := testEngine.Quote
|
||||||
has, err := testEngine.Where(builder.Eq{q("col_name"): "col1"}).Get(&cond)
|
has, err := testEngine.Where(builder.Eq{q("col_name"): "col1"}).Get(&cond)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, true, has, "records should exist")
|
assert.Equal(t, true, has, "records should exist")
|
||||||
|
@ -90,7 +90,7 @@ func TestBuilder(t *testing.T) {
|
||||||
assert.EqualValues(t, 0, len(conds), "records should not exist")
|
assert.EqualValues(t, 0, len(conds), "records should not exist")
|
||||||
|
|
||||||
// complex condtions
|
// complex condtions
|
||||||
var where = builder.NewCond()
|
where := builder.NewCond()
|
||||||
if true {
|
if true {
|
||||||
where = where.And(builder.Eq{q("col_name"): "col1"})
|
where = where.And(builder.Eq{q("col_name"): "col1"})
|
||||||
where = where.Or(builder.And(builder.In(q("col_name"), "col1", "col2"), builder.Expr(q("col_name")+" = ?", "col1")))
|
where = where.Or(builder.And(builder.In(q("col_name"), "col1", "col2"), builder.Expr(q("col_name")+" = ?", "col1")))
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -106,14 +106,14 @@ func TestExistStructForJoin(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
|
||||||
var orderlist = OrderList{
|
orderlist := OrderList{
|
||||||
Eid: ply.Id,
|
Eid: ply.Id,
|
||||||
}
|
}
|
||||||
cnt, err = testEngine.Insert(&orderlist)
|
cnt, err = testEngine.Insert(&orderlist)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
|
||||||
var um = Number{
|
um := Number{
|
||||||
Lid: orderlist.Id,
|
Lid: orderlist.Id,
|
||||||
}
|
}
|
||||||
cnt, err = testEngine.Insert(&um)
|
cnt, err = testEngine.Insert(&um)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -142,8 +142,13 @@ func TestInsert(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
assertSync(t, new(Userinfo))
|
assertSync(t, new(Userinfo))
|
||||||
|
|
||||||
user := Userinfo{0, "xiaolunwen", "dev", "lunny", time.Now(),
|
user := Userinfo{
|
||||||
Userdetail{Id: 1}, 1.78, []byte{1, 2, 3}, true}
|
0, "xiaolunwen", "dev", "lunny", time.Now(),
|
||||||
|
Userdetail{Id: 1},
|
||||||
|
1.78,
|
||||||
|
[]byte{1, 2, 3},
|
||||||
|
true,
|
||||||
|
}
|
||||||
cnt, err := testEngine.Insert(&user)
|
cnt, err := testEngine.Insert(&user)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt, "insert not returned 1")
|
assert.EqualValues(t, 1, cnt, "insert not returned 1")
|
||||||
|
@ -161,8 +166,10 @@ func TestInsertAutoIncr(t *testing.T) {
|
||||||
assertSync(t, new(Userinfo))
|
assertSync(t, new(Userinfo))
|
||||||
|
|
||||||
// auto increment insert
|
// auto increment insert
|
||||||
user := Userinfo{Username: "xiaolunwen2", Departname: "dev", Alias: "lunny", Created: time.Now(),
|
user := Userinfo{
|
||||||
Detail: Userdetail{Id: 1}, Height: 1.78, Avatar: []byte{1, 2, 3}, IsMan: true}
|
Username: "xiaolunwen2", Departname: "dev", Alias: "lunny", Created: time.Now(),
|
||||||
|
Detail: Userdetail{Id: 1}, Height: 1.78, Avatar: []byte{1, 2, 3}, IsMan: true,
|
||||||
|
}
|
||||||
cnt, err := testEngine.Insert(&user)
|
cnt, err := testEngine.Insert(&user)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
@ -184,7 +191,7 @@ func TestInsertDefault(t *testing.T) {
|
||||||
err := testEngine.Sync(di)
|
err := testEngine.Sync(di)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var di2 = DefaultInsert{Name: "test"}
|
di2 := DefaultInsert{Name: "test"}
|
||||||
_, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("Status")).Insert(&di2)
|
_, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("Status")).Insert(&di2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -210,7 +217,7 @@ func TestInsertDefault2(t *testing.T) {
|
||||||
err := testEngine.Sync(di)
|
err := testEngine.Sync(di)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var di2 = DefaultInsert2{Name: "test"}
|
di2 := DefaultInsert2{Name: "test"}
|
||||||
_, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("CheckTime")).Insert(&di2)
|
_, err = testEngine.Omit(testEngine.GetColumnMapper().Obj2Table("CheckTime")).Insert(&di2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -438,7 +445,7 @@ func TestCreatedJsonTime(t *testing.T) {
|
||||||
assert.True(t, has)
|
assert.True(t, has)
|
||||||
assert.EqualValues(t, time.Time(ci5.Created).Unix(), time.Time(di5.Created).Unix())
|
assert.EqualValues(t, time.Time(ci5.Created).Unix(), time.Time(di5.Created).Unix())
|
||||||
|
|
||||||
var dis = make([]MyJSONTime, 0)
|
dis := make([]MyJSONTime, 0)
|
||||||
err = testEngine.Find(&dis)
|
err = testEngine.Find(&dis)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -762,7 +769,7 @@ func TestInsertWhere(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
assertSync(t, new(InsertWhere))
|
assertSync(t, new(InsertWhere))
|
||||||
|
|
||||||
var i = InsertWhere{
|
i := InsertWhere{
|
||||||
RepoId: 1,
|
RepoId: 1,
|
||||||
Width: 10,
|
Width: 10,
|
||||||
Height: 20,
|
Height: 20,
|
||||||
|
@ -872,7 +879,7 @@ func TestInsertExpr2(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(InsertExprsRelease))
|
assertSync(t, new(InsertExprsRelease))
|
||||||
|
|
||||||
var ie = InsertExprsRelease{
|
ie := InsertExprsRelease{
|
||||||
RepoId: 1,
|
RepoId: 1,
|
||||||
IsTag: true,
|
IsTag: true,
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1054,7 @@ func TestInsertIntSlice(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(InsertIntSlice)))
|
assert.NoError(t, testEngine.Sync(new(InsertIntSlice)))
|
||||||
|
|
||||||
var v = InsertIntSlice{
|
v := InsertIntSlice{
|
||||||
NameIDs: []int{1, 2},
|
NameIDs: []int{1, 2},
|
||||||
}
|
}
|
||||||
cnt, err := testEngine.Insert(&v)
|
cnt, err := testEngine.Insert(&v)
|
||||||
|
@ -1064,7 +1071,7 @@ func TestInsertIntSlice(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
|
||||||
var v3 = InsertIntSlice{
|
v3 := InsertIntSlice{
|
||||||
NameIDs: nil,
|
NameIDs: nil,
|
||||||
}
|
}
|
||||||
cnt, err = testEngine.Insert(&v3)
|
cnt, err = testEngine.Insert(&v3)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -59,7 +59,7 @@ func TestBufferIterate(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(UserBufferIterate)))
|
assert.NoError(t, testEngine.Sync(new(UserBufferIterate)))
|
||||||
|
|
||||||
var size = 20
|
size := 20
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
cnt, err := testEngine.Insert(&UserBufferIterate{
|
cnt, err := testEngine.Insert(&UserBufferIterate{
|
||||||
IsMan: true,
|
IsMan: true,
|
||||||
|
@ -68,7 +68,7 @@ func TestBufferIterate(t *testing.T) {
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cnt = 0
|
cnt := 0
|
||||||
err := testEngine.BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
err := testEngine.BufferSize(9).Iterate(new(UserBufferIterate), func(i int, bean interface{}) error {
|
||||||
user := bean.(*UserBufferIterate)
|
user := bean.(*UserBufferIterate)
|
||||||
assert.EqualValues(t, cnt+1, user.Id)
|
assert.EqualValues(t, cnt+1, user.Id)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -53,17 +53,21 @@ type StringPK struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ID int64
|
type (
|
||||||
type MyIntPK struct {
|
ID int64
|
||||||
|
MyIntPK struct {
|
||||||
ID ID `xorm:"pk autoincr"`
|
ID ID `xorm:"pk autoincr"`
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type StrID string
|
type (
|
||||||
type MyStringPK struct {
|
StrID string
|
||||||
|
MyStringPK struct {
|
||||||
ID StrID `xorm:"pk notnull"`
|
ID StrID `xorm:"pk notnull"`
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func TestIntId(t *testing.T) {
|
func TestIntId(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
|
@ -187,7 +191,7 @@ func TestUintId(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
|
||||||
var inserts = []UintId{
|
inserts := []UintId{
|
||||||
{Name: "test1"},
|
{Name: "test1"},
|
||||||
{Name: "test2"},
|
{Name: "test2"},
|
||||||
}
|
}
|
||||||
|
@ -390,7 +394,7 @@ func TestCompositeKey(t *testing.T) {
|
||||||
assert.True(t, has)
|
assert.True(t, has)
|
||||||
assert.EqualValues(t, compositeKeyVal, compositeKeyVal2)
|
assert.EqualValues(t, compositeKeyVal, compositeKeyVal2)
|
||||||
|
|
||||||
var cps = make([]CompositeKey, 0)
|
cps := make([]CompositeKey, 0)
|
||||||
err = testEngine.Find(&cps)
|
err = testEngine.Find(&cps)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, len(cps))
|
assert.EqualValues(t, 1, len(cps))
|
||||||
|
@ -460,13 +464,15 @@ func TestCompositeKey2(t *testing.T) {
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MyString string
|
type (
|
||||||
type UserPK2 struct {
|
MyString string
|
||||||
|
UserPK2 struct {
|
||||||
UserId MyString `xorm:"varchar(19) not null pk"`
|
UserId MyString `xorm:"varchar(19) not null pk"`
|
||||||
NickName string `xorm:"varchar(19) not null"`
|
NickName string `xorm:"varchar(19) not null"`
|
||||||
GameId uint32 `xorm:"integer pk"`
|
GameId uint32 `xorm:"integer pk"`
|
||||||
Score int32 `xorm:"integer"`
|
Score int32 `xorm:"integer"`
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func TestCompositeKey3(t *testing.T) {
|
func TestCompositeKey3(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -25,13 +25,11 @@ func TestSum(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
assert.NoError(t, testEngine.Sync(new(SumStruct)))
|
assert.NoError(t, testEngine.Sync(new(SumStruct)))
|
||||||
|
|
||||||
var (
|
cases := []SumStruct{
|
||||||
cases = []SumStruct{
|
|
||||||
{1, 6.2},
|
{1, 6.2},
|
||||||
{2, 5.3},
|
{2, 5.3},
|
||||||
{92, -0.2},
|
{92, -0.2},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
var f float32
|
var f float32
|
||||||
|
@ -84,13 +82,11 @@ func TestSumWithTableName(t *testing.T) {
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
assert.NoError(t, testEngine.Sync(new(SumStructWithTableName)))
|
assert.NoError(t, testEngine.Sync(new(SumStructWithTableName)))
|
||||||
|
|
||||||
var (
|
cases := []SumStructWithTableName{
|
||||||
cases = []SumStructWithTableName{
|
|
||||||
{1, 6.2},
|
{1, 6.2},
|
||||||
{2, 5.3},
|
{2, 5.3},
|
||||||
{92, -0.2},
|
{92, -0.2},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
var i int
|
var i int
|
||||||
var f float32
|
var f float32
|
||||||
|
@ -138,13 +134,11 @@ func TestSumCustomColumn(t *testing.T) {
|
||||||
Float float32
|
Float float32
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
cases := []SumStruct2{
|
||||||
cases = []SumStruct2{
|
|
||||||
{1, 6.2},
|
{1, 6.2},
|
||||||
{2, 5.3},
|
{2, 5.3},
|
||||||
{92, -0.2},
|
{92, -0.2},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
assert.NoError(t, testEngine.Sync(new(SumStruct2)))
|
assert.NoError(t, testEngine.Sync(new(SumStruct2)))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -187,7 +187,6 @@ func TestMultipleTransaction(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsertMulti2InterfaceTransaction(t *testing.T) {
|
func TestInsertMulti2InterfaceTransaction(t *testing.T) {
|
||||||
|
|
||||||
type Multi2InterfaceTransaction struct {
|
type Multi2InterfaceTransaction struct {
|
||||||
ID uint64 `xorm:"id pk autoincr"`
|
ID uint64 `xorm:"id pk autoincr"`
|
||||||
Name string
|
Name string
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
@ -162,7 +162,7 @@ func createEngine(dbType, connStr string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var tableNames = make([]interface{}, 0, len(tables))
|
tableNames := make([]interface{}, 0, len(tables))
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
tableNames = append(tableNames, table.Name)
|
tableNames = append(tableNames, table.Name)
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"xorm.io/xorm/convert"
|
"xorm.io/xorm/convert"
|
||||||
|
|
||||||
"xorm.io/xorm/internal/utils"
|
"xorm.io/xorm/internal/utils"
|
||||||
|
@ -18,7 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func formatTime(t time.Time, scales ...int) string {
|
func formatTime(t time.Time, scales ...int) string {
|
||||||
var layout = "2006-01-02 15:04:05"
|
layout := "2006-01-02 15:04:05"
|
||||||
if len(scales) > 0 && scales[0] > 0 {
|
if len(scales) > 0 && scales[0] > 0 {
|
||||||
layout += "." + strings.Repeat("0", scales[0])
|
layout += "." + strings.Repeat("0", scales[0])
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ func TestTimeUserTime(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(TimeUser))
|
assertSync(t, new(TimeUser))
|
||||||
|
|
||||||
var user = TimeUser{
|
user := TimeUser{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
OperTime: time.Now(),
|
OperTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,7 @@ func TestTimeUserTimeDiffLoc(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(TimeUser2))
|
assertSync(t, new(TimeUser2))
|
||||||
|
|
||||||
var user = TimeUser2{
|
user := TimeUser2{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
OperTime: time.Now(),
|
OperTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
@ -110,7 +111,7 @@ func TestTimeUserCreated(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserCreated))
|
assertSync(t, new(UserCreated))
|
||||||
|
|
||||||
var user = UserCreated{
|
user := UserCreated{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@ func TestTimeUserCreatedDiffLoc(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserCreated2))
|
assertSync(t, new(UserCreated2))
|
||||||
|
|
||||||
var user = UserCreated2{
|
user := UserCreated2{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +185,7 @@ func TestTimeUserUpdated(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserUpdated))
|
assertSync(t, new(UserUpdated))
|
||||||
|
|
||||||
var user = UserUpdated{
|
user := UserUpdated{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +205,7 @@ func TestTimeUserUpdated(t *testing.T) {
|
||||||
assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt))
|
assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt))
|
||||||
fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt)
|
fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt)
|
||||||
|
|
||||||
var user3 = UserUpdated{
|
user3 := UserUpdated{
|
||||||
Id: "lunny2",
|
Id: "lunny2",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +251,7 @@ func TestTimeUserUpdatedDiffLoc(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserUpdated2))
|
assertSync(t, new(UserUpdated2))
|
||||||
|
|
||||||
var user = UserUpdated2{
|
user := UserUpdated2{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +271,7 @@ func TestTimeUserUpdatedDiffLoc(t *testing.T) {
|
||||||
assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt))
|
assert.EqualValues(t, formatTime(user.UpdatedAt), formatTime(user2.UpdatedAt))
|
||||||
fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt)
|
fmt.Println("user2", user2.CreatedAt, user2.UpdatedAt)
|
||||||
|
|
||||||
var user3 = UserUpdated2{
|
user3 := UserUpdated2{
|
||||||
Id: "lunny2",
|
Id: "lunny2",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +305,7 @@ func TestTimeUserDeleted(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserDeleted))
|
assertSync(t, new(UserDeleted))
|
||||||
|
|
||||||
var user = UserDeleted{
|
user := UserDeleted{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +368,7 @@ func TestTimeUserDeletedDiffLoc(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserDeleted2))
|
assertSync(t, new(UserDeleted2))
|
||||||
|
|
||||||
var user = UserDeleted2{
|
user := UserDeleted2{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +413,7 @@ func (j JSONDate) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JSONDate) UnmarshalJSON(value []byte) error {
|
func (j *JSONDate) UnmarshalJSON(value []byte) error {
|
||||||
var v = strings.TrimSpace(strings.Trim(string(value), "\""))
|
v := strings.TrimSpace(strings.Trim(string(value), "\""))
|
||||||
|
|
||||||
t, err := time.ParseInLocation("2006-01-02 15:04:05", v, time.Local)
|
t, err := time.ParseInLocation("2006-01-02 15:04:05", v, time.Local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -438,7 +439,7 @@ func TestCustomTimeUserDeleted(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserDeleted3))
|
assertSync(t, new(UserDeleted3))
|
||||||
|
|
||||||
var user = UserDeleted3{
|
user := UserDeleted3{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +501,7 @@ func TestCustomTimeUserDeletedDiffLoc(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(UserDeleted4))
|
assertSync(t, new(UserDeleted4))
|
||||||
|
|
||||||
var user = UserDeleted4{
|
user := UserDeleted4{
|
||||||
Id: "lunny",
|
Id: "lunny",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,7 +584,7 @@ func TestTimestamp(t *testing.T) {
|
||||||
|
|
||||||
assertSync(t, new(TimestampStruct))
|
assertSync(t, new(TimestampStruct))
|
||||||
|
|
||||||
var d1 = TimestampStruct{
|
d1 := TimestampStruct{
|
||||||
InsertTime: time.Now(),
|
InsertTime: time.Now(),
|
||||||
}
|
}
|
||||||
cnt, err := testEngine.Insert(&d1)
|
cnt, err := testEngine.Insert(&d1)
|
||||||
|
@ -625,10 +626,10 @@ func TestTimestamp(t *testing.T) {
|
||||||
func TestString2Time(t *testing.T) {
|
func TestString2Time(t *testing.T) {
|
||||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
var timeTmp1 = time.Date(2023, 7, 14, 11, 30, 0, 0, loc)
|
timeTmp1 := time.Date(2023, 7, 14, 11, 30, 0, 0, loc)
|
||||||
var timeTmp2 = time.Date(2023, 7, 14, 0, 0, 0, 0, loc)
|
timeTmp2 := time.Date(2023, 7, 14, 0, 0, 0, 0, loc)
|
||||||
var time1StampStr = strconv.FormatInt(timeTmp1.Unix(), 10)
|
time1StampStr := strconv.FormatInt(timeTmp1.Unix(), 10)
|
||||||
var timeStr = "0000-00-00 00:00:00"
|
timeStr := "0000-00-00 00:00:00"
|
||||||
dt, err := convert.String2Time(timeStr, time.Local, time.Local)
|
dt, err := convert.String2Time(timeStr, time.Local, time.Local)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, dt.Nanosecond() == 0)
|
assert.True(t, dt.Nanosecond() == 0)
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package integrations
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
Loading…
Reference in New Issue