-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_test.go
39 lines (36 loc) · 894 Bytes
/
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
package validate_test
import (
_ "fmt"
. "github.com/franela/goblin"
. "github.com/joslinm/validate"
"testing"
)
func TestValidate(t *testing.T) {
g := Goblin(t)
g.Describe("Validate", func() {
g.Describe("Output", func() {
g.It("Should return a hash of params sent in if they pass their rules", func() {
params, _ := Validate(map[string]interface{}{
"x": "4",
"y": "hi!",
}).With(RuleBook{
"x": RB.Min(1),
"y": RB.Regex("hi.*"),
})
g.Assert(params["x"]).Equal(4)
g.Assert(params["y"]).Equal("hi!")
})
g.It("Should return a hash of errors for all failed params", func() {
_, errors := Validate(map[string]interface{}{
"x": "4",
"y": "hi!",
}).With(RuleBook{
"x": RB.Min(5),
"y": RB.Regex("ddd.*"),
})
g.Assert(errors["x"] != nil).IsTrue()
g.Assert(errors["y"] != nil).IsTrue()
})
})
})
}