2023-03-12 22:14:10 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/0xERR0R/blocky/helpertest"
|
|
|
|
|
|
|
|
"github.com/creasty/defaults"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("FilteringConfig", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
var cfg Filtering
|
2023-03-12 22:14:10 +01:00
|
|
|
|
|
|
|
suiteBeforeEach()
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg = Filtering{
|
2023-03-12 22:14:10 +01:00
|
|
|
QueryTypes: NewQTypeSet(AAAA, MX),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("IsEnabled", func() {
|
|
|
|
It("should be false by default", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg := Filtering{}
|
2023-03-12 22:14:10 +01:00
|
|
|
Expect(defaults.Set(&cfg)).Should(Succeed())
|
|
|
|
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeFalse())
|
|
|
|
})
|
|
|
|
|
|
|
|
When("enabled", func() {
|
|
|
|
It("should be true", func() {
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
When("disabled", func() {
|
|
|
|
It("should be false", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg := Filtering{}
|
2023-03-12 22:14:10 +01:00
|
|
|
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeFalse())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("LogConfig", func() {
|
|
|
|
It("should log configuration", func() {
|
|
|
|
cfg.LogConfig(logger)
|
|
|
|
|
|
|
|
Expect(hook.Calls).Should(HaveLen(3))
|
2023-11-24 01:50:13 +01:00
|
|
|
Expect(hook.Messages).Should(ContainElements(
|
|
|
|
ContainSubstring("query types:"),
|
|
|
|
ContainSubstring(" - AAAA"),
|
|
|
|
ContainSubstring(" - MX"),
|
|
|
|
))
|
2023-03-12 22:14:10 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|