Skip to content

Commit

Permalink
test mountBpfPinPath with a privileged test
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Apr 16, 2024
1 parent 0c71339 commit aa32f3d
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/internal/discover/attacher_linux_privileged_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build linux

package discover

import (
"log/slog"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMountBpfPinPath(t *testing.T) {
if os.Getenv(privilegedEnv) == "" {
t.Skipf("Set %s to run this test", privilegedEnv)
}
tmpDir := "path"
ta := &TraceAttacher{
log: slog.With("component", "discover.TraceAttacher"),
pinPath: tmpDir,
}

// Nothing there to start the test
mounted, matched, err := IsMountFS(FilesystemTypeBPFFS, tmpDir)
assert.NoError(t, err)
assert.False(t, mounted)
assert.False(t, matched)

err = ta.mountBpfPinPath()
assert.NoError(t, err)

// Check that it is mounted
mounted, matched, err = IsMountFS(FilesystemTypeBPFFS, tmpDir)
assert.NoError(t, err)
assert.True(t, mounted)
assert.True(t, matched)

// Ensure mounting the same path twice does not fail
err = ta.mountBpfPinPath()
assert.NoError(t, err)

// Check that it is mounted
mounted, matched, err = IsMountFS(FilesystemTypeBPFFS, tmpDir)
assert.NoError(t, err)
assert.True(t, mounted)
assert.True(t, matched)

ta.unmountBpfPinPath()

// Check that it is cleaned up
mounted, matched, err = IsMountFS(FilesystemTypeBPFFS, tmpDir)
assert.NoError(t, err)
assert.False(t, mounted)
assert.False(t, matched)
}

0 comments on commit aa32f3d

Please sign in to comment.