-
Notifications
You must be signed in to change notification settings - Fork 0
/
argument_test.go
103 lines (83 loc) · 2.41 KB
/
argument_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
package boltutil
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCondition(t *testing.T) {
t.Run("ignoreIfExist Put", func(t *testing.T) {
db := testDB(t, true)
defer db.Close()
person := &Person{
Id: "id1",
Name: "name1",
}
assert.NoError(t, db.Put(person))
person.Name = "name2"
assert.NoError(t, db.Put(person, NewCondition().IgnoreIfExist(true)))
require.NoError(t, db.Get(person))
assert.Equal(t, "name1", person.Name)
person.Name = "name3"
assert.NoError(t, db.Put(person))
require.NoError(t, db.Get(person))
assert.Equal(t, "name3", person.Name)
person.Name = "name4"
assert.NoError(t, db.Put(person, NewCondition().IgnoreIfExist(false)))
require.NoError(t, db.Get(person))
assert.Equal(t, "name4", person.Name)
})
t.Run("failIfExist Put", func(t *testing.T) {
db := testDB(t, true)
defer db.Close()
person := &Person{
Id: "id1",
Name: "name1",
}
assert.NoError(t, db.Put(person))
person.Name = "name2"
assert.Error(t, db.Put(person, NewCondition().FailIfExist(true)))
require.NoError(t, db.Get(person))
assert.Equal(t, "name1", person.Name)
person.Name = "name3"
assert.NoError(t, db.Put(person))
require.NoError(t, db.Get(person))
assert.Equal(t, "name3", person.Name)
person.Name = "name4"
assert.NoError(t, db.Put(person, NewCondition().FailIfExist(false)))
require.NoError(t, db.Get(person))
assert.Equal(t, "name4", person.Name)
})
t.Run("ignoreIfNotExist Get", func(t *testing.T) {
db := testDB(t, true)
defer db.Close()
person := &Person{
Id: "id1",
Name: "name1",
}
assert.NoError(t, db.Get(person, NewCondition().IgnoreIfNotExist(true)))
assert.Error(t, db.Get(person))
assert.Error(t, db.Get(person, NewCondition().IgnoreIfNotExist(false)))
})
t.Run("failIfNotExist Put", func(t *testing.T) {
db := testDB(t, true)
defer db.Close()
person := &Person{
Id: "id1",
Name: "name1",
}
assert.Error(t, db.Put(person, NewCondition().FailIfNotExist(true)))
require.Error(t, db.Get(person))
assert.NoError(t, db.Put(person))
require.NoError(t, db.Get(person))
})
t.Run("failIfNotExist Delete", func(t *testing.T) {
db := testDB(t, true)
defer db.Close()
person := &Person{
Id: "id1",
Name: "name1",
}
assert.Error(t, db.Delete(person, NewCondition().FailIfNotExist(true)))
assert.NoError(t, db.Delete(person))
})
}