-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
93 lines (83 loc) · 1.78 KB
/
node_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fracker_test
import (
"github.com/coreos/go-etcd/etcd"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
f "github.com/shopkeep/fracker"
)
var _ = Describe("Node", func() {
Describe(`Each`, func() {
// a counter to check the number of times a function yields
var yields int
var valMap map[string]string
var node f.Node
BeforeEach(func() {
yields = 0
valMap = make(map[string]string, 0)
})
JustBeforeEach(func() {
node.Each(func(k, v string) {
valMap[k] = v
yields++
})
})
Context(`when the node isn't a directory`, func() {
BeforeEach(func() {
node = f.NewNode(&etcd.Node{
Dir: false,
Key: "/foo",
Value: "1234",
})
})
It(`yields once`, func() {
Expect(yields).To(Equal(1))
})
It(`yields the file's name and value`, func() {
Expect(valMap).To(Equal(map[string]string{
"/foo": "1234",
}))
})
})
Context(`when the node is a directory`, func() {
BeforeEach(func() {
node = f.NewNode(&etcd.Node{
Dir: true,
Key: "/foo",
Nodes: []*etcd.Node{
&etcd.Node{
Dir: false,
Key: "/foo/bar",
Value: "1234",
},
&etcd.Node{
Dir: true,
Key: "/foo/baz",
Nodes: []*etcd.Node{
&etcd.Node{
Dir: false,
Key: "/foo/baz/qux",
Value: "crunch",
},
&etcd.Node{
Dir: false,
Key: "/foo/baz/goo",
Value: "munch",
},
},
},
},
})
})
It(`yields once for each file`, func() {
Expect(yields).To(Equal(3))
})
It(`yields each key value pair`, func() {
Expect(valMap).To(Equal(map[string]string{
"/foo/bar": "1234",
"/foo/baz/qux": "crunch",
"/foo/baz/goo": "munch",
}))
})
})
})
})