testutil

package
v0.0.0-...-7aa4b52 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanDial

func CanDial(tb testing.TB, netns ns.NetNS, network, address string) (ok bool)

CanDial returns true if an address can be dialled in a specific network namespace.

func CanDialName

func CanDialName(tb testing.TB, netns ns.NetNS, network, address, name string)

CanDialName checks that a ListenWithName is reachable at the given network and address.

func ChangeEffectiveCaps

func ChangeEffectiveCaps(caps ...cap.Value) error

ChangeEffectiveCaps modifies the effective capabilities to the given list

The effective set will be empty if called without arguments.

This function changes its behaviour based on whether it is run inside a WithCapabilities closure. In that case it sets the capabilities only for the current thread. Otherwise it changes the process' set.

func ConnectSocket

func ConnectSocket(tb testing.TB, conn syscall.Conn)

ConnectSocket connects a UDP socket to localhost.

func CurrentNetNS

func CurrentNetNS(tb testing.TB) ns.NetNS

CurrentNetNS returns the current thread's network namespace.

func Dial

func Dial(tb testing.TB, netns ns.NetNS, network, address string) (conn syscall.Conn)

Dial connects to network and address in the given network namespace.

func DropIncomingTraffic

func DropIncomingTraffic(tb testing.TB, conn syscall.Conn)

func EnterUnprivilegedMode

func EnterUnprivilegedMode()

EnterUnprivilegedMode drops all effective capabilities and enters a capabilities only environment.

This means that privileged operations need to either change the effective capabilities of the current process, or execute a child process with a modified ambient capability set.

func FileStatusFlags

func FileStatusFlags(tb testing.TB, conn syscall.Conn) int

FileStatusFlags returns flags for the open file description onderlying conn.

func FlattenMetrics

func FlattenMetrics(tb testing.TB, g prometheus.Gatherer) map[string]float64

func IPPrefixComparer

func IPPrefixComparer() cmp.Option

func JoinNetNS

func JoinNetNS(tb testing.TB, netns ns.NetNS, fn func() error, caps ...cap.Value)

JoinNetNS executes a function in a different network namespace.

Any goroutines invoked from the function will still execute in the parent network namespace.

func Listen

func Listen(tb testing.TB, netns ns.NetNS, network, address string) (sys syscall.Conn)

Listen listens on a given address in a specific network namespace.

Uses a local address if address is empty.

func ListenAndEcho

func ListenAndEcho(tb testing.TB, netns ns.NetNS, network, address string) (sys syscall.Conn)

ListenAndEcho calls Listen and then starts an echo server on the returned connection.

func ListenAndEchoWithName

func ListenAndEchoWithName(tb testing.TB, netns ns.NetNS, network, address, name string) (sys syscall.Conn)

ListenAndEchoWithName is like ListenAndEcho, except that you can distinguish multiple listeners by using CanDialName.

func NewNetNS

func NewNetNS(tb testing.TB, networks ...string) ns.NetNS

NewNetNS creates a pristine network namespace.

func OpenFiles

func OpenFiles(tb testing.TB, n int) []*os.File

OpenFiles returns the specified number of files.

The files are a random mixture of pipes, TCP and UDP sockets.

func ReuseportGroup

func ReuseportGroup(tb testing.TB, netns ns.NetNS, network string, n int) (conns []syscall.Conn)

ReuseportGroup creates sockets that listen on the same port on either 127.0.0.1 or ::1, depending on the network.

func ReuseportSockets

func ReuseportSockets(tb testing.TB, network string) (a, b *os.File, ip net.IP, port int)

ReuseportSockets creates two sockets that listen on the same port on either 127.0.0.1 or ::1, depending on the network.

func SetupLoopback

func SetupLoopback() error

func SpawnChildWithFiles

func SpawnChildWithFiles(tb testing.TB, files ...*os.File) (pid int)

SpawnChildWithFiles creates a process that holds onto a bunch of files.

func WithCapabilities

func WithCapabilities(fn func() error, caps ...cap.Value) error

WithCapabilities raises the effective capabilities.

Goroutines spawned from the passed function do not inherit the raised capabilities. Blocking in the passed function is allowed, but will block changes to the process' capability set.

Passing an empty list of capabilities will invoke fn without any privileges.

Types

This section is empty.

Jump to

Keyboard shortcuts

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