forked from xormplus/xorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_exist_test.go
76 lines (58 loc) · 1.82 KB
/
session_exist_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
// 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 (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExistStruct(t *testing.T) {
assert.NoError(t, prepareEngine())
type RecordExist struct {
Id int64
Name string
}
assertSync(t, new(RecordExist))
has, err := testEngine.Exist(new(RecordExist))
assert.NoError(t, err)
assert.False(t, has)
cnt, err := testEngine.Insert(&RecordExist{
Name: "test1",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
has, err = testEngine.Exist(new(RecordExist))
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.Exist(&RecordExist{
Name: "test1",
})
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.Exist(&RecordExist{
Name: "test2",
})
assert.NoError(t, err)
assert.False(t, has)
has, err = testEngine.Where("name = ?", "test1").Exist(&RecordExist{})
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.Where("name = ?", "test2").Exist(&RecordExist{})
assert.NoError(t, err)
assert.False(t, has)
has, err = testEngine.SQL("select * from "+testEngine.TableName("record_exist", true)+" where name = ?", "test1").Exist()
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.SQL("select * from "+testEngine.TableName("record_exist", true)+" where name = ?", "test2").Exist()
assert.NoError(t, err)
assert.False(t, has)
has, err = testEngine.Table("record_exist").Exist()
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.Table("record_exist").Where("name = ?", "test1").Exist()
assert.NoError(t, err)
assert.True(t, has)
has, err = testEngine.Table("record_exist").Where("name = ?", "test2").Exist()
assert.NoError(t, err)
assert.False(t, has)
}