blocky/cmd/root_test.go

71 lines
1.5 KiB
Go
Raw Permalink Normal View History

2021-02-08 21:57:59 +01:00
package cmd
import (
2022-08-19 22:04:35 +02:00
"io"
2022-09-08 22:34:08 +02:00
"os"
2021-08-25 22:06:34 +02:00
"github.com/0xERR0R/blocky/log"
2022-03-03 11:27:27 +01:00
. "github.com/onsi/ginkgo/v2"
2021-02-08 21:57:59 +01:00
. "github.com/onsi/gomega"
2022-09-08 22:34:08 +02:00
. "github.com/0xERR0R/blocky/helpertest"
2021-02-08 21:57:59 +01:00
)
2022-09-08 22:34:08 +02:00
var _ = Describe("root command", func() {
2021-02-08 21:57:59 +01:00
When("Version command is called", func() {
log.Log().ExitFunc = nil
2021-02-08 21:57:59 +01:00
It("should execute without error", func() {
2021-02-08 22:42:48 +01:00
c := NewRootCommand()
2022-08-19 22:04:35 +02:00
c.SetOutput(io.Discard)
2021-02-08 22:42:48 +01:00
c.SetArgs([]string{"help"})
2021-02-08 21:57:59 +01:00
err := c.Execute()
Expect(err).Should(Succeed())
})
})
2022-09-08 22:34:08 +02:00
When("Config provided", func() {
var (
tmpDir *TmpFolder
tmpFile *TmpFile
)
BeforeEach(func() {
configPath = defaultConfigPath
tmpDir = NewTmpFolder("RootCommand")
tmpFile = tmpDir.CreateStringFile("config",
"upstreams:",
" groups:",
" default:",
" - 1.1.1.1",
2022-09-08 22:34:08 +02:00
"blocking:",
" denylists:",
2022-09-08 22:34:08 +02:00
" ads:",
" - https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt",
" clientGroupsBlock:",
" default:",
" - ads",
"port: 5333",
)
})
It("should accept old env var", func() {
os.Setenv(configFileEnvVarOld, tmpFile.Path)
DeferCleanup(func() { os.Unsetenv(configFileEnvVarOld) })
Expect(initConfig()).Should(Succeed())
2022-09-08 22:34:08 +02:00
Expect(configPath).Should(Equal(tmpFile.Path))
})
It("should accept new env var", func() {
os.Setenv(configFileEnvVar, tmpFile.Path)
DeferCleanup(func() { os.Unsetenv(configFileEnvVar) })
Expect(initConfig()).Should(Succeed())
2022-09-08 22:34:08 +02:00
Expect(configPath).Should(Equal(tmpFile.Path))
})
})
2021-02-08 21:57:59 +01:00
})