Skip to content

Commit

Permalink
fix up agent reset_test.go defers
Browse files Browse the repository at this point in the history
  • Loading branch information
zackattack01 committed Dec 23, 2024
1 parent 9f6e0cf commit da95bb3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ee/agent/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ func TestMain(m *testing.M) {
fmt.Printf("failed to make temp dir for test osquery binary: %v", err)
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
}
defer os.RemoveAll(downloadDir)

target := packaging.Target{}
if err := target.PlatformFromString(runtime.GOOS); err != nil {
fmt.Printf("error parsing platform %s: %v", runtime.GOOS, err)
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
}
target.Arch = packaging.ArchFlavor(runtime.GOARCH)
if runtime.GOOS == "darwin" {
target.Arch = packaging.Universal
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

dlPath, err := packaging.FetchBinary(ctx, downloadDir, "osqueryd", target.PlatformBinaryName("osqueryd"), "nightly", target)
if err != nil {
fmt.Printf("error fetching binary osqueryd binary: %v", err)
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
cancel() // explicit cancel as defer will not run when os.Exit is called
os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
}

testOsqueryBinary = filepath.Join(downloadDir, filepath.Base(dlPath))
Expand All @@ -63,12 +64,17 @@ func TestMain(m *testing.M) {

if err := fsutil.CopyFile(dlPath, testOsqueryBinary); err != nil {
fmt.Printf("error copying osqueryd binary: %v", err)
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
cancel() // explicit cancel as defer will not run when os.Exit is called
os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
}

// Run the tests
retCode := m.Run()
os.Exit(retCode) //nolint:forbidigo // Fine to use os.Exit inside tests

cancel() // explicit cancel as defer will not run when os.Exit is called
os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
os.Exit(retCode) //nolint:forbidigo // Fine to use os.Exit inside tests
}

func TestDetectAndRemediateHardwareChange(t *testing.T) {
Expand Down

0 comments on commit da95bb3

Please sign in to comment.