-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchange_test.go
40 lines (33 loc) · 886 Bytes
/
change_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
package changeset
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChange(t *testing.T) {
var data struct {
FIELD1 int `db:"field1"`
Field2 string
Field3 bool
}
expectedValues := map[string]interface{}{
"field1": 0,
"field2": "",
"field3": false,
}
expectedTypes := map[string]reflect.Type{
"field1": reflect.TypeOf(0),
"field2": reflect.TypeOf(""),
"field3": reflect.TypeOf(false),
}
ch := Change(data)
assert.Nil(t, ch.Errors())
assert.Equal(t, expectedValues, ch.Values())
assert.Equal(t, expectedTypes, ch.Types())
assert.Equal(t, map[string]interface{}{}, ch.Changes())
ch = Change(data, map[string]interface{}{"field1": 2})
assert.Nil(t, ch.Errors())
assert.Equal(t, expectedValues, ch.Values())
assert.Equal(t, expectedTypes, ch.Types())
assert.Equal(t, map[string]interface{}{"field1": 2}, ch.Changes())
}