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"`
}
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"`
Failures int `xml:"failures,attr"`
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"`
TestSuites []JUnitTestSuite `xml:"testsuite"`
}
JUnitTestSuites is the root element of a JUnit XML report.
func AsJUnit ¶
func AsJUnit(results []TestResult) JUnitTestSuites
AsJUnit converts test results into a JUnitTestSuites structure.
type MockResponse ¶
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) 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.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner loads and executes Starlark test files.
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) ([]TestResult, 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 ¶
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.