Skip to content

Commit f4d02ff

Browse files
committed
feat: add explain and verbose attributes to opa_test
1 parent 7c6deb5 commit f4d02ff

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

MODULE.bazel.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ opa_test(
2828
name = "simple_test",
2929
size = "small",
3030
srcs = ["main_test.rego"],
31+
explain = "full",
3132
deps = [":simple"],
3233
)
3334

opa/private/opa_test.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ def _opa_test_impl(ctx):
1111

1212
runfiles = ctx.runfiles(files = [toolchain.opa, bundle] + ctx.files.srcs)
1313

14+
args = ["--explain", ctx.attr.explain]
15+
16+
if ctx.attr.verbose:
17+
args.append("--verbose")
18+
1419
ctx.actions.write(
1520
output = test_file,
16-
content = "%s test %s %s" % (toolchain.opa.short_path, bundle.short_path, " ".join([f.short_path for f in ctx.files.srcs])),
21+
content = "%s test %s %s" % (toolchain.opa.short_path, bundle.short_path, " ".join(args + [f.short_path for f in ctx.files.srcs])),
1722
is_executable = True,
1823
)
1924

@@ -37,6 +42,15 @@ opa_test = rule(
3742
providers = [OpaInfo],
3843
doc = "The bundle to test",
3944
),
45+
"explain": attr.string(
46+
values = ["fails", "full", "notes", "debug"],
47+
doc = "enable query explanations (default fails)",
48+
default = "fails",
49+
),
50+
"verbose": attr.bool(
51+
doc = "set verbose reporting mode",
52+
default = False,
53+
),
4054
},
4155
toolchains = ["//tools:toolchain_type"],
4256
)

0 commit comments

Comments
 (0)