-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_test.go
66 lines (60 loc) · 1.51 KB
/
validate_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
package ttypes
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestWithRequire tests the WithRequire function.
func TestValidate_WithError(t *testing.T) {
tests := map[string]struct {
validate Validate
withError error
expectedErr error
}{
"WithError returns correct validate value with no error": {
validate: validateWErr,
withError: nil,
expectedErr: nil,
},
"WithError returns correct validate value with error": {
validate: validateWErr,
withError: errTest2,
expectedErr: errTest2,
},
"WithError returns no error withError": {
validate: validateWNil,
withError: errTest2,
expectedErr: nil,
},
}
for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
validateFn := testCase.validate.WithError(testCase.expectedErr)
assert.Equal(t, testCase.expectedErr, validateFn())
})
}
}
// TestIsEmpty tests the IsNotEmpty function.
func TestValidate_Not(t *testing.T) {
tests := map[string]struct {
validate Validate
err error
expectedErr error
}{
"Not on err validate should negate the error": {
validate: validateWErr,
err: errTest,
expectedErr: nil,
},
"Not on nil validate should throw error": {
validate: validateWNil,
err: errTest,
expectedErr: errTest,
},
}
for testName, testCase := range tests {
t.Run(testName, func(t *testing.T) {
validateFn := testCase.validate.Not(testCase.err)
assert.Equal(t, testCase.expectedErr, validateFn())
})
}
}