-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor so that clients do not require `cgrindel_bazel_starli…
…b` (#236) - Remove dependency on `cgrindel_bazel_starlib` in `bazel_integration_test`. - Convert `default_test_runner` from a macro to a rule. - Add an e2e test that confirms that `rules_bazel_integration_test` can be used without requiring any additional dependencies. Closes #234.
- Loading branch information
Showing
22 changed files
with
2,407 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,54 @@ | ||
"""Defines the default test runner for integration tests.""" | ||
|
||
load("@cgrindel_bazel_starlib//shlib/rules:execute_binary.bzl", "execute_binary") | ||
load( | ||
"@cgrindel_bazel_starlib//shlib/rules:execute_binary.bzl", | ||
"execute_binary_utils", | ||
) | ||
load(":integration_test_utils.bzl", "integration_test_utils") | ||
|
||
def default_test_runner( | ||
name, | ||
bazel_cmds = integration_test_utils.DEFAULT_BAZEL_CMDS, | ||
**kwargs): | ||
"""Macro that defines a test runner that executes a set of Bazel commands against a workspace. | ||
def _default_test_runner_impl(ctx): | ||
if len(ctx.attr.args) > 0: | ||
fail("""\ | ||
The args attribute is not supported. Use the bazel_cmds instead.\ | ||
""") | ||
|
||
Args: | ||
name: The name for the integration runner instance. | ||
bazel_cmds: A `list` of `string` values that represent arguments for | ||
Bazel. | ||
**kwargs: attributes that are passed to the `sh_binary` target. | ||
""" | ||
test_runner_args = [] | ||
for cmd in ctx.attr.bazel_cmds: | ||
test_runner_args.extend(["--bazel_cmd", cmd]) | ||
|
||
# Prepare the Bazel commands | ||
args = [] | ||
for cmd in bazel_cmds: | ||
args.extend(["--bazel_cmd", cmd]) | ||
|
||
# Define the shell binary | ||
binary_name = name + "_binary" | ||
native.sh_binary( | ||
name = binary_name, | ||
srcs = [ | ||
"@rules_bazel_integration_test//bazel_integration_test/private:default_test_runner.sh", | ||
], | ||
deps = [ | ||
"@bazel_tools//tools/bash/runfiles", | ||
"@cgrindel_bazel_starlib//shlib/lib:messages", | ||
], | ||
args = args, | ||
**kwargs | ||
out = ctx.actions.declare_file(ctx.label.name + ".sh") | ||
execute_binary_utils.write_execute_binary_script( | ||
write_file = ctx.actions.write, | ||
out = out, | ||
bin_path = ctx.executable._test_runner_script.short_path, | ||
arguments = test_runner_args, | ||
workspace_name = ctx.workspace_name, | ||
) | ||
|
||
# Wrap the arguments with the binary. | ||
execute_binary( | ||
name = name, | ||
binary = binary_name, | ||
arguments = args, | ||
runfiles = ctx.runfiles(files = ctx.files._test_runner_script) | ||
runfiles = execute_binary_utils.collect_runfiles( | ||
runfiles, | ||
[ctx.attr._test_runner_script], | ||
) | ||
|
||
return DefaultInfo(executable = out, runfiles = runfiles) | ||
|
||
default_test_runner = rule( | ||
implementation = _default_test_runner_impl, | ||
attrs = { | ||
"bazel_cmds": attr.string_list( | ||
default = integration_test_utils.DEFAULT_BAZEL_CMDS, | ||
doc = """\ | ||
The Bazel commands to be executed by the test runner in the test workspace.\ | ||
""", | ||
), | ||
"_test_runner_script": attr.label( | ||
default = "//bazel_integration_test/private:default_test_runner.sh", | ||
executable = True, | ||
allow_files = True, | ||
cfg = "target", | ||
), | ||
}, | ||
doc = "", | ||
executable = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load("@bazel_binaries//:defs.bzl", "bazel_binaries") | ||
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") | ||
load( | ||
"//bazel_integration_test:defs.bzl", | ||
"bazel_integration_tests", | ||
"default_test_runner", | ||
"integration_test_utils", | ||
) | ||
|
||
bzlformat_pkg(name = "bzlformat") | ||
|
||
default_test_runner(name = "e2e_test_runner") | ||
|
||
bazel_integration_tests( | ||
name = "e2e_test", | ||
bazel_binaries = bazel_binaries, | ||
bazel_versions = bazel_binaries.versions.all, | ||
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS + [ | ||
"no-sandbox", | ||
], | ||
test_runner = ":e2e_test_runner", | ||
workspace_files = integration_test_utils.glob_workspace_files("workspace") + [ | ||
"//:local_repository_files", | ||
], | ||
workspace_path = "workspace", | ||
) | ||
|
||
test_suite( | ||
name = "integration_tests", | ||
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, | ||
tests = integration_test_utils.bazel_integration_test_names( | ||
"e2e_test", | ||
bazel_binaries.versions.all, | ||
), | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# E2E Test | ||
|
||
The e2e tests are designed to test the use of `rules_bazel_integration_test` by a client. It | ||
demonstrates the minimum requirements needed to use this ruleset. | ||
|
||
This package contains integration tests that execute other integration tests defined under the | ||
workspace in the `workspace` directory. The `workspace` directory contains its own child workspace | ||
under the `child_workspace` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# To update these lines, execute | ||
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages` | ||
build --deleted_packages=child_workspace | ||
query --deleted_packages=child_workspace | ||
|
||
# Import Shared settings | ||
import %workspace%/../../../shared.bazelrc | ||
|
||
# Import CI settings. | ||
import %workspace%/../../../ci.bazelrc | ||
|
||
# Try to import a local.rc file; typically, written by CI | ||
try-import %workspace%/../../../local.bazelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../.bazelversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("@bazel_binaries//:defs.bzl", "bazel_binaries") | ||
load( | ||
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl", | ||
"bazel_integration_tests", | ||
"default_test_runner", | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
# Declare a test runner to drive the integration tests. | ||
default_test_runner( | ||
name = "child_test_runner", | ||
) | ||
|
||
# If you want to execute an integration test using multiple versions of Bazel, | ||
# use bazel_integration_tests. It will generate multiple integration test | ||
# targets with names derived from the base name and the bazel version. | ||
bazel_integration_tests( | ||
name = "child_test", | ||
bazel_versions = bazel_binaries.versions.all, | ||
tags = ["exclusive-if-local"], | ||
test_runner = ":child_test_runner", | ||
workspace_path = "child_workspace", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module( | ||
name = "e2e_parent", | ||
version = "0.0.0", | ||
) | ||
|
||
bazel_dep( | ||
name = "rules_bazel_integration_test", | ||
version = "0.0.0", | ||
dev_dependency = True, | ||
) | ||
local_path_override( | ||
module_name = "rules_bazel_integration_test", | ||
path = "../../..", | ||
) | ||
|
||
bazel_binaries = use_extension( | ||
"@rules_bazel_integration_test//:extensions.bzl", | ||
"bazel_binaries", | ||
dev_dependency = True, | ||
) | ||
bazel_binaries.download(version_file = "//:.bazelversion") | ||
use_repo( | ||
bazel_binaries, | ||
"bazel_binaries", | ||
"build_bazel_bazel_.bazelversion", | ||
) |
Oops, something went wrong.