scenario

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package scenario provides a tiny, dependency-free test harness for running behavior-driven policy scenarios against a Manglekit client.

A Scenario bundles a human-readable Name, a Run function that exercises the system under test, and an expectation about whether that run should be blocked (a non-nil error) or allowed (a nil error). Run executes every scenario and reports failures via t.Error-equivalent logging so it can be driven from a normal main or a test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMain

func RunMain(ctx context.Context, scenarios []Scenario)

RunMain executes the scenarios and, if any fail, prints a summary and exits with a non-zero status so CI catches the regression. It is intended to be called from a package main.

Types

type Result

type Result struct {
	Scenario Scenario
	Passed   bool
	Err      error
}

Result summarizes the outcome of a single scenario execution.

func Run

func Run(ctx context.Context, scenarios []Scenario) []Result

Run executes each scenario in order with the provided context. It returns a slice with one Result per scenario. A scenario passes when its outcome matches the declared expectation:

  • WantBlocked: Run must return a non-nil error.
  • WantAllowed: Run must return a nil error.
  • neither set: Run must return a nil error (fail-closed default).

Run never aborts early; every scenario is executed so a single failing scenario does not mask the rest.

type Scenario

type Scenario struct {
	// Name is a human-readable label printed for the scenario.
	Name string

	// Run exercises the system under test and returns an error if the
	// scenario's own internal assertions fail. For policy-gated flows,
	// Run typically calls into the engine and returns an error when the
	// observed outcome differs from the expected one.
	Run func(ctx context.Context) error

	// WantBlocked asserts that Run returns a non-nil error (the action was
	// halted/blocked by policy).
	WantBlocked bool

	// WantAllowed asserts that Run returns a nil error (the action was
	// permitted by policy).
	WantAllowed bool
}

Scenario describes a single behavior-driven check.

Exactly one of WantBlocked/WantAllowed should normally be set to assert the expected outcome of Run. If neither is set, Run is executed and any error is treated as a failure (fail-closed by default).

Jump to

Keyboard shortcuts

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