-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_test.go
84 lines (67 loc) · 1.82 KB
/
tree_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
package vault_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/phogolabs/vault"
"github.com/phogolabs/vault/fake"
)
var _ = Describe("RepositoryTree", func() {
var (
repository *fake.Repository
tree *vault.RepositoryTree
)
BeforeEach(func() {
repository = &fake.Repository{}
tree = &vault.RepositoryTree{
Repository: repository,
Root: make(map[string]map[string]interface{}),
}
})
AfterEach(func() {
tree.Stop()
Expect(repository.StopCallCount()).To(Equal(1))
})
fetch := func(config map[string]interface{}) map[string]map[string]interface{} {
return map[string]map[string]interface{}{
"app/service-api/config": config,
}
}
ItReturnsTheSecretSuccessfully := func(count int) {
It("returns the secret successfully", func() {
secret, err := tree.Secret("/app/service-api/config")
Expect(err).To(BeNil())
Expect(secret).To(HaveKeyWithValue("password", "swordfish"))
Expect(repository.SecretCallCount()).To(Equal(count))
})
}
Context("when the secrets is not cached", func() {
BeforeEach(func() {
secrets := map[string]interface{}{
"password": "swordfish",
}
repository.SecretReturns(secrets, nil)
})
ItReturnsTheSecretSuccessfully(1)
})
Context("when the secret is already fetched", func() {
BeforeEach(func() {
secrets := map[string]interface{}{
"password": "swordfish",
}
tree.Root = fetch(secrets)
})
ItReturnsTheSecretSuccessfully(0)
})
Context("when the provider fails", func() {
BeforeEach(func() {
repository.SecretReturns(nil, fmt.Errorf("oh no!"))
})
It("returns an error", func() {
secret, err := tree.Secret("/app/service-api/config")
Expect(err).To(MatchError("oh no!"))
Expect(secret).To(BeNil())
Expect(tree.Root).NotTo(HaveKey("/app/service-api/config"))
})
})
})