testutil

package
v0.0.0-...-daad6bc Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testutil contains helper functions used in network tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IP6tablesRestore

func IP6tablesRestore(tb testing.TB, state []byte)

IP6tablesRestore restores iptables state from a file

func IP6tablesSave

func IP6tablesSave(tb testing.TB)

IP6tablesSave saves the current iptables state to a file and returns its path

func IptablesRestore

func IptablesRestore(tb testing.TB, state []byte)

IptablesRestore restores iptables state from a file

func IptablesSave

func IptablesSave(tb testing.TB) []byte

IptablesSave saves the current iptables state to a file and returns its path

func MustPingTCP

func MustPingTCP(tb require.TestingT, ip net.IP, port int) net.Conn

MustPingTCP is a wrapper around PingTCP that guarantees a non-nil connection is returned

func MustPingUDP

func MustPingUDP(tb require.TestingT, ip net.IP, port int) net.Conn

MustPingUDP is a wrapper around PingUDP that guarantees a non-nil connection is returned

func PingTCP

func PingTCP(tb require.TestingT, ip net.IP, port int) net.Conn

PingTCP connects to the provided IP address over TCP/TCPv6, sends the string "ping", reads from the connection, and returns the open connection for further use/inspection.

func PingUDP

func PingUDP(tb require.TestingT, ip net.IP, port int) net.Conn

PingUDP connects to the provided IP address over UDP/UDPv6, sends the string "ping", and returns the open connection for further use/inspection.

func RunCommand

func RunCommand(cmd string) (string, error)

RunCommand runs a single command

func RunCommandWithContext

func RunCommandWithContext(ctx context.Context, cmd string) (string, error)

RunCommandWithContext runs a single command with the given context

func RunCommands

func RunCommands(tb testing.TB, cmds []string, ignoreErrors bool) []string

RunCommands runs each command in cmds individually and returns the output as a []string, with each element corresponding to the respective command. If ignoreErrors is false, it will fail the test via t.Fatal immediately upon error. Otherwise, the output on errors will be logged via t.Log.

func StartCommandCtx

func StartCommandCtx(ctx context.Context, cmd string) (*exec.Cmd, io.WriteCloser, error)

StartCommandCtx Runs a command with the given context, returning a handle to the command and its input stream.

func StartServerTCP

func StartServerTCP(t testing.TB, ip net.IP, port int) io.Closer

StartServerTCP starts a TCP server listening at provided IP address and port. It will respond to any connection with "hello" and then close the connection. It returns an io.Closer that should be Close'd when you are finished with it.

func StartServerTCPNs

func StartServerTCPNs(t testing.TB, ip net.IP, port int, ns string) io.Closer

StartServerTCPNs is identical to StartServerTCP, but it operates with the network namespace provided by name.

func StartServerUDP

func StartServerUDP(t *testing.T, ip net.IP, port int) io.Closer

StartServerUDP starts a UDP server listening at provided IP address and port. It does not respond in any fashion to sent datagrams. It returns an io.Closer that should be Close'd when you are finished with it.

func StartServerUDPNs

func StartServerUDPNs(t *testing.T, ip net.IP, port int, ns string) io.Closer

StartServerUDPNs is identical to StartServerUDP, but it operates with the network namespace provided by name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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