Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAllPrerequisites(prereqs []Prerequisite) (bool, string)
- func CheckPrerequisite(p Prerequisite) bool
- func ExitCode(s Summary) int
- func FormatHuman(s Summary) string
- func FormatJSON(s Summary) (string, error)
- func RunAssertions(assertions []Assertion, output TestOutput) (passed, failed int, firstFailure string)
- type Assertion
- func AssertJSONPathEquals(key, expected string) Assertion
- func AssertJSONPathExists(key string) Assertion
- func AssertJSONValid() Assertion
- func AssertMetricFamiliesPresent(families []string) Assertion
- func AssertNoFatalPatterns(patterns []string) Assertion
- func AssertOutputContains(s string) Assertion
- type Prerequisite
- type RunOptions
- type SmokeTest
- type Summary
- type SummaryCounts
- type TestOutput
- type TestResult
Constants ¶
const ( PrereqBinary = "binary" PrereqFile = "file" PrereqSystemd = "systemd" PrereqDaemonRunning = "daemon_running" PrereqModuleEnabled = "module_enabled" PrereqHTTPEndpoint = "http_endpoint" PrereqValidatorBin = "validator_present" PrereqConfigKey = "config_key" PrereqNFTBinary = "nft_binary" )
Prerequisite types
const ( StatusPass = "PASS" StatusFail = "FAIL" StatusSkip = "SKIP" )
Status constants for test results.
Variables ¶
var DefaultFatalPatterns = []string{
"bad array subscript",
"unbound variable",
"syntax error",
"command not found",
"No such file or directory",
"panic:",
"segmentation fault",
"traceback",
"SIGSEGV",
"nil pointer dereference",
}
DefaultFatalPatterns are runtime errors that always indicate FAIL. These catch shell explosions, Go panics, and missing binaries.
Functions ¶
func CheckAllPrerequisites ¶ added in v1.95.0
func CheckAllPrerequisites(prereqs []Prerequisite) (bool, string)
CheckAllPrerequisites evaluates all prerequisites for a test. Returns the first unmet prerequisite name, or "" if all met.
func CheckPrerequisite ¶ added in v1.95.0
func CheckPrerequisite(p Prerequisite) bool
CheckPrerequisite evaluates a single prerequisite. Returns true if met, false if not (test should SKIP).
func ExitCode ¶
ExitCode returns the process exit code for a smoke summary. 0 = all PASS (SKIPs don't count as failure) 1 = any FAIL
func FormatHuman ¶
FormatHuman returns a human-readable smoke report.
func FormatJSON ¶
FormatJSON returns a JSON smoke report.
func RunAssertions ¶ added in v1.95.0
func RunAssertions(assertions []Assertion, output TestOutput) (passed, failed int, firstFailure string)
RunAssertions evaluates a list of assertions against test output. Returns counts and the name of the first failed assertion (if any).
Types ¶
type Assertion ¶ added in v1.95.0
type Assertion struct {
Name string
Fn func(TestOutput) bool
}
Assertion defines a named check on test output.
func AssertJSONPathEquals ¶ added in v1.95.0
AssertJSONPathEquals checks that a top-level JSON key has an expected string value.
func AssertJSONPathExists ¶ added in v1.95.0
AssertJSONPathExists checks that a top-level key exists in JSON stdout.
func AssertJSONValid ¶ added in v1.95.0
func AssertJSONValid() Assertion
AssertJSONValid checks that stdout is valid JSON.
func AssertMetricFamiliesPresent ¶ added in v1.95.0
AssertMetricFamiliesPresent checks that key metric families appear in /metrics output.
func AssertNoFatalPatterns ¶ added in v1.95.0
AssertNoFatalPatterns checks output against fatal runtime patterns.
func AssertOutputContains ¶ added in v1.95.0
AssertOutputContains checks that stdout contains a substring.
type Prerequisite ¶
type Prerequisite struct {
Type string // "daemon", "file", "binary"
Name string // e.g. "nftband.service", "/etc/nftban/main.conf", "nftban-validate"
}
Prerequisite defines a condition that must be true for a test to run. If not met, the test is SKIP (not FAIL).
type RunOptions ¶ added in v1.95.0
type RunOptions struct {
Group string // truth, daemon, config, metrics, modules, deep, all
Module string // filter by specific module (ddos, portscan, etc.)
Deep bool // include DeepOnly tests
}
RunOptions controls smoke execution filtering.
type SmokeTest ¶
type SmokeTest struct {
ID string
Name string
Category string // truth, daemon, config, metrics, modules, deep
Module string // "", "ddos", "portscan", "botguard", "loginmon"
Command []string // command + args to execute
AllowedExit []int // exit codes that count as PASS (e.g. [0,1,2])
Timeout time.Duration
Prerequisites []Prerequisite
FatalPatterns []string // stderr/stdout patterns that force FAIL
Assert func(TestOutput) bool // v1.94 simple assertion (kept for compat)
Assertions []Assertion // v1.95 structured assertions
DeepOnly bool // only run with --deep flag
CIEnabled bool // included in G20 CI gate
Notes string
}
SmokeTest defines a single registered smoke probe. All test execution is driven by this metadata — no ad hoc logic outside the registry.
func DefaultRegistry ¶
func DefaultRegistry() []SmokeTest
DefaultRegistry returns the full smoke test set (Phase 1 + Phase 2). Phase 1: truth, daemon, config, metrics (always run) Phase 2: modules (gated on prerequisites, SKIP if disabled)
func ModuleTests ¶ added in v1.95.0
func ModuleTests() []SmokeTest
ModuleTests returns the Phase 2 module-aware smoke test set. Each test is gated on module_enabled prerequisite — SKIP if disabled. These do NOT claim enforcement or protection — only that commands run and produce contract-safe output.
type Summary ¶
type Summary struct {
Version string `json:"version"`
Result string `json:"result"` // PASS or FAIL
Counts SummaryCounts `json:"summary"`
Tests []TestResult `json:"tests"`
}
Summary holds the overall smoke run result.
func RunSmoke ¶
func RunSmoke(version string, opts RunOptions) Summary
RunSmoke executes all registered tests, filtered by options. Returns a Summary with PASS/FAIL/SKIP per test.
type SummaryCounts ¶
SummaryCounts holds pass/fail/skip counts.
type TestOutput ¶
TestOutput holds captured output from a test execution.
type TestResult ¶
type TestResult struct {
ID string `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
Status string `json:"status"` // PASS, FAIL, SKIP
DurationMs int64 `json:"duration_ms"`
Detail string `json:"detail,omitempty"`
}
TestResult holds the outcome of a single smoke test.