testcmd

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testcmd implements the `mkit test` subcommand: declarative fixture testing for Datalog policies without writing Go code.

Index

Constants

This section is empty.

Variables

View Source
var TestCmd = &cobra.Command{
	Use:   "test [flags] <test-file>",
	Short: "Run declarative unit test fixtures against a Datalog policy",
	Long: `Run declarative unit test fixtures against a Datalog policy.

Test fixtures can be defined in YAML or JSON, asserting that specific facts
and actions produce expected allow/halt decisions, matched rules, and tiers.

Exit codes follow the mkit contract:
  0  all tests passed
  1  one or more policy tests failed
  2  usage/flag error
  3  runtime/file error`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		testFilePath := args[0]
		return RunTests(cmd.Context(), testFilePath, policyFlag, verbose, outputFmt, cmd)
	},
}

Functions

func AddCommands

func AddCommands(rootCmd *cobra.Command)

func RunTests

func RunTests(ctx context.Context, testFilePath, overridePolicy string, verbose bool, output string, cmd *cobra.Command) error

RunTests executes the suite against the resolved policy.

Types

type FixtureSuite

type FixtureSuite struct {
	Policy string     `yaml:"policy" json:"policy"`
	Tests  []TestCase `yaml:"tests" json:"tests"`
}

FixtureSuite represents a collection of declarative policy test cases.

type SuiteReport

type SuiteReport struct {
	PolicyPath string       `json:"policy_path"`
	Total      int          `json:"total"`
	Passed     int          `json:"passed"`
	Failed     int          `json:"failed"`
	DurationMs int64        `json:"duration_ms"`
	Results    []TestResult `json:"results"`
}

type TestCase

type TestCase struct {
	Name           string   `yaml:"name" json:"name"`
	Action         string   `yaml:"action,omitempty" json:"action,omitempty"`
	Facts          []string `yaml:"facts" json:"facts"`
	Query          string   `yaml:"query,omitempty" json:"query,omitempty"`
	Expect         string   `yaml:"expect" json:"expect"` // "halt", "deny", "allow", "pass"
	ExpectedReason string   `yaml:"expected_reason,omitempty" json:"expected_reason,omitempty"`
	ExpectedTier   string   `yaml:"expected_tier,omitempty" json:"expected_tier,omitempty"`
}

TestCase represents an individual policy assertion.

type TestFailureError

type TestFailureError struct {
	FailedCount int
	TotalCount  int
}

func (*TestFailureError) Error

func (e *TestFailureError) Error() string

func (*TestFailureError) Is

func (e *TestFailureError) Is(target error) bool

type TestResult

type TestResult struct {
	Name           string `json:"name"`
	Passed         bool   `json:"passed"`
	Error          string `json:"error,omitempty"`
	ProofTree      string `json:"proof_tree,omitempty"`
	DurationMicros int64  `json:"duration_micros"`
}

Jump to

Keyboard shortcuts

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