Skip to content

Commit

Permalink
Update test directory for interactive too
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Nov 4, 2024
1 parent 34cd1ae commit c7cfcb8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/osquery/interactive/interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestProc(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

rootDir := t.TempDir()
rootDir := testRootDirectory(t)
require.NoError(t, downloadOsquery(rootDir))

var logBytes threadsafebuffer.ThreadSafeBuffer
Expand Down Expand Up @@ -176,3 +176,24 @@ func downloadOsquery(dir string) error {

return nil
}

// testRootDirectory returns a temporary directory suitable for use in these tests.
// The default t.TempDir is too long of a path, creating too long of an osquery
// extension socket, on posix systems.
func testRootDirectory(t *testing.T) string {
if runtime.GOOS == "windows" {

Check failure on line 184 in pkg/osquery/interactive/interactive_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck)

Check failure on line 184 in pkg/osquery/interactive/interactive_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck)

Check failure on line 184 in pkg/osquery/interactive/interactive_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck)

Check failure on line 184 in pkg/osquery/interactive/interactive_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck)
return t.TempDir()
}

ulid := ulid.New()
rootDir := filepath.Join(os.TempDir(), ulid[len(ulid)-4:])
require.NoError(t, os.Mkdir(rootDir, 0700))

t.Cleanup(func() {
if err := os.RemoveAll(rootDir); err != nil {
t.Errorf("testRootDirectory RemoveAll cleanup: %v", err)
}
})

return rootDir
}

0 comments on commit c7cfcb8

Please sign in to comment.