@@ -234,17 +234,15 @@ func initIni() {
234
234
}
235
235
236
236
// initDirs makes directories for testing.
237
- func initDirs (t * testing.T ) (string , string ) {
238
- var (
239
- testDirs = []string {`a a` , `b` , `C_` }
240
- config = `improbable`
241
- )
237
+ func initDirs (t * testing.T ) (root , config string ) {
238
+ testDirs := []string {`a a` , `b` , `C_` }
239
+ config = `improbable`
242
240
243
241
if runtime .GOOS != "windows" {
244
242
testDirs = append (testDirs , `d\d` )
245
243
}
246
244
247
- root : = t .TempDir ()
245
+ root = t .TempDir ()
248
246
249
247
for _ , dir := range testDirs {
250
248
innerDir := filepath .Join (root , dir )
@@ -428,7 +426,7 @@ func TestReadInConfig(t *testing.T) {
428
426
file , err := fs .Create (testutil .AbsFilePath (t , "/etc/viper/config.yaml" ))
429
427
require .NoError (t , err )
430
428
431
- _ , err = file .Write ([] byte ( `key: value` ) )
429
+ _ , err = file .WriteString ( `key: value` )
432
430
require .NoError (t , err )
433
431
434
432
file .Close ()
@@ -453,7 +451,7 @@ func TestReadInConfig(t *testing.T) {
453
451
file , err := fs .Create (testutil .AbsFilePath (t , "/etc/viper/config.yaml" ))
454
452
require .NoError (t , err )
455
453
456
- _ , err = file .Write ([] byte ( `key: value` ) )
454
+ _ , err = file .WriteString ( `key: value` )
457
455
require .NoError (t , err )
458
456
459
457
file .Close ()
@@ -936,7 +934,8 @@ func TestUnmarshalWithDecoderOptions(t *testing.T) {
936
934
if raw == "" {
937
935
return m , nil
938
936
}
939
- return m , json .Unmarshal ([]byte (raw ), & m )
937
+ err := json .Unmarshal ([]byte (raw ), & m )
938
+ return m , err
940
939
},
941
940
))
942
941
@@ -2343,21 +2342,21 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) {
2343
2342
assert .Equal (t , 5 , cast .ToInt (Get ("ef.lm.p.q" )))
2344
2343
}
2345
2344
2346
- func newViperWithConfigFile (t * testing.T ) (* Viper , string ) {
2345
+ func newViperWithConfigFile (t * testing.T ) (v * Viper , configFile string ) {
2347
2346
watchDir := t .TempDir ()
2348
- configFile : = path .Join (watchDir , "config.yaml" )
2347
+ configFile = path .Join (watchDir , "config.yaml" )
2349
2348
err := os .WriteFile (configFile , []byte ("foo: bar\n " ), 0o640 )
2350
2349
require .NoError (t , err )
2351
- v : = New ()
2350
+ v = New ()
2352
2351
v .SetConfigFile (configFile )
2353
2352
err = v .ReadInConfig ()
2354
2353
require .NoError (t , err )
2355
2354
require .Equal (t , "bar" , v .Get ("foo" ))
2356
2355
return v , configFile
2357
2356
}
2358
2357
2359
- func newViperWithSymlinkedConfigFile (t * testing.T ) (* Viper , string , string ) {
2360
- watchDir : = t .TempDir ()
2358
+ func newViperWithSymlinkedConfigFile (t * testing.T ) (v * Viper , watchDir , configFile string ) {
2359
+ watchDir = t .TempDir ()
2361
2360
dataDir1 := path .Join (watchDir , "data1" )
2362
2361
err := os .Mkdir (dataDir1 , 0o777 )
2363
2362
require .NoError (t , err )
@@ -2368,11 +2367,11 @@ func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string) {
2368
2367
// now, symlink the tm `data1` dir to `data` in the baseDir
2369
2368
os .Symlink (dataDir1 , path .Join (watchDir , "data" ))
2370
2369
// and link the `<watchdir>/datadir1/config.yaml` to `<watchdir>/config.yaml`
2371
- configFile : = path .Join (watchDir , "config.yaml" )
2370
+ configFile = path .Join (watchDir , "config.yaml" )
2372
2371
os .Symlink (path .Join (watchDir , "data" , "config.yaml" ), configFile )
2373
2372
t .Logf ("Config file location: %s\n " , path .Join (watchDir , "config.yaml" ))
2374
2373
// init Viper
2375
- v : = New ()
2374
+ v = New ()
2376
2375
v .SetConfigFile (configFile )
2377
2376
err = v .ReadInConfig ()
2378
2377
require .NoError (t , err )
@@ -2612,6 +2611,8 @@ func BenchmarkGetBoolFromMap(b *testing.B) {
2612
2611
}
2613
2612
2614
2613
// Skip some tests on Windows that kept failing when Windows was added to the CI as a target.
2614
+ //
2615
+ //nolint:gocritic // sloppyTestFuncName
2615
2616
func skipWindows (t * testing.T ) {
2616
2617
if runtime .GOOS == "windows" {
2617
2618
t .Skip ("Skip test on Windows" )
0 commit comments