From 293162ac5462e2b32d869635b727c44d2ccb665f Mon Sep 17 00:00:00 2001 From: Zack Olson Date: Tue, 28 Jan 2025 13:23:34 -0500 Subject: [PATCH] test cleanup improvements (#2015) --- pkg/osquery/runsimple/osqueryrunner_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/osquery/runsimple/osqueryrunner_test.go b/pkg/osquery/runsimple/osqueryrunner_test.go index 67935c2f0..c735ac1f3 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.RemoveAll(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,7 +40,9 @@ func TestMain(m *testing.M) { // Run the tests! retCode := m.Run() - os.Exit(retCode) //nolint:forbidigo // Fine to use os.Exit in tests + + os.RemoveAll(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 } func Test_OsqueryRunSqlNoIO(t *testing.T) {