diff --git a/config/config_test.go b/config/config_test.go index b02776867bb..35832a00e64 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -17,7 +17,6 @@ package config import ( "os" "path" - "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -560,19 +559,10 @@ func TestLoadEmptyConfig(t *testing.T) { } func loadConfigFile(t *testing.T, fileName string, factories component.Factories) (*configmodels.Config, error) { - // Open the file for reading. - file, err := os.Open(filepath.Clean(fileName)) - require.NoErrorf(t, err, "unable to open the file %v", fileName) - require.NotNil(t, file) - - defer func() { - require.NoErrorf(t, file.Close(), "unable to close the file %v", fileName) - }() - // Read yaml config from file v := NewViper() - v.SetConfigType("yaml") - require.NoErrorf(t, v.ReadConfig(file), "unable to read the file %v", fileName) + v.SetConfigFile(fileName) + require.NoErrorf(t, v.ReadInConfig(), "unable to read the file %v", fileName) // Load the config from viper using the given factories. cfg, err := Load(v, factories) diff --git a/config/configtest/configtest.go b/config/configtest/configtest.go index cd1d190b566..3d75e3e5d35 100644 --- a/config/configtest/configtest.go +++ b/config/configtest/configtest.go @@ -15,8 +15,6 @@ package configtest import ( - "os" - "path/filepath" "testing" "github.com/spf13/viper" @@ -32,19 +30,10 @@ import ( // and can then be used to unmarshal the file contents to objects. // Example usage for testing can be found in configtest_test.go func NewViperFromYamlFile(t *testing.T, fileName string) *viper.Viper { - // Open the file for reading. - file, err := os.Open(filepath.Clean(fileName)) - require.NoErrorf(t, err, "unable to open the file %v", fileName) - require.NotNil(t, file) - - defer func() { - require.NoErrorf(t, file.Close(), "unable to close the file %v", fileName) - }() - // Read yaml config from file v := config.NewViper() - v.SetConfigType("yaml") - require.NoErrorf(t, v.ReadConfig(file), "unable to read the file %v", fileName) + v.SetConfigFile(fileName) + require.NoErrorf(t, v.ReadInConfig(), "unable to read the file %v", fileName) return v }