@@ -361,10 +361,11 @@ func TestCleanTempNginxCfg(t *testing.T) {
361
361
t .Fatal (err )
362
362
}
363
363
364
- tmpfile , err := os .CreateTemp ("" , tempNginxPattern )
364
+ tmpfile , err := os .CreateTemp (filepath . Join ( os . TempDir (), "nginx" ) , tempNginxPattern )
365
365
if err != nil {
366
366
t .Fatal (err )
367
367
}
368
+ expectedDeletedFile := tmpfile .Name ()
368
369
defer tmpfile .Close ()
369
370
370
371
dur , err := time .ParseDuration ("-10m" )
@@ -378,10 +379,11 @@ func TestCleanTempNginxCfg(t *testing.T) {
378
379
t .Fatal (err )
379
380
}
380
381
381
- tmpfile , err = os .CreateTemp ("" , tempNginxPattern )
382
+ tmpfile , err = os .CreateTemp (filepath . Join ( os . TempDir (), "nginx" ) , tempNginxPattern )
382
383
if err != nil {
383
384
t .Fatal (err )
384
385
}
386
+ expectedFile := tmpfile .Name ()
385
387
defer tmpfile .Close ()
386
388
387
389
err = cleanTempNginxCfg ()
@@ -391,8 +393,8 @@ func TestCleanTempNginxCfg(t *testing.T) {
391
393
392
394
var files []string
393
395
394
- err = filepath .Walk (os .TempDir (), func (path string , info os.FileInfo , _ error ) error {
395
- if info .IsDir () && os .TempDir () != path {
396
+ err = filepath .Walk (filepath . Join ( os .TempDir (), "nginx" ), func (path string , info os.FileInfo , _ error ) error {
397
+ if info .IsDir () && filepath . Join ( os .TempDir (), "nginx" ) != path {
396
398
return filepath .SkipDir
397
399
}
398
400
@@ -405,8 +407,18 @@ func TestCleanTempNginxCfg(t *testing.T) {
405
407
t .Fatal (err )
406
408
}
407
409
408
- if len (files ) != 1 {
409
- t .Errorf ("expected one file but %d were found" , len (files ))
410
+ // some other files can be created by other tests
411
+ var found bool
412
+ for _ , file := range files {
413
+ if file == expectedDeletedFile {
414
+ t .Errorf ("file %s should be deleted" , file )
415
+ }
416
+ if file == expectedFile {
417
+ found = true
418
+ }
419
+ }
420
+ if ! found {
421
+ t .Errorf ("file %s should not be deleted" , expectedFile )
410
422
}
411
423
}
412
424
0 commit comments