forked from 0xERR0R/blocky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_test.go
108 lines (87 loc) · 2.58 KB
/
redis_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
package config
import (
"github.com/0xERR0R/blocky/log"
"github.com/creasty/defaults"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Redis", func() {
var (
c Redis
err error
)
suiteBeforeEach()
BeforeEach(func() {
err = defaults.Set(&c)
Expect(err).Should(Succeed())
})
Describe("IsEnabled", func() {
When("all fields are default", func() {
It("should be disabled", func() {
Expect(c.IsEnabled()).Should(BeFalse())
})
})
When("Address is set", func() {
BeforeEach(func() {
c.Address = "localhost:6379"
})
It("should be enabled", func() {
Expect(c.IsEnabled()).Should(BeTrue())
})
})
})
Describe("LogConfig", func() {
BeforeEach(func() {
logger, hook = log.NewMockEntry()
})
When("all fields are default", func() {
It("should log default values", func() {
c.LogConfig(logger)
Expect(hook.Messages).Should(
SatisfyAll(ContainElement(ContainSubstring("address: ")),
ContainElement(ContainSubstring("username: ")),
ContainElement(ContainSubstring("password: ")),
ContainElement(ContainSubstring("database: ")),
ContainElement(ContainSubstring("required: ")),
ContainElement(ContainSubstring("connectionAttempts: ")),
ContainElement(ContainSubstring("connectionCooldown: "))))
})
})
When("Address is set", func() {
BeforeEach(func() {
c.Address = "localhost:6379"
})
It("should log address", func() {
c.LogConfig(logger)
Expect(hook.Messages).Should(ContainElement(ContainSubstring("address: localhost:6379")))
})
})
When("SentinelAddresses is set", func() {
BeforeEach(func() {
c.SentinelAddresses = []string{"localhost:26379", "localhost:26380"}
})
It("should log sentinel addresses", func() {
c.LogConfig(logger)
Expect(hook.Messages).Should(
SatisfyAll(
ContainElement(ContainSubstring("sentinel:")),
ContainElement(ContainSubstring(" addresses:")),
ContainElement(ContainSubstring(" - localhost:26379")),
ContainElement(ContainSubstring(" - localhost:26380"))))
})
})
const secretValue = "secret-value"
It("should not log the password", func() {
c.Password = secretValue
c.LogConfig(logger)
Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).ShouldNot(ContainElement(ContainSubstring(secretValue)))
})
It("should not log the sentinel password", func() {
c.SentinelPassword = secretValue
c.LogConfig(logger)
Expect(hook.Calls).ShouldNot(BeEmpty())
Expect(hook.Messages).ShouldNot(ContainElement(ContainSubstring(secretValue)))
})
})
})