-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalidate_exclusion_test.go
57 lines (48 loc) · 1.02 KB
/
validate_exclusion_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
package changeset
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidateExclusion(t *testing.T) {
tests := []interface{}{
2,
3.0,
"d",
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%T", tt), func(t *testing.T) {
ch := &Changeset{
changes: map[string]interface{}{
"field": tt,
},
}
ValidateExclusion(ch, "field", []interface{}{1, 2.0, "c"})
assert.Nil(t, ch.Errors())
})
}
}
func TestValidateExclusion_error(t *testing.T) {
tests := []interface{}{
1,
2.0,
"c",
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%T", tt), func(t *testing.T) {
ch := &Changeset{
changes: map[string]interface{}{
"field": tt,
},
}
ValidateExclusion(ch, "field", []interface{}{1, 2.0, "c"})
assert.NotNil(t, ch.Errors())
assert.Equal(t, "field must not be any of [1 2 c]", ch.Error().Error())
})
}
}
func TestValidateExclusion_missing(t *testing.T) {
ch := &Changeset{}
ValidateExclusion(ch, "field", []interface{}{5})
assert.Nil(t, ch.Errors())
}