forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_version_test.go
128 lines (110 loc) · 2.16 KB
/
tag_version_test.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
126
127
128
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
"errors"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type VersionS struct {
Id int64
Name string
Ver int `xorm:"version"`
Created time.Time `xorm:"created"`
}
func TestVersion1(t *testing.T) {
assert.NoError(t, prepareEngine())
err := testEngine.DropTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
err = testEngine.CreateTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
ver := &VersionS{Name: "sfsfdsfds"}
_, err = testEngine.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 := testEngine.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 = testEngine.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 = testEngine.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(t *testing.T) {
assert.NoError(t, prepareEngine())
err := testEngine.DropTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
err = testEngine.CreateTables(new(VersionS))
if err != nil {
t.Error(err)
panic(err)
}
var vers = []VersionS{
{Name: "sfsfdsfds"},
{Name: "xxxxx"},
}
_, err = testEngine.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)
}
}
}