Run Rego tests
rego_testRun Rego unit tests with opa test, returning pass/fail counts and per-test records. Supports filtering tests by name regex, setting coverage thresholds, and verbose debugging with variable bindings.
Instructions
Run Rego unit tests with opa test. Returns aggregate pass/fail counts plus per-test records. Tests live in *_test.rego files; rule names beginning with test_ are picked up. Use runPattern to filter by name regex. Use threshold to gate on a minimum coverage percentage (returns COVERAGE_BELOW_THRESHOLD on failure). Use varValues: true with verbose: true to include local variable bindings in the trace -- essential for debugging table-driven tests written with every tc in cases { ... } to identify which case caused a failure. Note: enabling coverage or threshold switches OPA to coverage-report output mode -- per-test counts are unavailable but coverage and coveragePct fields are populated.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | Test directories or files. `opa test` looks for `*_test.rego` siblings of source files. | |
| verbose | No | Emit per-test pass/fail details. | |
| coverage | No | Include per-line coverage data. Switches output to coverage-report mode: test record counts are not available, but `coverage` and `coveragePct` fields are populated. | |
| runPattern | No | Run only tests whose names match this regular expression (passed as `--run`). | |
| threshold | No | Minimum coverage percentage required (0–100). Returns COVERAGE_BELOW_THRESHOLD when actual coverage falls below this value. Implicitly enables coverage-report output mode. | |
| varValues | No | Include local variable bindings in trace output (`--var-values`). When a table-driven test using `every tc in cases { ... }` fails, the trace shows which `tc` triggered the failure. Has no effect unless `verbose: true` is also set (OPA only emits trace entries in verbose mode). |