-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_test.go
88 lines (66 loc) · 1.3 KB
/
update_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
package grocery
import (
"testing"
"time"
)
type UpdateTestModel struct {
Base
StringVal string
TimeVal time.Time
}
func TestSetZeroValues(t *testing.T) {
m := &UpdateTestModel{
StringVal: "asdf",
}
id, err := Store(m)
if err != nil {
t.Error(err)
}
// Check 0
model := new(UpdateTestModel)
err = Load(id, model)
if err != nil {
t.Error(err)
}
if model.StringVal != m.StringVal {
t.Errorf("TestSetZeroValues FAILED, initial value was not set correctly")
}
// Update 1
m.StringVal = ""
err = Update(id, m)
if err != nil {
t.Error(err)
}
// Check 1
Load(id, model)
if model.StringVal == "" {
t.Errorf("TestSetZeroValues FAILED, zero value was set")
}
// Update 2
m.StringVal = ""
UpdateWithOptions(id, m, &UpdateOptions{
SetZeroValues: true,
})
// Check 2
Load(id, model)
if model.StringVal != "" {
t.Errorf("TestSetZeroValues FAILED, zero value was not set")
}
}
func TestSetTimeValue(t *testing.T) {
m := &UpdateTestModel{
TimeVal: time.Now(),
}
id, err := Store(m)
if err != nil {
t.Error(err)
}
model := new(UpdateTestModel)
err = Load(id, model)
if err != nil {
t.Error(err)
}
if m.TimeVal.Before(model.TimeVal) || m.TimeVal.Sub(model.TimeVal) > time.Second {
t.Errorf("TestSetTimeValue FAILED, initial value was not set correctly")
}
}