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 ¶
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 ¶
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 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 ¶
func (*TestFailureError) Error ¶
func (e *TestFailureError) Error() string
func (*TestFailureError) Is ¶
func (e *TestFailureError) Is(target error) bool