#!/usr/bin/env bats # # Simplest test for skopeo inspect # load helpers @test "inspect: basic" { workdir=$TESTDIR/inspect remote_image=docker://quay.io/libpod/alpine_labels:latest # Inspect remote source, then pull it. There's a small race condition # in which the remote image can get updated between the inspect and # the copy; let's just not worry about it. run_skopeo inspect $remote_image inspect_remote=$output # Now pull it into a directory run_skopeo copy $remote_image dir:$workdir expect_output --substring "Getting image source signatures" expect_output --substring "Writing manifest to image destination" # Unpacked contents must include a manifest and version [ -e $workdir/manifest.json ] [ -e $workdir/version ] # Now run inspect locally run_skopeo inspect dir:$workdir inspect_local=$output run_skopeo inspect --raw dir:$workdir inspect_local_raw=$output config_digest=$(jq -r '.config.digest' <<<"$inspect_local_raw") # Each SHA-named layer file (but not the config) must be listed in the output of 'inspect'. # In all existing versions of Skopeo (with 1.6 being the current as of this comment), # the output of 'inspect' lists layer digests, # but not the digest of the config blob ($config_digest), if any. layers=$(jq -r '.Layers' <<<"$inspect_local") for sha in $(find $workdir -type f | xargs -l1 basename | grep -E '^[0-9a-f]{64}$'); do if [ "sha256:$sha" != "$config_digest" ]; then expect_output --from="$layers" --substring "sha256:$sha" \ "Locally-extracted SHA file is present in 'inspect'" fi done # Simple sanity check on 'inspect' output. # For each of the given keys (LHS of the table below): # 1) Get local and remote values # 2) Sanity-check local value using simple expression # 3) Confirm that local and remote values match. # # The reason for (2) is to make sure that we don't compare bad results # # The reason for a hardcoded list, instead of 'jq keys', is that RepoTags # is always empty locally, but a list remotely. while read key expect; do local=$(echo "$inspect_local" | jq -r ".$key") remote=$(echo "$inspect_remote" | jq -r ".$key") expect_output --from="$local" --substring "$expect" \ "local $key is sane" expect_output --from="$remote" "$local" \ "local $key matches remote" done <