From 5e9c6e7e8319458d4ef1d8c5d9e44649870ba10d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 13 Nov 2017 19:59:25 +0100 Subject: [PATCH] Fixed failing ci build caused from #34. Now using specific config files for tests --- handlers/auth_test.go | 4 ++-- handlers/test.yaml | 4 ++++ util/config.go | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 handlers/test.yaml 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()