Skip to content

Commit 9b62438

Browse files
committed
test/buildah-bud: fix checkout to also handle go.mod replace
There is a rather surprising bug in the current test checkout logic. The go.mod version parsing never actually consider a go.mod replace for buildah and always read the main version. This meant a buildah replace actually is testing the old version with the new code and that means the new tests are not run leading people in false belive when testing a buildah vendor that it worked. But then later it fails when doing the proper update without replace. To fix this first use go list to parse go.mod which is more robust. Then first check if there is a replace and then use that repo/version instead. Signed-off-by: Paul Holzinger <[email protected]>
1 parent a97d90c commit 9b62438

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

test/buildah-bud/run-buildah-bud-tests

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,20 @@ function die() {
8989
failhint=
9090
trap 'if [[ $? != 0 ]]; then if [[ -n $failhint ]]; then echo;echo "***************************************";echo "$failhint";echo;echo "Please see $BUD_TEST_DIR_REL/README.md for advice";fi;fi' 0
9191

92-
# Find the version of buildah we've vendored in, so we can run the right tests
93-
buildah_version=$(awk "\$1 == \"$BUILDAH_REPO\" { print \$2 }" <go.mod)
92+
# Find the version of buildah we've vendored in, so we can run the right tests.
93+
# Note first check if buildah is being replaced with a different version in which case we need to use that one.
94+
buildah_replace=$(go list -m -f '{{if .Replace}}{{.Replace}}{{end}}' $BUILDAH_REPO)
95+
buildah_checkout_repo="$BUILDAH_REPO"
96+
97+
if [[ -z "$buildah_replace" ]]; then
98+
# No replace this is fine, check the main version
99+
buildah_version=$(go list -m -f '{{.Version}}' $BUILDAH_REPO)
100+
else
101+
# replace string is "REPO VERSION" so split this into our two vars
102+
buildah_checkout_repo="${buildah_replace% *}"
103+
buildah_version="${buildah_replace#* }"
104+
fi
105+
94106

95107
if [[ -z "$buildah_version" ]]; then
96108
# This should not happen
@@ -147,7 +159,7 @@ if [[ -n $do_checkout ]]; then
147159
fi
148160

149161
failhint="'git clone' failed - this should never happen!"
150-
(set -x;git clone -q $shallow_checkout https://$BUILDAH_REPO $buildah_dir)
162+
(set -x;git clone -q $shallow_checkout https://$buildah_checkout_repo $buildah_dir)
151163

152164
# Recent versions of git (like `2.39`) disallow some operations (like `am`)
153165
# without an identity being set. In this case, git will throw an error
@@ -193,7 +205,7 @@ if [[ -n $do_checkout ]]; then
193205
# for a developer to push a new set of diffs to podman-land.
194206
failhint=
195207
sed -e "s,\[BASETAG\],${BASE_TAG},g" \
196-
-e "s,\[BUILDAHREPO\],${BUILDAH_REPO},g" \
208+
-e "s,\[BUILDAHREPO\],${buildah_checkout_repo},g" \
197209
< ${BUD_TEST_DIR}/make-new-buildah-diffs \
198210
> make-new-buildah-diffs
199211
chmod 755 make-new-buildah-diffs

0 commit comments

Comments
 (0)