|
| 1 | +#!/usr/bin/env bats |
| 2 | +# |
| 3 | +# Simplest test for skopeo inspect |
| 4 | +# |
| 5 | + |
| 6 | +load helpers |
| 7 | + |
| 8 | +@test "inspect: basic" { |
| 9 | + workdir=$TESTDIR/inspect |
| 10 | + |
| 11 | + remote_image=docker://quay.io/libpod/alpine_labels:latest |
| 12 | + # Inspect remote source, then pull it. There's a small race condition |
| 13 | + # in which the remote image can get updated between the inspect and |
| 14 | + # the copy; let's just not worry about it. |
| 15 | + run_skopeo inspect $remote_image |
| 16 | + inspect_remote=$output |
| 17 | + |
| 18 | + # Now pull it into a directory |
| 19 | + run_skopeo copy $remote_image dir:$workdir |
| 20 | + expect_output --substring "Getting image source signatures" |
| 21 | + expect_output --substring "Writing manifest to image destination" |
| 22 | + |
| 23 | + # Unpacked contents must include a manifest and version |
| 24 | + [ -e $workdir/manifest.json ] |
| 25 | + [ -e $workdir/version ] |
| 26 | + |
| 27 | + # Now run inspect locally |
| 28 | + run_skopeo inspect dir:$workdir |
| 29 | + inspect_local=$output |
| 30 | + |
| 31 | + # Each SHA-named file must be listed in the output of 'inspect' |
| 32 | + for sha in $(find $workdir -type f | xargs -l1 basename | egrep '^[0-9a-f]{64}$'); do |
| 33 | + expect_output --from="$inspect_local" --substring "sha256:$sha" \ |
| 34 | + "Locally-extracted SHA file is present in 'inspect'" |
| 35 | + done |
| 36 | + |
| 37 | + # Simple sanity check on 'inspect' output. |
| 38 | + # For each of the given keys (LHS of the table below): |
| 39 | + # 1) Get local and remote values |
| 40 | + # 2) Sanity-check local value using simple expression |
| 41 | + # 3) Confirm that local and remote values match. |
| 42 | + # |
| 43 | + # The reason for (2) is to make sure that we don't compare bad results |
| 44 | + # |
| 45 | + # The reason for a hardcoded list, instead of 'jq keys', is that RepoTags |
| 46 | + # is always empty locally, but a list remotely. |
| 47 | + while read key expect; do |
| 48 | + local=$(echo "$inspect_local" | jq -r ".$key") |
| 49 | + remote=$(echo "$inspect_remote" | jq -r ".$key") |
| 50 | + |
| 51 | + expect_output --from="$local" --substring "$expect" \ |
| 52 | + "local $key is sane" |
| 53 | + |
| 54 | + expect_output --from="$remote" "$local" \ |
| 55 | + "local $key matches remote" |
| 56 | + done <<END_EXPECT |
| 57 | +Architecture amd64 |
| 58 | +Created [0-9-]+T[0-9:]+\.[0-9]+Z |
| 59 | +Digest sha256:[0-9a-f]{64} |
| 60 | +DockerVersion [0-9]+\.[0-9][0-9.-]+ |
| 61 | +Labels \\\{.*PODMAN.*podman.*\\\} |
| 62 | +Layers \\\[.*sha256:.*\\\] |
| 63 | +Os linux |
| 64 | +END_EXPECT |
| 65 | +} |
| 66 | + |
| 67 | +# vim: filetype=sh |
0 commit comments