adguardhome-sync/cmd/root_test.go

66 lines
1.8 KiB
Go
Raw Normal View History

2021-11-02 01:38:35 +08:00
package cmd
import (
2021-11-30 05:25:01 +08:00
"os"
"github.com/bakito/adguardhome-sync/pkg/log"
2021-11-02 01:38:35 +08:00
"github.com/bakito/adguardhome-sync/pkg/types"
2021-12-10 05:55:38 +08:00
. "github.com/onsi/ginkgo/v2"
2021-11-02 01:38:35 +08:00
. "github.com/onsi/gomega"
"go.uber.org/zap"
2021-11-02 01:38:35 +08:00
)
var envVars = []string{
"FEATURES_GENERALSETTINGS",
"FEATURES_QUERYLOGCONFIG",
"FEATURES_STATSCONFIG",
"FEATURES_CLIENTSETTINGS",
"FEATURES_SERVICES",
"FEATURES_FILTERS",
"FEATURES_DHCP_SERVERCONFIG",
"FEATURES_DHCP_STATICLEASES",
"FEATURES_DNS_SERVERCONFIG",
"FEATURES_DNS_ACCESSLISTS",
"FEATURES_DNS_REWRITES",
}
var _ = Describe("Run", func() {
var logger *zap.SugaredLogger
2021-11-02 01:38:35 +08:00
BeforeEach(func() {
logger = log.GetLogger("root")
2021-11-02 01:38:35 +08:00
for _, envVar := range envVars {
Ω(os.Unsetenv(envVar)).ShouldNot(HaveOccurred())
}
initConfig()
})
Context("getConfig", func() {
It("features should be true by default", func() {
cfg, err := getConfig(logger)
2021-11-02 01:38:35 +08:00
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, true)
})
It("features should be false", func() {
for _, envVar := range envVars {
Ω(os.Setenv(envVar, "false")).ShouldNot(HaveOccurred())
}
cfg, err := getConfig(logger)
2021-11-02 01:38:35 +08:00
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, false)
})
})
})
func verifyFeatures(cfg *types.Config, value bool) {
Ω(cfg.Features.GeneralSettings).Should(Equal(value))
Ω(cfg.Features.QueryLogConfig).Should(Equal(value))
Ω(cfg.Features.StatsConfig).Should(Equal(value))
Ω(cfg.Features.ClientSettings).Should(Equal(value))
Ω(cfg.Features.Services).Should(Equal(value))
Ω(cfg.Features.Filters).Should(Equal(value))
Ω(cfg.Features.DHCP.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DHCP.StaticLeases).Should(Equal(value))
Ω(cfg.Features.DNS.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DNS.AccessLists).Should(Equal(value))
Ω(cfg.Features.DNS.Rewrites).Should(Equal(value))
}