testutils

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testutils provides utility code needed by multiple packages' test suites, but which should not be referenced in any non-test code.

Index

Constants

This section is empty.

Variables

View Source
var CIScaleFactor int

CIScaleFactor is an approximate scaling factor by which to multiply time deadlines in performance-sensitive tests to compensate for the running system being slower than the reference system.

View Source
var CIScaleFactorDuration time.Duration

CIScaleFactorDuration is just CIScaleFactor cast to a time.Duration for simplicity.

View Source
var CIScaleMs time.Duration // nolint:revive,stylecheck // this is like `time.Millisecond`

CIScaleMs is time.Millisecond * CIScaleFactor

View Source
var Rand *rand.Rand

Rand is a per-run initialized non-crypto RNG

Functions

func CaptureOutput added in v0.10.0

func CaptureOutput(t *testing.T, f func()) []byte

CaptureOutput runs f with os.Stdout redirected to a temp file, and then re-reads everything that is written and returns it

func ContainsIPNet added in v0.8.2

func ContainsIPNet(addrs []net.IPNet, predicate func(net.IPNet) bool) bool

ContainsIPNet runs a predicate across a net.IPNet slice and returns if any match was found

func MakeIPv4Net added in v0.8.1

func MakeIPv4Net(a, b, c, d byte, ones int) net.IPNet

MakeIPv4Net creates a net.IPNet with the given address and CIDR mask length

func MakeIPv6 added in v0.8.1

func MakeIPv6(left, right []byte) net.IP

MakeIPv6 helps build IPv6 values in a similar method to how the "::" marker in an IPv6 literal works

func MakeIPv6Net added in v0.8.1

func MakeIPv6Net(left, right []byte, ones int) net.IPNet

MakeIPv6Net uses MakeIPv6 to create a net.IPNet with the built IP and the given CIDR mask length

func MustKey

func MustKey(t require.TestingT) (key wgtypes.Key)

MustKey uses MustRandBytes to generate a random (not crypto-valid) key

func MustKeyPair

func MustKeyPair(t require.TestingT) (privateKey, publicKey wgtypes.Key)

MustKeyPair generates a real pair of private and public keys, panicing (via require) if this fails

func MustParseKey added in v0.9.1

func MustParseKey(t require.TestingT, s string) wgtypes.Key

MustParseKey parses the string version of a wireguard key, panicing via require if it fails, returning the parsed key otherwise

func MustRandBytes

func MustRandBytes(t require.TestingT, data []byte) []byte

MustRandBytes fills the given slice with random bytes using rand.Read

func RandIPNet added in v0.8.1

func RandIPNet(t *testing.T, size int, left, right []byte, ones int) net.IPNet

RandIPNet generates a random IPNet of the given size, and with optional fixed left/right bytes, and with the given CIDR prefix length

func RandUDP4Addr added in v0.8.1

func RandUDP4Addr(t *testing.T) *net.UDPAddr

RandUDP4Addr generates a random IPv4 UDP address for test purposes

func RandUDP6Addr added in v0.8.1

func RandUDP6Addr(t *testing.T) *net.UDPAddr

RandUDP6Addr generates a random IPv6 UDP address for test purposes

func SrcDirectory added in v0.10.0

func SrcDirectory() string

SrcDirectory uses the call stack to compute the directory of the caller's source file.

Types

This section is empty.

Directories

Path Synopsis
Package facts provides helper code for generating facts for use in unit tests.
Package facts provides helper code for generating facts for use in unit tests.

Jump to

Keyboard shortcuts

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