diff --git a/handlers/auth_test.go b/handlers/auth_test.go index 5ab7f51..d56e764 100644 --- a/handlers/auth_test.go +++ b/handlers/auth_test.go @@ -42,8 +42,8 @@ var ( func TestCreateBackend(t *testing.T) { secret = util.GetPrivateKey() - viper.AddConfigPath("../") - viper.Set("General.DataDir", "../data") + viper.SetConfigName("test") + util.DoNotSetConfigName = true if err := util.ReadInConfig(); err != nil { t.Fatalf("could not reload config file: %v", err) } diff --git a/handlers/test.yaml b/handlers/test.yaml new file mode 100644 index 0000000..823f57f --- /dev/null +++ b/handlers/test.yaml @@ -0,0 +1,4 @@ +General: + DataDir: ../data + EnableDebugMode: true + ShortedIDLength: 4 diff --git a/util/config.go b/util/config.go index 5f24edd..7998819 100644 --- a/util/config.go +++ b/util/config.go @@ -9,14 +9,19 @@ import ( "github.com/spf13/viper" ) -var dataDirPath string +var ( + dataDirPath string + DoNotSetConfigName = false +) // ReadInConfig loads the configuration and other needed folders for further usage func ReadInConfig() error { viper.AutomaticEnv() viper.SetEnvPrefix("gus") viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetConfigName("config") + if !DoNotSetConfigName { + viper.SetConfigName("config") + } viper.AddConfigPath(".") setConfigDefaults() err := viper.ReadInConfig()