From 3630cfca2bf65b55e15f52d3a6aa4707a7d173ae Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 4 Jul 2019 14:18:08 +0200 Subject: [PATCH] e2e: fix full path support when reading viper config file Something changed in Viper such that it now returns the ConfigFileNotFound error when the config file is not found, for example when it is specified including the .yaml or .json suffix. When the code was originally was written, it returned "Unsupported Config Type". Found when adding a unit test for this code (separate commit because it depends on the flag changes). --- test/e2e/framework/viperconfig/viperconfig.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/e2e/framework/viperconfig/viperconfig.go b/test/e2e/framework/viperconfig/viperconfig.go index 0006e9bb70f..0b68174d2cf 100644 --- a/test/e2e/framework/viperconfig/viperconfig.go +++ b/test/e2e/framework/viperconfig/viperconfig.go @@ -25,10 +25,6 @@ import ( "github.com/spf13/viper" ) -const ( - viperFileNotFound = "Unsupported Config Type \"\"" -) - // ViperizeFlags checks whether a configuration file was specified, reads it, and updates // the configuration variables accordingly. Must be called after framework.HandleFlags() // and before framework.AfterReadingAllFlags(). @@ -68,7 +64,7 @@ func ViperizeFlags(requiredConfig, optionalConfig string) error { // of file suffices. Therefore try once more without // suffix. ext := filepath.Ext(viperConfig) - if ext != "" && err.Error() == viperFileNotFound { + if _, ok := err.(viper.ConfigFileNotFoundError); ok && ext != "" { viper.SetConfigName(filepath.Base(viperConfig[0 : len(viperConfig)-len(ext)])) err = viper.ReadInConfig() }