This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
testVersion.go
125 lines (109 loc) · 2.03 KB
/
testVersion.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package tests
import (
"errors"
"fmt"
"testing"
"time"
"github.com/go-xorm/xorm"
)
type VersionS struct {
Id int64
Name string
Ver int `xorm:"version"`
Created time.Time `xorm:"created"`
}
func testVersion(engine *xorm.Engine, t *testing.T) {
testVersion1(engine, t)
testVersion2(engine, t)
}
func testVersion1(engine *xorm.Engine, t *testing.T) {
err := engine.DropTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
err = engine.CreateTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
ver := &VersionS{Name: "sfsfdsfds"}
_, err = engine.Insert(ver)
if err != nil {
t.Error(err)
panic(err)
}
fmt.Println(ver)
if ver.Ver != 1 {
err = errors.New("insert error")
t.Error(err)
panic(err)
}
newVer := new(VersionS)
has, err := engine.Id(ver.Id).Get(newVer)
if err != nil {
t.Error(err)
panic(err)
}
if !has {
t.Error(errors.New(fmt.Sprintf("no version id is %v", ver.Id)))
panic(err)
}
fmt.Println(newVer)
if newVer.Ver != 1 {
err = errors.New("insert error")
t.Error(err)
panic(err)
}
newVer.Name = "-------"
_, err = engine.Id(ver.Id).Update(newVer)
if err != nil {
t.Error(err)
panic(err)
}
if newVer.Ver != 2 {
err = errors.New("update should set version back to struct")
t.Error(err)
}
newVer = new(VersionS)
has, err = engine.Id(ver.Id).Get(newVer)
if err != nil {
t.Error(err)
panic(err)
}
fmt.Println(newVer)
if newVer.Ver != 2 {
err = errors.New("insert error")
t.Error(err)
panic(err)
}
}
func testVersion2(engine *xorm.Engine, t *testing.T) {
err := engine.DropTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
err = engine.CreateTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
var vers = []VersionS{
{Name: "sfsfdsfds"},
{Name: "xxxxx"},
}
_, err = engine.Insert(vers)
if err != nil {
t.Error(err)
panic(err)
}
fmt.Println(vers)
for _, v := range vers {
if v.Ver != 1 {
err := errors.New("version should be 1")
t.Error(err)
panic(err)
}
}
}