blocky/config/redis_test.go

109 lines
2.6 KiB
Go
Raw Permalink Normal View History

Refactoring Redis (#1271) * RedisConfig -> Redis * moved redis config to seperate file * bugfix in config test during parallel processing * implement config.Configurable in Redis config * use Context in GetRedisCache * use Context in New * caching resolver test fix * use Context in PublishEnabled * use Context in getResponse * remove ctx field * bugfix in api interface test * propperly close channels * set ruler for go files from 80 to 111 * line break because function length is to long * only execute redis.New if it is enabled in config * stabilized flaky tests * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * fix ruler * redis test refactoring * vscode setting cleanup * removed else if chain * Update redis_test.go * context race fix * test fail on missing seintinel servers * cleanup context usage * cleanup2 * context fixes * added context util * disabled nil context rule for tests * copy paste error ctxSend -> CtxSend * use util.CtxSend * fixed comment * fixed flaky test * failsafe and tests --------- Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
2023-11-27 18:08:31 +01:00
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)))
Refactoring Redis (#1271) * RedisConfig -> Redis * moved redis config to seperate file * bugfix in config test during parallel processing * implement config.Configurable in Redis config * use Context in GetRedisCache * use Context in New * caching resolver test fix * use Context in PublishEnabled * use Context in getResponse * remove ctx field * bugfix in api interface test * propperly close channels * set ruler for go files from 80 to 111 * line break because function length is to long * only execute redis.New if it is enabled in config * stabilized flaky tests * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * fix ruler * redis test refactoring * vscode setting cleanup * removed else if chain * Update redis_test.go * context race fix * test fail on missing seintinel servers * cleanup context usage * cleanup2 * context fixes * added context util * disabled nil context rule for tests * copy paste error ctxSend -> CtxSend * use util.CtxSend * fixed comment * fixed flaky test * failsafe and tests --------- Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
2023-11-27 18:08:31 +01:00
})
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)))
Refactoring Redis (#1271) * RedisConfig -> Redis * moved redis config to seperate file * bugfix in config test during parallel processing * implement config.Configurable in Redis config * use Context in GetRedisCache * use Context in New * caching resolver test fix * use Context in PublishEnabled * use Context in getResponse * remove ctx field * bugfix in api interface test * propperly close channels * set ruler for go files from 80 to 111 * line break because function length is to long * only execute redis.New if it is enabled in config * stabilized flaky tests * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * Update config/redis_test.go Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com> * fix ruler * redis test refactoring * vscode setting cleanup * removed else if chain * Update redis_test.go * context race fix * test fail on missing seintinel servers * cleanup context usage * cleanup2 * context fixes * added context util * disabled nil context rule for tests * copy paste error ctxSend -> CtxSend * use util.CtxSend * fixed comment * fixed flaky test * failsafe and tests --------- Co-authored-by: ThinkChaos <ThinkChaos@users.noreply.github.com>
2023-11-27 18:08:31 +01:00
})
})
})