-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval_test.go
79 lines (62 loc) · 1.93 KB
/
eval_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
76
77
78
79
package gestalt_test
import (
"reflect"
"testing"
"github.com/ovrclk/gestalt"
"github.com/ovrclk/gestalt/component"
"github.com/ovrclk/gestalt/vars"
"github.com/stretchr/testify/assert"
)
func TestMeta(t *testing.T) {
exports := []string{"a"}
c := gestalt.NewComponent("foo", nil).
WithMeta(vars.NewMeta().Export(exports...))
if x := c.Meta().Exports(); !reflect.DeepEqual(x, exports) {
t.Errorf("meta export missing keys %v != %v", x, exports)
}
}
func TestExportWithParentGroup(t *testing.T) {
generator := exportComponent("a", "foo")
check, ran := checkComponent(t, "a", "foo")
cgroup := component.NewGroup("create")
cgroup.Run(component.NewRetry(1, 0).Run(generator))
cgroup.WithMeta(vars.NewMeta().Export("a"))
pgroup := component.NewGroup("parent")
pgroup.Run(cgroup)
pgroup.Run(check)
e := gestalt.NewEvaluator()
e.Evaluate(pgroup)
assert.True(t, *ran)
}
func TestExportWithEnsureParent(t *testing.T) {
generator := exportComponent("a", "foo")
check, ran := checkComponent(t, "a", "foo")
fcheck, fran := checkComponent(t, "a", "foo")
cgroup := component.NewGroup("create")
cgroup.Run(component.NewRetry(1, 0).Run(generator))
cgroup.WithMeta(vars.NewMeta().Export("a"))
pgroup := component.NewEnsure("parent")
pgroup.First(generator)
pgroup.Run(check)
pgroup.Finally(fcheck)
e := gestalt.NewEvaluator()
e.Evaluate(pgroup)
assert.True(t, *ran)
assert.True(t, *fran)
}
func exportComponent(key, value string) gestalt.Component {
return gestalt.NewComponent("create", func(e gestalt.Evaluator) error {
e.Emit(key, value)
return nil
}).WithMeta(vars.NewMeta().Export(key))
}
func checkComponent(t *testing.T, key, value string) (gestalt.Component, *bool) {
ran := false
check := gestalt.NewComponent("check", func(e gestalt.Evaluator) error {
ran = true
assert.True(t, e.Vars().Has(key))
assert.Equal(t, value, e.Vars().Get(key))
return nil
}).WithMeta(vars.NewMeta().Require(key))
return check, &ran
}