-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_test.go
75 lines (54 loc) · 1.8 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
67
68
69
70
71
72
73
74
75
package gestalt_test
import (
"testing"
"github.com/ovrclk/gestalt"
"github.com/ovrclk/gestalt/component"
"github.com/ovrclk/gestalt/vars"
)
func TestValidate(t *testing.T) {
suite := component.NewSuite("top")
if missing := gestalt.Validate(suite); len(missing) > 0 {
t.Errorf("missing vars for empty suite")
}
suite.Run(gestalt.NoopComponent("a"))
if missing := gestalt.Validate(suite); len(missing) > 0 {
t.Fail()
}
suite.Run(gestalt.NoopComponent("b").
WithMeta(vars.NewMeta().Export("x")))
if missing := gestalt.Validate(suite); len(missing) > 0 {
t.Fail()
}
suite.Run(gestalt.NoopComponent("c").
WithMeta(vars.NewMeta().Require("x")))
if missing := gestalt.Validate(suite); len(missing) > 0 {
t.Fail()
}
suite.Run(gestalt.NoopComponent("d").
WithMeta(vars.NewMeta().Require("y")))
if missing := gestalt.Validate(suite); len(missing) != 1 {
t.Errorf("invalid missing vars count: %#v", missing)
} else if missing[0].Path != "/top/d" || missing[0].Name != "y" {
t.Errorf("invalid missing vars: %#v", missing)
}
suite.WithMeta(vars.NewMeta().Require("y"))
input := vars.FromMap(map[string]string{"y": "z"})
if missing := gestalt.ValidateWith(suite, input); len(missing) > 0 {
t.Fail()
}
suite.Run(component.NewSuite("lower").
Run(gestalt.NoopComponent("d").
WithMeta(vars.NewMeta().Require("y"))))
if missing := gestalt.ValidateWith(suite, input); len(missing) > 0 {
t.Fail()
}
if missing := gestalt.Validate(suite); len(missing) != 1 {
t.Errorf("invalid missing vars count: %#v", missing)
} else if missing[0].Path != "/top" || missing[0].Name != "y" {
t.Errorf("invalid missing vars: %#v", missing)
}
suite.WithMeta(vars.NewMeta().Default("y", "z"))
if missing := gestalt.Validate(suite); len(missing) > 0 {
t.Errorf("default entries not being applied")
}
}