1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#!/usr/bin/env bats
load helpers
@test "images-by-digest" {
# Bail if "sha256sum" isn't available.
if test -z "$(which sha256sum 2> /dev/null)" ; then
skip "need sha256sum"
fi
# Create a couple of random files.
createrandom ${TESTDIR}/random1
createrandom ${TESTDIR}/random2
createrandom ${TESTDIR}/random3
digest1=$(sha256sum ${TESTDIR}/random1)
digest2=$(sha256sum ${TESTDIR}/random2)
digest3=$(sha256sum ${TESTDIR}/random3)
# Create a layer.
run storage --debug=false create-layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
firstimage=${output%% *}
# Set the first file as the manifest of this image.
run storage --debug=false set-image-data -f ${TESTDIR}/random1 ${firstimage} manifest
echo "$output"
# Create another image using that layer.
run storage --debug=false create-image $layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
secondimage=${output%% *}
# Set the first file as the manifest of this image.
run storage --debug=false set-image-data -f ${TESTDIR}/random1 ${secondimage} manifest
echo "$output"
# Create yet another image using that layer.
run storage --debug=false create-image $layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
thirdimage=${output%% *}
# Set the second file as the manifest of this image.
run storage --debug=false set-image-data -f ${TESTDIR}/random2 ${thirdimage} manifest
echo "$output"
# Create still another image using that layer.
run storage --debug=false create-image --digest sha256:${digest3// *} $layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
fourthimage=${output%% *}
# Create another image using that layer.
run storage --debug=false create-image --digest sha256:${digest3// *} $layer
echo "$output"
[ "$status" -eq 0 ]
[ "$output" != "" ]
fifthimage=${output%% *}
# Set the third file as the manifest of this image.
run storage --debug=false set-image-data -f ${TESTDIR}/random3 ${fifthimage} manifest
echo "$output"
# Check that "images-by-digest" lists the right images.
run storage --debug=false images-by-digest --quiet sha256:${digest1// *}
echo "$output"
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[0]}" = "$firstimage" ] || [ "${lines[0]}" = "$secondimage" ]
[ "${lines[1]}" = "$firstimage" ] || [ "${lines[1]}" = "$secondimage" ]
run storage --debug=false images-by-digest --quiet sha256:${digest2// *}
echo "$output"
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 1 ]
[ "${lines[0]}" = "$thirdimage" ]
run storage --debug=false images-by-digest --quiet sha256:${digest3// *}
echo "$output"
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" = "$fourthimage" ] || [ "${lines[0]}" = "$fifthimage" ]
[ "${lines[1]}" = "$fourthimage" ] || [ "${lines[1]}" = "$fifthimage" ]
run storage --debug=false delete-image ${secondimage}
echo "$output"
[ "$status" -eq 0 ]
run storage --debug=false images-by-digest --quiet sha256:${digest1// *}
echo "$output"
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 1 ]
[ "${lines[0]}" = "$firstimage" ]
run storage --debug=false delete-image ${firstimage}
echo "$output"
[ "$status" -eq 0 ]
run storage --debug=false images-by-digest --quiet sha256:${digest1// *}
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
|