package tester
import "github.com/open-policy-agent/opa/tester"
Package tester contains utilities for executing Rego tests.
Index ¶
- Constants
- func Load(args []string, filter loader.Filter) (map[string]*ast.Module, storage.Store, error)
- type JSONCoverageReporter
- type JSONReporter
- type PrettyReporter
- type Reporter
- type Result
- func Run(ctx context.Context, paths ...string) ([]*Result, error)
- func RunWithFilter(ctx context.Context, filter loader.Filter, paths ...string) ([]*Result, error)
- func (r Result) Pass() bool
- func (r *Result) String() string
- type Runner
- func NewRunner() *Runner
- func (r *Runner) EnableFailureLine(yes bool) *Runner
- func (r *Runner) EnableTracing(yes bool) *Runner
- func (r *Runner) Run(ctx context.Context, modules map[string]*ast.Module) (ch chan *Result, err error)
- func (r *Runner) SetCompiler(compiler *ast.Compiler) *Runner
- func (r *Runner) SetCoverageTracer(tracer topdown.Tracer) *Runner
- func (r *Runner) SetRuntime(term *ast.Term) *Runner
- func (r *Runner) SetStore(store storage.Store) *Runner
Constants ¶
const TestPrefix = "test_"
TestPrefix declares the prefix for all rules.
Functions ¶
func Load ¶
Load returns modules and an in-memory store for running tests.
Types ¶
type JSONCoverageReporter ¶
type JSONCoverageReporter struct { Cover *cover.Cover Modules map[string]*ast.Module Output io.Writer Threshold float64 }
JSONCoverageReporter reports coverage as a JSON structure.
func (JSONCoverageReporter) Report ¶
func (r JSONCoverageReporter) Report(ch chan *Result) error
Report prints the test report to the reporter's output. If any tests fail or encounter errors, this function returns an error.
type JSONReporter ¶
JSONReporter reports test results as array of JSON objects.
func (JSONReporter) Report ¶
func (r JSONReporter) Report(ch chan *Result) error
Report prints the test report to the reporter's output.
type PrettyReporter ¶
PrettyReporter reports test results in a simple human readable format.
func (PrettyReporter) Report ¶
func (r PrettyReporter) Report(ch chan *Result) error
Report prints the test report to the reporter's output.
type Reporter ¶
type Reporter interface { // Report is called with a channel that will contain test results. Report(ch chan *Result) error }
Reporter defines the interface for reporting test results.
type Result ¶
type Result struct { Location *ast.Location `json:"location"` Package string `json:"package"` Name string `json:"name"` Fail bool `json:"fail,omitempty"` Error error `json:"error,omitempty"` Duration time.Duration `json:"duration"` Trace []*topdown.Event `json:"trace,omitempty"` FailedAt *ast.Expr `json:"failed_at,omitempty"` }
Result represents a single test case result.
func Run ¶
Run executes all test cases found under files in path.
func RunWithFilter ¶
RunWithFilter executes all test cases found under files in path. The filter will be applied to exclude files that should not be included.
func (Result) Pass ¶
Pass returns true if the test case passed.
func (*Result) String ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner implements simple test discovery and execution.
func NewRunner ¶
func NewRunner() *Runner
NewRunner returns a new runner.
func (*Runner) EnableFailureLine ¶
EnableFailureLine if set will provide the exact failure line
func (*Runner) EnableTracing ¶
EnableTracing enables tracing of evaluation and includes traces in results. Tracing is currently mutually exclusive with coverage.
func (*Runner) Run ¶
func (r *Runner) Run(ctx context.Context, modules map[string]*ast.Module) (ch chan *Result, err error)
Run executes all tests contained in supplied modules.
func (*Runner) SetCompiler ¶
SetCompiler sets the compiler used by the runner.
func (*Runner) SetCoverageTracer ¶
SetCoverageTracer sets the tracer to use to compute coverage.
func (*Runner) SetRuntime ¶
SetRuntime sets runtime information to expose to the evaluation engine.
func (*Runner) SetStore ¶
SetStore sets the store to execute tests over.
Source Files ¶
- Version
- v0.13.1
- Published
- Aug 14, 2019
- Platform
- js/wasm
- Imports
- 15 packages
- Last checked
- 2 hours ago –
Tools for package owners.