Skip to content

Commit f290ca5

Browse files
committed
tests: image-verify: rework tar smoke-tests
The smoke tests we do in image-verify need to also handle zstd. While we're at it, rework things to make shellcheck happy. Fixes: 7bb2940 ("test: check blobs with gnutar, add sm file insert") Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 87c9c37 commit f290ca5

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

test/helpers.bash

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,37 @@ function requires() {
108108
}
109109

110110
function image-verify() {
111-
local ocidir="$@"
112-
# test that each generated targz file is valid according to gnutar:
113-
for f in $(ls $ocidir/blobs/sha256/); do
114-
file $ocidir/blobs/sha256/$f | grep "gzip" || {
115-
continue
111+
local ocidir="$1"
112+
113+
# Smoke-test for our blobs.
114+
while IFS= read -r blob; do
115+
# Make sure tar layers are valid according to gnutar.
116+
mimetype="$(file --mime "$blob")"
117+
cat=
118+
case "$mimetype" in
119+
*application/x-tar*)
120+
cat="cat"
121+
;;
122+
*application/zstd*)
123+
cat="zstdcat"
124+
;;
125+
*application/gzip*)
126+
cat="zcat"
127+
;;
128+
*)
129+
continue
130+
;;
131+
esac
132+
"$cat" <"$blob" | file --mime - | grep "application/x-tar" || {
133+
fail "blob $blob is compressed but is not a tar archive?"
116134
}
117-
zcat $ocidir/blobs/sha256/$f | tar tvf - >/dev/null || {
135+
"$cat" <"$blob" | tar tvf - >/dev/null || {
118136
rc=$?
119-
file $ocidir/blobs/sha256/$f
120-
echo "error untarring $f: $rc"
121-
return $rc
137+
file "$blob"
138+
echo "error untarring $blob: $rc"
139+
return "$rc"
122140
}
123-
echo $f: valid tar archive
141+
echo "$blob: valid tar archive"
124142
done
125143

126144
# Validate that all inodes are owned by the same uid:gid as the root

0 commit comments

Comments
 (0)