Documentation
¶
Overview ¶
Package testutil provides shared test utilities and fixtures for NFTBan tests.
Index ¶
- Constants
- Variables
- func AssertEqual[T comparable](t *testing.T, got, want T)
- func AssertError(t *testing.T, err error)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertNoError(t *testing.T, err error)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func ContainsString(slice []string, s string) bool
- func InvalidIPs() []string
- func InvalidPorts() []int
- func ReadTestFile(t *testing.T, path string) string
- func SampleCIDRList(n int) []string
- func SampleIPv4List(n int) []string
- func StringSliceEqual(a, b []string) bool
- func TempDir(t *testing.T) string
- func WriteTestFile(t *testing.T, dir, name, content string) string
Constants ¶
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)
const ( TestLoopback4 = "127.0.0.1" TestBroadcast = "255.255.255.255" TestZeroIP = "0.0.0.0" )
Loopback and special addresses
const ( TestPrivate10 = "10.0.0.1" TestPrivate172 = "172.16.0.1" TestPrivate192 = "192.168.1.1" )
Private range addresses (RFC 1918)
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 )
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" )
const ( TestPortSSH = 22 TestPortHTTP = 80 TestPortHTTPS = 443 TestPortHigh = 55000 TestPortMax = 65535 )
const ( TestReasonBruteForce = "brute-force" TestReasonFeedMatch = "threat-feed" TestReasonPortScan = "port-scan" TestReasonDDoS = "ddos" TestReasonManual = "manual" )
Variables ¶
var TestAllowedCountries = []string{"US", "GB", "DE", "FR"}
var TestBlockedCountries = []string{"CN", "RU", "KP"}
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 ¶
AssertError fails the test if err is nil.
func AssertFalse ¶
AssertFalse fails the test if condition is true.
func AssertNoError ¶
AssertNoError fails the test if err is not nil.
func AssertTrue ¶
AssertTrue fails the test if condition is false.
func ContainsString ¶
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 ¶
ReadTestFile reads the content of a file as a string, failing the test on error.
func SampleCIDRList ¶
SampleCIDRList returns a list of test CIDR ranges for batch operations.
func SampleIPv4List ¶
SampleIPv4List returns a list of test IPv4 addresses for batch operations.
func StringSliceEqual ¶
StringSliceEqual checks if two string slices are equal (order matters).
Types ¶
This section is empty.