This commit is contained in:
41
internal/config/config_test.go
Normal file
41
internal/config/config_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"clintonambulance.com/calculate_negative_points/internal/config"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
type FakeSicherObject struct{}
|
||||
|
||||
func (_ FakeSicherObject) SetEnvStyle(_ string) {}
|
||||
func (_ FakeSicherObject) LoadEnv(_ string, obj interface{}) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ = Describe("ConfigTest", func() {
|
||||
var version config.Version
|
||||
var logger, _ = config.NewLogger(version, os.Stdout, []string{"cmd", "-e", "testEnvironment"})
|
||||
shouldNotExit := func(code int) {
|
||||
// "Fatal" to mimic os.Exit
|
||||
log.Default().Print("exit called with code", code)
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
config.NewSicherObject = func(_ string, _ string) config.SicherObject {
|
||||
return FakeSicherObject{}
|
||||
}
|
||||
version = config.Version{Release: "1.0.0", Commit: "abcdef", Date: "2023-01-01"}
|
||||
})
|
||||
|
||||
It("Errors if the config file is not found", func() {
|
||||
argv := []string{"cmd", "-c", "config/no-such-file.yml"}
|
||||
_, err := config.Load(version, shouldNotExit, argv, logger)
|
||||
Expect(err.Error()).To(Equal("error loading configuration file: open config/no-such-file.yml: no such file or directory"))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user