Skip to content

Commit 1cfaf2d

Browse files
Fix test compatibility with Bazel versions before 8
1 parent 25602cc commit 1cfaf2d

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

tests/test_defs.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ helm_package_regex_test = rule(
7878
},
7979
test = True,
8080
)
81+
82+
def label_to_str(label):
83+
return str(Label(label))

tests/with_image_deps_img/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load("@rules_img//img:image.bzl", "image_manifest")
33
load("@rules_img//img:layer.bzl", "image_layer")
44
load("@rules_img//img:push.bzl", "image_push")
55
load("//helm:defs.bzl", "helm_chart", "helm_lint_test", "helm_template_test")
6-
load("//tests:test_defs.bzl", "helm_package_regex_test")
6+
load("//tests:test_defs.bzl", "helm_package_regex_test", "label_to_str")
77

88
exports_files(["Chart.lock"])
99

@@ -23,6 +23,14 @@ helm_chart(
2323
":image_e.push",
2424
"@rules_helm_test_img_container_base",
2525
],
26+
substitutions = {
27+
# This goofy workaround is needed because Bazel 8 has '~' characters in
28+
# the label string, while newer versions have '+'. Relying on the fact
29+
# that the substitutions are handled before image stamps, we can do a
30+
# double replacement, and thus avoid hardcoding either character into
31+
# the values file ensuring compatibility with both versions
32+
"base_container_label": label_to_str("@rules_helm_test_img_container_base//:image"),
33+
},
2634
target_compatible_with = EXCLUDE_WINDOWS,
2735
)
2836

tests/with_image_deps_img/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bazel_produced_images:
2424
image_pull:
2525
url: "{@+helm_test+rules_helm_test_img_container_base//:image}"
2626
image_pull_tag:
27-
url: "{@+helm_test+rules_helm_test_img_container_base//:image.repository}:{@+helm_test+rules_helm_test_img_container_base//:image.tag}"
27+
url: "{@{base_container_label}.repository}:{@{base_container_label}.tag}"
2828

2929
imagePullSecrets: []
3030
nameOverride: ""

0 commit comments

Comments
 (0)