Skip to content

Commit 552cf5e

Browse files
author
Ashwini Kumar
committed
feat(labels): integrate get_first_arch and enhance retry testing
- Update get_image_labels to use get_first_arch. - Add test for updated get_image_labels. Signed-off-by: Ashwini Kumar
1 parent 3596d0b commit 552cf5e

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

test/utils.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -847,22 +847,18 @@ get_image_labels() {
847847
exit 2
848848
fi
849849

850-
local image_labels
851850
# Ensure that we don't have a tag and digest for skopeo
852851
image=$(get_image_registry_repository_digest "$image")
853852

854-
# Fetch first arch using --raw as skopeo may fail when
855-
# the image does not have build for arch same as base system.
856-
local raw_output
857-
858-
if ! raw_output=$(retry skopeo inspect --raw "docker://${image}"); then
859-
echo "get_image_labels: raw inspect failed after retries" >&2
853+
first_arch=$(get_first_arch "${image}")
854+
if [ -z "${first_arch}" ] || [ "${first_arch}" == "null" ]; then
855+
echo "get_image_labels: architecture could not be determined for ${image}" >&2
856+
exit 1
860857
fi
861858

862-
first_arch=$(echo "${raw_output}" | jq -r '.manifests[].platform.architecture' | head -n 1)
863859
echo "get_image_labels: First architecture found: ${first_arch}"
864860

865-
861+
local image_labels
866862
if ! image_labels=$(retry skopeo inspect --override-arch="${first_arch}" --no-tags docker://"${image}"); then
867863
echo "get_image_labels: failed to inspect the image" >&2
868864
exit 1

unittests_bash/test_utils.bats

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,12 @@ EOF
760760
@test "Get Image Labels: registry/image-manifest:tag@invalid" {
761761
run get_image_labels registry/image-manifest:tag@invalid
762762

763-
local EXPECTED_LINE_1="get_image_labels: First architecture found:"
764-
local EXPECTED_LINE_2="get_image_labels: failed to inspect the image"
765-
local EXPECTED_ERROR_LINE="Invalid numeric literal at line 1, column 13"
763+
local EXPECTED_LINE_1="get_first_arch: Error fetching raw manifest for registry/image-manifest@invalid"
764+
local EXPECTED_LINE_2="get_image_labels: architecture could not be determined for registry/image-manifest@invalid"
766765

767766
[[ "$status" -eq 1 \
768767
&& "${output}" == *"${EXPECTED_LINE_1}"* \
769-
&& "${output}" == *"${EXPECTED_LINE_2}"* \
770-
&& "${output}" == *"${EXPECTED_ERROR_LINE}"* ]]
768+
&& "${output}" == *"${EXPECTED_LINE_2}"* ]]
771769
}
772770

773771
@test "Get relatedImages from operator bundle: valid-operator-bundle-1" {
@@ -1438,12 +1436,12 @@ EOF
14381436

14391437
}
14401438

1441-
@test "Retry Get Image Labels: registry/image:tag@invalid-url" {
1439+
@test "Retry Get Image Labels: registry/image-manifest@valid" {
14421440
RETRY_COUNT=1
14431441
RETRY_INTERVAL=1
14441442
retry_output=$(get_retry_expected_output)
1445-
run get_image_labels registry/image:tag@invalid-url
1446-
EXPECTED_RESPONSE=$(echo -e -n "get_image_labels: First architecture found: \n${retry_output}get_image_labels: failed to inspect the image")
1443+
run get_image_labels registry/image-manifest@valid
1444+
EXPECTED_RESPONSE=$(echo -e -n "get_image_labels: First architecture found: amd64\n${retry_output}get_image_labels: failed to inspect the image")
14471445

14481446
[[ "${output}" == *"${EXPECTED_RESPONSE}"* && "$status" -eq 1 ]]
14491447
}
@@ -2103,4 +2101,18 @@ EOF
21032101

21042102
[ "$status" -eq 1 ]
21052103
[[ "$output" == *"get_first_arch: Error fetching raw manifest"* ]]
2104+
}
2105+
@test "Retry get_first_arch: registry/invalid-image:lates" {
2106+
RETRY_COUNT=1
2107+
RETRY_INTERVAL=1
2108+
2109+
retry_output=$(get_retry_expected_output)
2110+
2111+
run get_first_arch "registry/invalid-image:latest"
2112+
2113+
local EXPECTED_FINAL_ERROR="get_first_arch: Error fetching raw manifest for ${image}"
2114+
EXPECTED_RESPONSE=$(echo -e "${retry_output}\n${FINAL_ERROR}")
2115+
echo "$EXPECTED_RESPONSE"
2116+
[[ "${output}" == *"${EXPECTED_RESPONSE}"* && "$status" -eq 1 ]]
2117+
21062118
}

0 commit comments

Comments
 (0)