Help us shape the future of Go! Take the 2026 Go Developer Survey

ruletest

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package ruletest provides a Starlark-based test runner for Minder rule types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JUnitFailure

type JUnitFailure struct {
	Message string `xml:"message,attr"`
	Type    string `xml:"type,attr,omitempty"`
	Body    string `xml:",chardata"`
}

JUnitFailure represents a failure within a test case.

type JUnitTestCase

type JUnitTestCase struct {
	Name      string `xml:"name,attr"`
	ClassName string `xml:"classname,attr"`

	Failure   *JUnitFailure `xml:"failure,omitempty"`
	Error     *JUnitFailure `xml:"error,omitempty"`
	Skipped   *JUnitFailure `xml:"skipped,omitempty"`
	SystemOut *Output       `xml:"system-out,omitempty"`
	SystemErr *Output       `xml:"system-err,omitempty"`
}

JUnitTestCase represents a single test case in a JUnit XML report.

type JUnitTestSuite

type JUnitTestSuite struct {
	Name     string `xml:"name,attr"`
	Tests    int    `xml:"tests,attr"`
	Errors   int    `xml:"errors,attr"`
	Failures int    `xml:"failures,attr"`
	Skipped  int    `xml:"skipped,attr,omitempty"`
	Disabled int    `xml:"disabled,attr,omitempty"`

	File string `xml:"file,attr,omitempty"`

	Properties *[]Property `xml:"properties>property,omitempty"`

	TestCases []JUnitTestCase `xml:"testcase"`
}

JUnitTestSuite represents a single test suite in a JUnit XML report.

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName  xml.Name `xml:"testsuites"`
	Tests    int      `xml:"tests,attr,omitempty"`
	Errors   int      `xml:"errors,attr,omitempty"`
	Failures int      `xml:"failures,attr,omitempty"`
	Skipped  int      `xml:"skipped,attr,omitempty"`
	Disabled int      `xml:"disabled,attr,omitempty"`

	TestSuites []JUnitTestSuite `xml:"testsuite"`
}

JUnitTestSuites is the root element of a JUnit XML report.

func AsJUnit

func AsJUnit(results []TestRun) JUnitTestSuites

AsJUnit converts test results into a JUnitTestSuites structure.

type MockResponse

type MockResponse struct {
	StatusCode int
	Body       string
}

MockResponse represents a mocked HTTP response in Starlark. It is the expected value type for the dictionary provided to the mock_http parameter in eval().

func (*MockResponse) Attr

func (m *MockResponse) Attr(name string) (starlark.Value, error)

Attr retrieves the attribute for Starlark.

func (*MockResponse) AttrNames

func (*MockResponse) AttrNames() []string

AttrNames returns the list of attribute names.

func (*MockResponse) Freeze

func (*MockResponse) Freeze()

Freeze makes the value immutable.

func (*MockResponse) Hash

func (*MockResponse) Hash() (uint32, error)

Hash returns a hash value for the mock response.

func (*MockResponse) String

func (m *MockResponse) String() string

func (*MockResponse) Truth

func (*MockResponse) Truth() starlark.Bool

Truth returns the truth value of the mock response.

func (*MockResponse) Type

func (*MockResponse) Type() string

Type returns the Starlark type name.

type Output added in v0.3.2

type Output struct {
	Body string `xml:",cdata"`
}

Output represents the text output from a test case (currently not captured).

type Property added in v0.3.2

type Property struct {
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

Property represents a key-value pair in a JUnit XML report (used for coverage).

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner loads and executes Starlark test files.

func NewRunner

func NewRunner() *Runner

NewRunner creates a new test runner.

func (*Runner) RunFile

func (r *Runner) RunFile(filename string, src any, ruleTypes map[string]*minderv1.RuleType) ([]TestResult, error)

RunFile executes a single Starlark test file and returns the results for each test_* function found in it.

filename is the path to the *.star file. If src is nil, the file is read from disk; otherwise src may be a string, []byte, or io.Reader containing the Starlark source. ruleTypes supplies the rule type definitions available to eval() calls within the test file.

func (*Runner) RunPaths

func (r *Runner) RunPaths(paths []string) ([]TestRun, error)

RunPaths takes a list of file or directory paths, discovering all *.star test files recursively. Tests are grouped by their immediate directory, and any *.yaml rules in that same directory are loaded and made available to the tests. It collects errors instead of returning early on the first error.

type TestResult

type TestResult struct {
	Filename string
	Name     string
	Failures []string
	Errors   []string

	// EvaluatedRules is a set of rule names that were evaluated during the test.
	EvaluatedRules map[string]struct{}
}

TestResult holds the outcome of a single Starlark test function.

func (*TestResult) Passed

func (tr *TestResult) Passed() bool

Passed returns true if the test had no failures.

type TestRun added in v0.3.2

type TestRun struct {
	// BaseDir is the directory from which the test run was initiated.
	BaseDir string
	// LoadedRules is a list of rule names that were loaded from disk for the run.
	LoadedRules []string
	// Results is a list of test results for each test function executed.
	Results []TestResult
}

TestRun represents a run of all the tests in a given directory.

func (*TestRun) UncoveredRules added in v0.3.2

func (tr *TestRun) UncoveredRules() []string

UncoveredRules returns a list of rule names that were loaded but not evaluated during the test run.

Jump to

Keyboard shortcuts

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