This repository was archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtestID.go
More file actions
74 lines (60 loc) · 1.38 KB
/
testID.go
File metadata and controls
74 lines (60 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tests
import (
"testing"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
)
type IDGonicMapper struct {
ID int64
}
func testID(engine *xorm.Engine, t *testing.T) {
testGonicMapperID(engine, t)
testSameMapperID(engine, t)
}
func testGonicMapperID(engine *xorm.Engine, t *testing.T) {
oldMapper := engine.ColumnMapper
engine.SetMapper(core.LintGonicMapper)
defer engine.SetMapper(oldMapper)
err := engine.CreateTables(new(IDGonicMapper))
if err != nil {
t.Fatal(err)
}
tables, err := engine.DBMetas()
if err != nil {
t.Fatal(err)
}
for _, tb := range tables {
if tb.Name == "id_gonic_mapper" {
if len(tb.PKColumns()) != 1 && !tb.PKColumns()[0].IsPrimaryKey && !tb.PKColumns()[0].IsPrimaryKey {
t.Fatal(tb)
}
return
}
}
t.Fatal("not table id_gonic_mapper")
}
type IDSameMapper struct {
ID int64
}
func testSameMapperID(engine *xorm.Engine, t *testing.T) {
oldMapper := engine.ColumnMapper
engine.SetMapper(core.SameMapper{})
defer engine.SetMapper(oldMapper)
err := engine.CreateTables(new(IDSameMapper))
if err != nil {
t.Fatal(err)
}
tables, err := engine.DBMetas()
if err != nil {
t.Fatal(err)
}
for _, tb := range tables {
if tb.Name == "IDSameMapper" {
if len(tb.PKColumns()) != 1 && !tb.PKColumns()[0].IsPrimaryKey && !tb.PKColumns()[0].IsPrimaryKey {
t.Fatal(tb)
}
return
}
}
t.Fatal("not table IDSameMapper")
}