testutil

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities and fixtures for NFTBan tests.

Index

Constants

View Source
const (
	TestIPv4_1 = "192.0.2.1"     // TEST-NET-1
	TestIPv4_2 = "198.51.100.1"  // TEST-NET-2
	TestIPv4_3 = "203.0.113.1"   // TEST-NET-3
	TestIPv4_4 = "192.0.2.100"   // TEST-NET-1 another
	TestIPv4_5 = "198.51.100.50" // TEST-NET-2 another
)

Well-known test IPs (RFC 5737 documentation ranges)

View Source
const (
	TestLoopback4 = "127.0.0.1"
	TestBroadcast = "255.255.255.255"
	TestZeroIP    = "0.0.0.0"
)

Loopback and special addresses

View Source
const (
	TestPrivate10  = "10.0.0.1"
	TestPrivate172 = "172.16.0.1"
	TestPrivate192 = "192.168.1.1"
)

Private range addresses (RFC 1918)

View Source
const (
	TestIPv6_1      = "2001:db8::1"   // Documentation range
	TestIPv6_2      = "2001:db8::2"   // Documentation range
	TestIPv6_3      = "2001:db8:1::1" // Documentation range
	TestLoopback6   = "::1"           // IPv6 loopback
	TestIPv6LinkLoc = "fe80::1"       // Link-local
)
View Source
const (
	TestCIDR4_24 = "192.0.2.0/24"
	TestCIDR4_16 = "10.0.0.0/16"
	TestCIDR4_32 = "192.0.2.1/32"
	TestCIDR6_64 = "2001:db8::/64"
	TestCIDR6_48 = "2001:db8::/48"
)
View Source
const (
	TestPortSSH   = 22
	TestPortHTTP  = 80
	TestPortHTTPS = 443
	TestPortHigh  = 55000
	TestPortMax   = 65535
)
View Source
const (
	TestReasonBruteForce = "brute-force"
	TestReasonFeedMatch  = "threat-feed"
	TestReasonPortScan   = "port-scan"
	TestReasonDDoS       = "ddos"
	TestReasonManual     = "manual"
)

Variables

View Source
var TestAllowedCountries = []string{"US", "GB", "DE", "FR"}
View Source
var TestBlockedCountries = []string{"CN", "RU", "KP"}
View Source
var TestCountries = []string{"CN", "RU", "BR", "IN", "US"}

Functions

func AssertEqual

func AssertEqual[T comparable](t *testing.T, got, want T)

AssertEqual fails if got != want (for comparable types).

func AssertError

func AssertError(t *testing.T, err error)

AssertError fails the test if err is nil.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse fails the test if condition is true.

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError fails the test if err is not nil.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue fails the test if condition is false.

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString checks if a string slice contains the given element.

func InvalidIPs

func InvalidIPs() []string

InvalidIPs returns a list of malformed IP strings for negative testing.

func InvalidPorts

func InvalidPorts() []int

InvalidPorts returns a list of invalid port numbers for negative testing.

func ReadTestFile

func ReadTestFile(t *testing.T, path string) string

ReadTestFile reads the content of a file as a string, failing the test on error.

func SampleCIDRList

func SampleCIDRList(n int) []string

SampleCIDRList returns a list of test CIDR ranges for batch operations.

func SampleIPv4List

func SampleIPv4List(n int) []string

SampleIPv4List returns a list of test IPv4 addresses for batch operations.

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual checks if two string slices are equal (order matters).

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory for testing that is cleaned up automatically.

func WriteTestFile

func WriteTestFile(t *testing.T, dir, name, content string) string

WriteTestFile creates a file in the given directory with the specified content.

Types

This section is empty.

Jump to

Keyboard shortcuts

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