diff --git a/pkg/osquery/runsimple/osqueryrunner_test.go b/pkg/osquery/runsimple/osqueryrunner_test.go index 67935c2f0..2ef4cbc35 100644 --- a/pkg/osquery/runsimple/osqueryrunner_test.go +++ b/pkg/osquery/runsimple/osqueryrunner_test.go @@ -26,11 +26,11 @@ func TestMain(m *testing.M) { fmt.Println("Failed to make temp dir for test binaries") os.Exit(1) //nolint:forbidigo // Fine to use os.Exit in tests } - defer os.RemoveAll(dir) if err := downloadOsqueryInBinDir(dir); err != nil { fmt.Printf("Failed to download osquery: %v\n", err) - os.Exit(1) //nolint:forbidigo // Fine to use os.Exit in tests + os.Remove(dir) // explicit removal as defer will not run when os.Exit is called + os.Exit(1) //nolint:forbidigo // Fine to use os.Exit in tests } testOsqueryBinary = filepath.Join(dir, "osqueryd") @@ -40,6 +40,8 @@ func TestMain(m *testing.M) { // Run the tests! retCode := m.Run() + + os.Remove(dir) // explicit removal as defer will not run when os.Exit is called os.Exit(retCode) //nolint:forbidigo // Fine to use os.Exit in tests }