-
Notifications
You must be signed in to change notification settings - Fork 4
/
when_test.go
50 lines (43 loc) · 913 Bytes
/
when_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
package govalidator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_When(t *testing.T) {
tests := []struct {
name string
condition bool
expectedExec bool
}{
{
name: "test the given closure will run if the condition is true",
condition: len("reza") > 0,
expectedExec: true,
},
{
name: "test the given closure won't run if the condition is false",
condition: len("reza") < 2,
expectedExec: false,
},
{
name: "test the given closure won't run if the condition is false",
condition: "" == "golang",
expectedExec: false,
},
}
for _, test := range tests {
v := New()
executed := false
v.When(test.condition, func() {
executed = true
})
assert.Equalf(
t,
test.expectedExec,
executed,
"test case %q failed, expected %s, got: %s",
test.expectedExec,
executed,
)
}
}