-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators_test.go
More file actions
59 lines (57 loc) · 1.42 KB
/
validators_test.go
File metadata and controls
59 lines (57 loc) · 1.42 KB
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
package stable
import (
"errors"
"testing"
)
func TestValidator_IsValid(t *testing.T) {
t.Parallel()
validationField := "testField"
type testTableData struct {
testCase string
validator validator
rows []map[string]string
expectedErr error
}
testTable := []testTableData{
{
testCase: "valueEmptyValidator pass",
validator: newValueEmptyValidator(validationField),
rows: []map[string]string{
{validationField: "1"},
{validationField: "2"},
},
expectedErr: nil,
},
{
testCase: "valueEmptyValidator error",
validator: newValueEmptyValidator(validationField),
rows: []map[string]string{
{validationField: "1"},
{validationField: ""},
},
expectedErr: errors.New("empty value for field \"testField\""),
},
{
testCase: "valueDuplicatesValidator pass",
validator: newValueDuplicatesValidator(validationField),
rows: []map[string]string{
{validationField: "1"},
{validationField: "2"},
},
expectedErr: nil,
},
{
testCase: "valueDuplicatesValidator error",
validator: newValueDuplicatesValidator(validationField),
rows: []map[string]string{
{validationField: "1"},
{validationField: "1"},
},
expectedErr: errors.New("duplicate value \"1\" for field \"testField\""),
},
}
for _, testUnit := range testTable {
err := testUnit.validator.isValid(testUnit.rows)
equal(t, testUnit.expectedErr, err, testUnit.testCase)
}
}