@@ -359,7 +359,7 @@ func TestReadInConfig(t *testing.T) {
359359 t .Run ("config file set" , func (t * testing.T ) {
360360 fs := afero .NewMemMapFs ()
361361
362- err := fs .Mkdir ("/etc/viper" , 0o777 )
362+ err := fs .Mkdir (testutil . AbsFilePath ( t , "/etc/viper" ) , 0o777 )
363363 require .NoError (t , err )
364364
365365 file , err := fs .Create (testutil .AbsFilePath (t , "/etc/viper/config.yaml" ))
@@ -1573,6 +1573,23 @@ func TestReadConfigWithSetConfigFile(t *testing.T) {
15731573 assert .Equal (t , 45000 , v .GetInt ("hello.pop" ))
15741574}
15751575
1576+ func TestWrongConfigWithSetConfigFileNotFound (t * testing.T ) {
1577+ _ , config := initDirs (t )
1578+
1579+ v := New ()
1580+ v .SetConfigName (config )
1581+ v .SetDefault (`key` , `default` )
1582+
1583+ v .SetConfigFile (`whatareyoutalkingabout.yaml` )
1584+
1585+ err := v .ReadInConfig ()
1586+ assert .IsType (t , ConfigFileNotFoundError {name : "" , locations : "" }, err )
1587+
1588+ // Even though config did not load and the error might have
1589+ // been ignored by the client, the default still loads
1590+ assert .Equal (t , `default` , v .GetString (`key` ))
1591+ }
1592+
15761593func TestIsSet (t * testing.T ) {
15771594 v := New ()
15781595 v .SetConfigType ("yaml" )
@@ -1652,7 +1669,7 @@ func TestWrongDirsSearchNotFound(t *testing.T) {
16521669 v .AddConfigPath (`thispathaintthere` )
16531670
16541671 err := v .ReadInConfig ()
1655- assert .IsType (t , ConfigFileNotFoundError {"" , "" }, err )
1672+ assert .IsType (t , ConfigFileNotFoundError {name : "" , locations : "" }, err )
16561673
16571674 // Even though config did not load and the error might have
16581675 // been ignored by the client, the default still loads
@@ -1670,7 +1687,7 @@ func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
16701687 v .AddConfigPath (`thispathaintthere` )
16711688
16721689 err := v .MergeInConfig ()
1673- assert .Equal (t , reflect .TypeOf (ConfigFileNotFoundError {"" , "" }), reflect .TypeOf (err ))
1690+ assert .Equal (t , reflect .TypeOf (ConfigFileNotFoundError {name : "" , locations : "" }), reflect .TypeOf (err ))
16741691
16751692 // Even though config did not load and the error might have
16761693 // been ignored by the client, the default still loads
0 commit comments