-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathvalidation_test.go
65 lines (49 loc) · 1.49 KB
/
validation_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
package rqp
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestIn(t *testing.T) {
err := In("one", "two")("three")
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "three: not in scope")
err = In(1, 2)(3)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "3: not in scope")
err = In(true)(false)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "false: not in scope")
}
func TestMinMax(t *testing.T) {
err := Max(100)(101)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "101: not in scope")
err = Max(100)(100)
assert.NoError(t, err)
err = Min(100)(100)
assert.NoError(t, err)
err = MinMax(10, 100)(9)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "9: not in scope")
err = MinMax(10, 100)(101)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "101: not in scope")
err = MinMax(10, 100)(50)
assert.NoError(t, err)
err = Multi(Min(10), Max(100))(50)
assert.NoError(t, err)
err = Multi(Min(10), Max(100))(101)
assert.Equal(t, errors.Cause(err), ErrNotInScope)
err = MinMax(10, 100)("one")
assert.Equal(t, errors.Cause(err), ErrNotInScope)
assert.EqualError(t, err, "one: not in scope")
}
func TestNotEmpty(t *testing.T) {
// good case
err := NotEmpty()("test")
assert.NoError(t, err)
// bad case
err = NotEmpty()("")
assert.Equal(t, errors.Cause(err), ErrNotInScope)
}