-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_validaktor_test.go
More file actions
49 lines (41 loc) · 1014 Bytes
/
struct_validaktor_test.go
File metadata and controls
49 lines (41 loc) · 1014 Bytes
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
package validaktor
import "testing"
type testStruct struct {
isValid bool
err error
data interface{}
}
func TestStructValidatorOk(t *testing.T) {
type (
st1 struct{ id int }
)
testData := []testStruct{
{data: &st1{id: 1}, isValid: true, err: nil},
{data: &st1{}, isValid: true, err: nil},
}
for _, v := range testData {
validator := &structValidator{}
isValid, err := validator.validate(v.data)
if v.isValid != isValid {
t.Errorf("%+v != %+v it should be valid with data %+v", v.isValid, isValid, v.data)
}
if err != v.err {
t.Errorf("there was an error %s", err)
}
}
}
func TestStructValidatorKo(t *testing.T) {
type (
st1 struct{ st1 *struct{} }
)
testData := []testStruct{
{data: &st1{st1: nil}, isValid: true, err: nil},
}
for _, v := range testData {
validator := &structValidator{}
isValid, _ := validator.validate(v.data)
if v.isValid != isValid {
t.Errorf("%+v != %+v it should be valid with data %+v", v.isValid, isValid, v.data)
}
}
}