-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvalidate_pattern_test.go
More file actions
48 lines (40 loc) · 853 Bytes
/
validate_pattern_test.go
File metadata and controls
48 lines (40 loc) · 853 Bytes
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
package changeset
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidatePattern(t *testing.T) {
tests := []interface{}{
"seafood",
1,
2.0,
false,
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%T", tt), func(t *testing.T) {
ch := &Changeset{
changes: map[string]interface{}{
"field": tt,
},
}
ValidatePattern(ch, "field", "foo.*")
assert.Nil(t, ch.Errors())
})
}
}
func TestValidatePattern_error(t *testing.T) {
ch := &Changeset{
changes: map[string]interface{}{
"field": "seafood",
},
}
ValidatePattern(ch, "field", "boo.*")
assert.NotNil(t, ch.Errors())
assert.Equal(t, "field's format is invalid", ch.Error().Error())
}
func TestValidatePattern_missing(t *testing.T) {
ch := &Changeset{}
ValidatePattern(ch, "field", "foo.*")
assert.Nil(t, ch.Errors())
}