Browse Source

Fixed failing ci build caused from #34. Now using specific config files for tests

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
5e9c6e7e83
  1. 4
      handlers/auth_test.go
  2. 4
      handlers/test.yaml
  3. 9
      util/config.go

4
handlers/auth_test.go

@ -42,8 +42,8 @@ var (
func TestCreateBackend(t *testing.T) { func TestCreateBackend(t *testing.T) {
secret = util.GetPrivateKey() secret = util.GetPrivateKey()
viper.AddConfigPath("../") viper.SetConfigName("test")
viper.Set("General.DataDir", "../data") util.DoNotSetConfigName = true
if err := util.ReadInConfig(); err != nil { if err := util.ReadInConfig(); err != nil {
t.Fatalf("could not reload config file: %v", err) t.Fatalf("could not reload config file: %v", err)
} }

4
handlers/test.yaml

@ -0,0 +1,4 @@
General:
DataDir: ../data
EnableDebugMode: true
ShortedIDLength: 4

9
util/config.go

@ -9,14 +9,19 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
var dataDirPath string var (
dataDirPath string
DoNotSetConfigName = false
)
// ReadInConfig loads the configuration and other needed folders for further usage // ReadInConfig loads the configuration and other needed folders for further usage
func ReadInConfig() error { func ReadInConfig() error {
viper.AutomaticEnv() viper.AutomaticEnv()
viper.SetEnvPrefix("gus") viper.SetEnvPrefix("gus")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetConfigName("config") if !DoNotSetConfigName {
viper.SetConfigName("config")
}
viper.AddConfigPath(".") viper.AddConfigPath(".")
setConfigDefaults() setConfigDefaults()
err := viper.ReadInConfig() err := viper.ReadInConfig()

Loading…
Cancel
Save