package tester

import "github.com/open-policy-agent/opa/tester"

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Package tester contains utilities for executing Rego tests.

Index

Constants

const SkipTestPrefix = v1.SkipTestPrefix

SkipTestPrefix declares the prefix for tests that should be skipped.

const TestPrefix = v1.TestPrefix

TestPrefix declares the prefix for all test rules.

Functions

func Load

func Load(args []string, filter loader.Filter) (map[string]*ast.Module, storage.Store, error)

Load returns modules and an in-memory store for running tests.

func LoadBundles

func LoadBundles(args []string, filter loader.Filter) (map[string]*bundle.Bundle, error)

LoadBundles will load the given args as bundles, either tarball or directory is OK.

func LoadBundlesWithRegoVersion

func LoadBundlesWithRegoVersion(args []string, filter loader.Filter, regoVersion ast.RegoVersion) (map[string]*bundle.Bundle, error)

LoadBundlesWithRegoVersion will load the given args as bundles, either tarball or directory is OK. Bundles are parsed in accordance with the given RegoVersion.

func LoadWithRegoVersion

func LoadWithRegoVersion(args []string, filter loader.Filter, regoVersion ast.RegoVersion) (map[string]*ast.Module, storage.Store, error)

LoadWithRegoVersion returns modules and an in-memory store for running tests. Modules are parsed in accordance with the given RegoVersion.

Types

type BenchmarkOptions

type BenchmarkOptions = v1.BenchmarkOptions

BenchmarkOptions defines options specific to benchmarking tests

type Builtin

type Builtin = v1.Builtin

type JSONCoverageReporter

type JSONCoverageReporter = v1.JSONCoverageReporter

JSONCoverageReporter reports coverage as a JSON structure.

type JSONReporter

type JSONReporter = v1.JSONReporter

JSONReporter reports test results as array of JSON objects.

type PrettyReporter

type PrettyReporter = v1.PrettyReporter

PrettyReporter reports test results in a simple human readable format.

type Reporter

type Reporter = v1.Reporter

Reporter defines the interface for reporting test results.

type Result

type Result = v1.Result

Result represents a single test case result.

func Run

func Run(ctx context.Context, paths ...string) ([]*Result, error)

Run executes all test cases found under files in path.

func RunWithFilter

func RunWithFilter(ctx context.Context, _ loader.Filter, paths ...string) ([]*Result, error)

RunWithFilter executes all test cases found under files in path. The filter will be applied to exclude files that should not be included.

type Runner

type Runner = v1.Runner

Runner implements simple test discovery and execution.

func NewRunner

func NewRunner() *Runner

NewRunner returns a new runner.

Source Files

doc.go reporter.go runner.go

Version
v1.4.2 (latest)
Published
May 2, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
4 hours ago

Tools for package owners.