test

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMntNsFilterMap

func CreateMntNsFilterMap(t testing.TB, mountNsIDs ...uint64) *ebpf.Map

CreateMntNsFilterMap creates and fills an eBPF map that can be used to filter by mount namespace in the different tracers.

func Equal

func Equal[T comparable](t *testing.T, expected, actual T, message string)

Equal compares if two values are the same. Deprecated: Use require.Equal instead.

func ExpectNoEvent

func ExpectNoEvent[Event any, Extra any](t *testing.T, _ *RunnerInfo, _ Extra, events []Event)

ExpectNoEvent doesn't expect any event to be captured by the tracer.

func HostInit added in v0.19.0

func HostInit(t *testing.T)

HostInit initializes the host package for testing without any automatic workarounds.

func ReadFileAsUint32 added in v0.17.0

func ReadFileAsUint32(t testing.TB, path string) uint32

func RequireKernelVersion

func RequireKernelVersion(t testing.TB, expectedVersion *kernel.VersionInfo)

func RequireRoot

func RequireRoot(t testing.TB)

RequireRoot skips the test if the not running as root

func RunWithRunner

func RunWithRunner(t testing.TB, runner *Runner, f func() error)

Types

type Runner

type Runner struct {
	Info *RunnerInfo
	// contains filtered or unexported fields
}

Runner is a helper type to execute tests in different conditions. It creates a go routine that is executed in a different mount namespace, user ID, etc. to simulate events hapenning inside containers.

func NewRunner

func NewRunner(config *RunnerConfig) (*Runner, error)

func NewRunnerWithTest

func NewRunnerWithTest(t testing.TB, config *RunnerConfig) *Runner

func (*Runner) Close

func (r *Runner) Close()

func (*Runner) Run

func (r *Runner) Run(f func() error) error

type RunnerConfig

type RunnerConfig struct {
	// User ID to run under
	Uid int

	// Group ID to run under
	Gid int

	// HostNetwork prevents the runner from creating a new network namespace
	HostNetwork bool
}

RunnerConfig defines how the runner should behave. TODO: We could implement more options like unsharing the network namespace, running on a different group ID, etc.

type RunnerInfo

type RunnerInfo struct {
	Pid         int
	Tid         int
	Comm        string
	Uid         int
	Gid         int
	MountNsID   uint64
	NetworkNsID uint64
	UserNsID    uint64
}

RunnerInfo contains information about the runner and it's used by the tests to verify that the generated events have the correct value for fields like PID, UID and MountNsID.

type ValidateEventType

type ValidateEventType[Event any, Extra any] func(*testing.T, *RunnerInfo, Extra, []Event)

func ExpectAtLeastOneEvent

func ExpectAtLeastOneEvent[Event any, Extra any](getEvent func(info *RunnerInfo, extra Extra) *Event) ValidateEventType[Event, Extra]

ExpectAtLeastOneEvent expects that at least one of the captures events matches.

func ExpectOneEvent

func ExpectOneEvent[Event any, Extra any](getEvent func(info *RunnerInfo, extra Extra) *Event) ValidateEventType[Event, Extra]

ExpectOneEvent expects only matching event to be captured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL