diff --git a/viper.go b/viper.go index e5a360a..d800395 100644 --- a/viper.go +++ b/viper.go @@ -1214,6 +1214,7 @@ func SetConfigName(in string) { v.SetConfigName(in) } func (v *Viper) SetConfigName(in string) { if in != "" { v.configName = in + v.configFile = "" } } diff --git a/viper_test.go b/viper_test.go index aa9d7fe..0c0c7e5 100644 --- a/viper_test.go +++ b/viper_test.go @@ -901,3 +901,9 @@ func TestUnmarshalingWithAliases(t *testing.T) { assert.Equal(t, &C, &config{Id: 1, FirstName: "Steve", Surname: "Owen"}) } + +func TestSetConfigNameClearsFileCache(t *testing.T) { + SetConfigFile("/tmp/config.yaml") + SetConfigName("default") + assert.Empty(t, v.getConfigFile()) +}