-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfracker_test.go
143 lines (124 loc) · 3.22 KB
/
fracker_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package fracker_test
import (
"github.com/coreos/go-etcd/etcd"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
f "github.com/shopkeep/fracker"
"bytes"
"errors"
)
var _ = Describe("Fracker", func() {
var out *bytes.Buffer
var fracker f.Fracker
var client *TestClient
var err error
BeforeEach(func() {
out = bytes.NewBuffer([]byte{})
client = &TestClient{}
fracker = f.New(client)
})
Describe(`Frack`, func() {
Context(`when a key doesn't exist`, func() {
BeforeEach(func() {
client.StubGet = func(key string) (f.Node, error) {
return nil, errors.New("no key")
}
})
JustBeforeEach(func() {
err = fracker.Frack(out, []string{"/foo"})
})
It(`returns an error`, func() {
Expect(err).ToNot(BeNil())
})
})
Context(`when a key does exist`, func() {
Context(`and is a file`, func() {
BeforeEach(func() {
client.StubGet = func(key string) (f.Node, error) {
n := &etcd.Node{
Dir: false,
Key: "/foo/baaaaaz",
Value: "crunch",
}
return f.NewNode(n), nil
}
})
JustBeforeEach(func() {
err = fracker.Frack(out, []string{"/foo/baaaaaz"})
})
It(`does not return an error`, func() {
Expect(err).To(BeNil())
})
It(`writes the last segment of the node's value in KEY=VALUE format`, func() {
Expect(out.String()).To(ContainSubstring("BAAAAAZ=crunch\n"))
})
})
Context(`and the name contains hyphens`, func() {
BeforeEach(func() {
client.StubGet = func(key string) (f.Node, error) {
n := &etcd.Node{
Dir: false,
Key: "/foo/fun-times",
Value: "crunch",
}
return f.NewNode(n), nil
}
})
JustBeforeEach(func() {
err = fracker.Frack(out, []string{"/foo/fun-times"})
})
It(`does not return an error`, func() {
Expect(err).To(BeNil())
})
It(`writes the key's name replacing the hyphens with underscores`, func() {
Expect(out.String()).To(ContainSubstring("FUN_TIMES=crunch\n"))
})
})
Context(`and is a directory`, func() {
BeforeEach(func() {
client.StubGet = func(key string) (f.Node, error) {
n := &etcd.Node{
Dir: true,
Key: "/foo",
Nodes: []*etcd.Node{
&etcd.Node{
Dir: true,
Key: "/foo/bar",
Nodes: []*etcd.Node{
&etcd.Node{
Dir: false,
Key: "/foo/bar/baz",
Value: "crunch",
},
&etcd.Node{
Dir: false,
Key: "/foo/bar/qux",
Value: "munch",
},
&etcd.Node{
Dir: false,
Key: "/foo/bar/zoot-suit",
Value: "funch",
},
},
},
},
}
return f.NewNode(n), nil
}
})
JustBeforeEach(func() {
err = fracker.Frack(out, []string{"/foo"})
})
It(`doesn't return an error`, func() {
Expect(err).To(BeNil())
})
It(`writes each value out in KEY=VALUE format (removing the prefix)`, func() {
Expect(out.String()).To(ContainSubstring("BAR_BAZ=crunch\n"))
Expect(out.String()).To(ContainSubstring("BAR_QUX=munch\n"))
Expect(out.String()).To(ContainSubstring("BAR_ZOOT_SUIT=funch\n"))
})
})
})
})
})