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"
|
2022-04-22 22:12:35 +02:00
|
|
|
|
2021-08-25 22:06:34 +02:00
|
|
|
"github.com/0xERR0R/blocky/log"
|
2021-02-25 23:36:39 +01:00
|
|
|
|
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() {
|
2021-02-25 23:36:39 +01:00
|
|
|
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",
|
2023-07-28 23:55:47 +02:00
|
|
|
"upstreams:",
|
|
|
|
" groups:",
|
|
|
|
" default:",
|
|
|
|
" - 1.1.1.1",
|
2022-09-08 22:34:08 +02:00
|
|
|
"blocking:",
|
2024-04-08 19:09:51 +02:00
|
|
|
" 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) })
|
|
|
|
|
2024-05-26 20:45:30 +02:00
|
|
|
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) })
|
|
|
|
|
2024-05-26 20:45:30 +02:00
|
|
|
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
|
|
|
})
|