smoke

package
v1.107.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const (
	StatusPass = "PASS"
	StatusFail = "FAIL"
	StatusSkip = "SKIP"
)

Status constants for test results.

Variables

View Source
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

func ExitCode(s Summary) int

ExitCode returns the process exit code for a smoke summary. 0 = all PASS (SKIPs don't count as failure) 1 = any FAIL

func FormatHuman

func FormatHuman(s Summary) string

FormatHuman returns a human-readable smoke report.

func FormatJSON

func FormatJSON(s Summary) (string, error)

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

func AssertJSONPathEquals(key, expected string) Assertion

AssertJSONPathEquals checks that a top-level JSON key has an expected string value.

func AssertJSONPathExists added in v1.95.0

func AssertJSONPathExists(key string) Assertion

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

func AssertMetricFamiliesPresent(families []string) Assertion

AssertMetricFamiliesPresent checks that key metric families appear in /metrics output.

func AssertNoFatalPatterns added in v1.95.0

func AssertNoFatalPatterns(patterns []string) Assertion

AssertNoFatalPatterns checks output against fatal runtime patterns.

func AssertOutputContains added in v1.95.0

func AssertOutputContains(s string) Assertion

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

type SummaryCounts struct {
	Pass int `json:"pass"`
	Fail int `json:"fail"`
	Skip int `json:"skip"`
}

SummaryCounts holds pass/fail/skip counts.

type TestOutput

type TestOutput struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Duration time.Duration
}

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.

Jump to

Keyboard shortcuts

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