Skip to content

Commit

Permalink
feat: add explain and verbose attributes to opa_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ffortier committed Apr 2, 2024
1 parent da540fe commit 8fb76ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
30 changes: 15 additions & 15 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/simple/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ opa_test(
name = "simple_test",
size = "small",
srcs = ["main_test.rego"],
explain = "full",
deps = [":simple"],
)

Expand Down
16 changes: 15 additions & 1 deletion opa/private/opa_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ def _opa_test_impl(ctx):

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

args = ["--explain", ctx.attr.explain]

if ctx.attr.verbose:
args.append("--verbose")

ctx.actions.write(
output = test_file,
content = "%s test %s %s" % (toolchain.opa.short_path, bundle.short_path, " ".join([f.short_path for f in ctx.files.srcs])),
content = "%s test %s %s" % (toolchain.opa.short_path, bundle.short_path, " ".join(args + [f.short_path for f in ctx.files.srcs])),
is_executable = True,
)

Expand All @@ -37,6 +42,15 @@ opa_test = rule(
providers = [OpaInfo],
doc = "The bundle to test",
),
"explain": attr.string(
values = ["fails", "full", "notes", "debug"],
doc = "enable query explanations (default fails)",
default = "fails",
),
"verbose": attr.bool(
doc = "set verbose reporting mode",
default = False,
),
},
toolchains = ["//tools:toolchain_type"],
)

0 comments on commit 8fb76ad

Please sign in to comment.