Skip to content

Commit bd72f6d

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 c17e577 commit bd72f6d

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
@@ -938,22 +938,18 @@ get_image_labels() {
938938
exit 2
939939
fi
940940

941-
local image_labels
942941
# Ensure that we don't have a tag and digest for skopeo
943942
image=$(get_image_registry_repository_digest "$image")
944943

945-
# Fetch first arch using --raw as skopeo may fail when
946-
# the image does not have build for arch same as base system.
947-
local raw_output
948-
949-
if ! raw_output=$(retry skopeo inspect --raw "docker://${image}"); then
950-
echo "get_image_labels: raw inspect failed after retries" >&2
944+
first_arch=$(get_first_arch "${image}")
945+
if [ -z "${first_arch}" ] || [ "${first_arch}" == "null" ]; then
946+
echo "get_image_labels: architecture could not be determined for ${image}" >&2
947+
exit 1
951948
fi
952949

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

956-
952+
local image_labels
957953
if ! image_labels=$(retry skopeo inspect --override-arch="${first_arch}" --no-tags docker://"${image}"); then
958954
echo "get_image_labels: failed to inspect the image" >&2
959955
exit 1

unittests_bash/test_utils.bats

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

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

843842
[[ "$status" -eq 1 \
844843
&& "${output}" == *"${EXPECTED_LINE_1}"* \
845-
&& "${output}" == *"${EXPECTED_LINE_2}"* \
846-
&& "${output}" == *"${EXPECTED_ERROR_LINE}"* ]]
844+
&& "${output}" == *"${EXPECTED_LINE_2}"* ]]
847845
}
848846

849847
@test "Get relatedImages from operator bundle: valid-operator-bundle-1" {
@@ -1514,12 +1512,12 @@ EOF
15141512

15151513
}
15161514

1517-
@test "Retry Get Image Labels: registry/image:tag@invalid-url" {
1515+
@test "Retry Get Image Labels: registry/image-manifest@valid" {
15181516
RETRY_COUNT=1
15191517
RETRY_INTERVAL=1
15201518
retry_output=$(get_retry_expected_output)
1521-
run get_image_labels registry/image:tag@invalid-url
1522-
EXPECTED_RESPONSE=$(echo -e -n "get_image_labels: First architecture found: \n${retry_output}get_image_labels: failed to inspect the image")
1519+
run get_image_labels registry/image-manifest@valid
1520+
EXPECTED_RESPONSE=$(echo -e -n "get_image_labels: First architecture found: amd64\n${retry_output}get_image_labels: failed to inspect the image")
15231521

15241522
[[ "${output}" == *"${EXPECTED_RESPONSE}"* && "$status" -eq 1 ]]
15251523
}
@@ -2179,4 +2177,18 @@ EOF
21792177

21802178
[ "$status" -eq 1 ]
21812179
[[ "$output" == *"get_first_arch: Error fetching raw manifest"* ]]
2180+
}
2181+
@test "Retry get_first_arch: registry/invalid-image:lates" {
2182+
RETRY_COUNT=1
2183+
RETRY_INTERVAL=1
2184+
2185+
retry_output=$(get_retry_expected_output)
2186+
2187+
run get_first_arch "registry/invalid-image:latest"
2188+
2189+
local EXPECTED_FINAL_ERROR="get_first_arch: Error fetching raw manifest for ${image}"
2190+
EXPECTED_RESPONSE=$(echo -e "${retry_output}\n${FINAL_ERROR}")
2191+
echo "$EXPECTED_RESPONSE"
2192+
[[ "${output}" == *"${EXPECTED_RESPONSE}"* && "$status" -eq 1 ]]
2193+
21822194
}

0 commit comments

Comments
 (0)