forked from wshops/wgm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater_test.go
86 lines (71 loc) · 1.71 KB
/
updater_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
package wgm_test
import (
"github.com/oeasenet/wgm"
"github.com/stretchr/testify/require"
"testing"
)
func TestGetUpdater(t *testing.T) {
doc := Doc{}
u := wgm.MustUpdater(doc)
require.NotNil(t, u)
}
func TestUpdater_Find(t *testing.T) {
DBdoc := NewDoc("Alice", 12)
SetupDefaultConnection()
objectID := InsertDoc(DBdoc)
defer DelDoc(DBdoc)
doc := &Doc{}
doc.Id = objectID
u, hasResult := wgm.MustUpdater(doc).Find()
require.True(t, hasResult)
require.NotNil(t, u)
require.Equal(t, doc.Age, DBdoc.Age)
require.Equal(t, doc.Name, DBdoc.Name)
}
func TestUpdater_Update(t *testing.T) {
DBdoc := NewDoc("Alice", 12)
SetupDefaultConnection()
objectID := InsertDoc(DBdoc)
defer DelDoc(DBdoc)
doc := &Doc{}
doc.Id = objectID
u, _ := wgm.MustUpdater(doc).Find()
doc.Name = "dada"
doc.Age = 99
err := u.Update()
require.Nil(t, err)
DBdoc = &Doc{}
wgm.FindOne(DBdoc, nil)
require.Equal(t, DBdoc.Age, 99)
require.Equal(t, DBdoc.Name, "dada")
}
func BenchmarkUpdater_Find(b *testing.B) {
DBdoc := NewDoc("Alice", 12)
SetupDefaultConnection()
objectID := InsertDoc(DBdoc)
defer DelDoc(DBdoc)
doc := &Doc{}
doc.Id = objectID
u, hasResult := wgm.MustUpdater(doc).Find()
require.True(b, hasResult)
require.NotNil(b, u)
require.Equal(b, doc.Age, DBdoc.Age)
require.Equal(b, doc.Name, DBdoc.Name)
}
func BenchmarkUpdater_Update(b *testing.B) {
DBdoc := NewDoc("Alice", 12)
SetupDefaultConnection()
objectID := InsertDoc(DBdoc)
defer DelDoc(DBdoc)
doc := &Doc{}
doc.Id = objectID
u, _ := wgm.MustUpdater(doc).Find()
doc.Name = "dada"
doc.Age = 99
err := u.Update()
require.Nil(b, err)
DBdoc = &Doc{}
wgm.FindOne(DBdoc, nil)
require.Equal(b, DBdoc.Age, 99)
require.Equal(b, DBdoc.Name, "dada")
}