Run the "bats" tests for deps/rabbit in bazel

This commit is contained in:
Philip Kuryloski 2021-05-14 10:39:03 +02:00
parent 7d7e6eafec
commit 6d59d5d597
4 changed files with 57 additions and 0 deletions

5
BUILD.bats Normal file
View File

@ -0,0 +1,5 @@
filegroup(
name = "bin_dir",
srcs = glob(["bin/**/*", "libexec/**/*"]),
visibility = ["//visibility:public"],
)

View File

@ -9,6 +9,7 @@ load(
"rabbitmq_lib",
"rabbitmq_suite",
)
load(":bats.bzl", "bats")
exports_files([
"scripts/rabbitmq-defaults",
@ -205,6 +206,14 @@ rabbitmq_lib(
deps = DEPS,
)
bats(
srcs = glob(["test/**/*.bats"]),
data = glob(
["scripts/*"],
exclude = ["scripts/*.bat"],
),
)
rabbitmq_home(
name = "broker-for-tests-home",
testonly = True,

36
deps/rabbit/bats.bzl vendored Normal file
View File

@ -0,0 +1,36 @@
def _impl(ctx):
script = """set -euo pipefail
external/bats/bin/bats {test_files}
""".format(
package_dir = ctx.label.package,
test_files = " ".join([t.short_path for t in ctx.files.srcs]),
)
ctx.actions.write(
output = ctx.outputs.executable,
content = script,
)
runfiles = ctx.runfiles(ctx.files.bats + ctx.files.srcs + ctx.files.data)
return [DefaultInfo(runfiles = runfiles)]
bats_test = rule(
implementation = _impl,
attrs = {
"bats": attr.label(),
"srcs": attr.label_list(
allow_files = [".bats"],
mandatory = True,
),
"data": attr.label_list(allow_files = True),
},
test = True,
)
def bats(**kwargs):
bats_test(
name = "bats",
bats = "@bats//:bin_dir",
**kwargs
)

View File

@ -19,6 +19,13 @@ def rabbitmq_external_deps(rabbitmq_workspace = "@rabbitmq-server"):
version = "0.5.6",
)
new_git_repository(
name = "bats",
remote = "https://github.com/sstephenson/bats",
tag = "v0.4.0",
build_file = rabbitmq_workspace + "//:BUILD.bats",
)
hex_pm_bazel_erlang_lib(
name = "cowboy",
first_srcs = [