Skip to content

Commit

Permalink
test: add oci_tarball test for sh_test (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Jun 12, 2024
1 parent 44175f4 commit 464858a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 33 additions & 1 deletion examples/assertion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ assert_json_matches(
filter1 = ".[0].RepoTags",
)

# Case 10: An oci_image directly fed into oci_tarball
# Case 10: an oci_tarball run as part of a genrule
oci_image(
name = "case10",
architecture = "arm64",
Expand All @@ -312,6 +312,38 @@ $(location :case10_tarball) && echo "worked" > $@
tools = [":case10_tarball"],
)

# Case 11: an oci_tarball run as part of sh_test
oci_image(
name = "case11",
architecture = "arm64",
os = "linux",
)

oci_tarball(
name = "case11_tarball",
image = ":case11",
repo_tags = ["case11:example"],
)

write_file(
name = "case11_test_sh",
out = "case11_test.sh",
content = [
"output=$($1)",
'if [[ "$output" != "Loaded image: case11:example" ]]; then',
' echo "failed to load: $output"',
" exit 1",
"fi",
],
)

sh_test(
name = "case11_test",
srcs = ["case11_test.sh"],
args = ["$(location :case11_tarball)"],
data = [":case11_tarball"],
)

# build them as test.
build_test(
name = "test",
Expand Down
2 changes: 2 additions & 0 deletions oci/private/tarball_run.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set -o pipefail -o errexit -o nounset

{{BASH_RLOCATION_FUNCTION}}

runfiles_export_envvars

readonly TAR="$(rlocation "{{tar}}")"
readonly MTREE="$(rlocation "{{mtree_path}}")"
readonly LOADER="$(rlocation "{{loader}}")"
Expand Down

0 comments on commit 464858a

Please sign in to comment.