package cases
import "github.com/open-policy-agent/opa/v1/test/cases"
Package cases contains utilities for evaluation test cases.
Index ¶
Types ¶
type Set ¶
type Set struct {
Cases []TestCase `json:"cases"`
}
Set represents a collection of test cases.
func Load ¶
Load returns a set of built-in test cases.
func MustLoad ¶
MustLoad returns a set of built-in test cases or panics if an error occurs.
func (Set) Sorted ¶
Sorted returns a sorted copy of s.
type TestCase ¶
type TestCase struct {
Filename string `json:"-" yaml:"-"` // name of file that case was loaded from
Note string `json:"note" yaml:"note"` // globally unique identifier for this test case
Query string `json:"query" yaml:"query"` // policy query to execute
Modules []string `json:"modules,omitempty" yaml:"modules,omitempty"` // policies to test against
Data *map[string]any `json:"data,omitempty" yaml:"data,omitempty"` // data to test against
Input *any `json:"input,omitempty" yaml:"input,omitempty"` // parsed input data to use
InputTerm *string `json:"input_term,omitempty" yaml:"input_term,omitempty"` // raw input data (serialized as a string, overrides input)
WantDefined *bool `json:"want_defined,omitempty" yaml:"want_defined,omitempty"` // expect query result to be defined (or not)
WantResult *[]map[string]any `json:"want_result,omitempty" yaml:"want_result,omitempty"` // expect query result (overrides defined)
WantErrorCode *string `json:"want_error_code,omitempty" yaml:"want_error_code,omitempty"` // expect query error code (overrides result)
WantError *string `json:"want_error,omitempty" yaml:"want_error,omitempty"` // expect query error message (overrides error code)
SortBindings bool `json:"sort_bindings,omitempty" yaml:"sort_bindings,omitempty"` // indicates that binding values should be treated as sets
StrictError bool `json:"strict_error,omitempty" yaml:"strict_error,omitempty"` // indicates that the error depends on strict builtin error mode
Env map[string]string `json:"env,omitempty" yaml:"env,omitempty"` // environment variables to be set during the test
}
TestCase represents a single test case.
Source Files ¶
Directories ¶
| Path | Synopsis |
|---|---|
| v1/test/cases/internal |
- Version
- v1.7.1 (latest)
- Published
- Jul 31, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 8 months ago –
Tools for package owners.