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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
#!/usr/bin/env bats
load helpers
@test "images-flags-order-verification" {
run_buildah images --all
run_buildah 125 images img1 -n
check_options_flag_err "-n"
run_buildah 125 images img1 --filter="service=redis" img2
check_options_flag_err "--filter=service=redis"
run_buildah 125 images img1 img2 img3 -q
check_options_flag_err "-q"
}
@test "images" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images
expect_line_count 3
}
@test "images all test" {
_prefetch alpine
run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test ${TESTSDIR}/bud/use-layers
run_buildah images
expect_line_count 3
run_buildah images -a
expect_line_count 8
# create a no name image which should show up when doing buildah images without the --all flag
run_buildah bud --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/use-layers
run_buildah images
expect_line_count 4
}
@test "images filter test" {
_prefetch k8s.gcr.io/pause busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json k8s.gcr.io/pause
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah 125 images --noheading --filter since k8s.gcr.io/pause
expect_output 'invalid filter: "since" requires value'
run_buildah images --noheading --filter since=k8s.gcr.io/pause
expect_line_count 1
}
@test "images format test" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images --format "{{.Name}}"
expect_line_count 2
}
@test "images noheading test" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images --noheading
expect_line_count 2
}
@test "images quiet test" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images --quiet
expect_line_count 2
}
@test "images no-trunc test" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images -q --no-trunc
expect_line_count 2
expect_output --substring --from="${lines[0]}" "sha256"
}
@test "images json test" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
for img in '' alpine busybox; do
# e.g. [ { "id": "xx", ... },{ "id": "yy", ... } ]
# We check for the presence of some keys, but not (yet) their values.
# FIXME: once we can rely on 'jq' tool being present, improve this test!
run_buildah images --json $img
expect_output --from="${lines[0]}" "[" "first line of JSON output: array"
for key in id names digest createdat size readonly history; do
expect_output --substring "\"$key\": "
done
done
}
@test "images json dup test" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid test
run_buildah tag test new-name
run_buildah images --json
expect_output --substring '"id": '
}
@test "images json valid" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid1=$output
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid2=$output
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid1 test
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid2 test2
run_buildah images --json
run python3 -m json.tool <<< "$output"
[ "${status}" -eq 0 ]
}
@test "specify an existing image" {
_prefetch alpine busybox
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine
cid1=$output
run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json busybox
cid2=$output
run_buildah images alpine
expect_line_count 2
}
@test "specify a nonexistent image" {
run_buildah 125 images alpine
expect_output --from="${lines[0]}" "No such image alpine"
expect_line_count 1
}
@test "Test dangling images" {
run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch
cid=$output
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid test
run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid test
run_buildah images
expect_line_count 3
run_buildah images --filter dangling=true
expect_output --substring " <none> "
expect_line_count 2
run_buildah images --filter dangling=false
expect_output --substring " latest "
expect_line_count 2
}
@test "image digest test" {
_prefetch busybox
run_buildah pull --signature-policy ${TESTSDIR}/policy.json busybox
run_buildah images --digests
expect_output --substring "sha256:"
}
@test "images in OCI format with no creation dates" {
mkdir -p $TESTDIR/blobs/sha256
# Create a layer.
dd if=/dev/zero bs=512 count=2 of=$TESTDIR/blob
layerdigest=$(sha256sum $TESTDIR/blob | awk '{print $1}')
layersize=$(stat -c %s $TESTDIR/blob)
mv $TESTDIR/blob $TESTDIR/blobs/sha256/${layerdigest}
# Create a configuration blob that doesn't include a "created" date.
now=$(TZ=UTC date +%Y-%m-%dT%H:%M:%S.%NZ)
arch=$(go env GOARCH)
cat > $TESTDIR/blob << EOF
{
"architecture": "$arch",
"os": "linux",
"config": {
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"sh"
]
},
"rootfs": {
"type": "layers",
"diff_ids": [
"sha256:${layerdigest}"
]
},
"history": [
{
"created": "${now}",
"created_by": "/bin/sh -c #(nop) ADD file:${layerdigest} in / "
}
]
}
EOF
configdigest=$(sha256sum $TESTDIR/blob | awk '{print $1}')
configsize=$(stat -c %s $TESTDIR/blob)
mv $TESTDIR/blob $TESTDIR/blobs/sha256/${configdigest}
# Create a manifest for that configuration blob and layer.
cat > $TESTDIR/blob << EOF
{
"schemaVersion": 2,
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:${configdigest}",
"size": ${configsize}
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar",
"digest": "sha256:${layerdigest}",
"size": ${layersize}
}
]
}
EOF
manifestdigest=$(sha256sum $TESTDIR/blob | awk '{print $1}')
manifestsize=$(stat -c %s $TESTDIR/blob)
mv $TESTDIR/blob $TESTDIR/blobs/sha256/${manifestdigest}
# Add the manifest to the image index.
cat > $TESTDIR/index.json << EOF
{
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:${manifestdigest}",
"size": ${manifestsize}
}
]
}
EOF
# Mark the directory as a layout directory.
echo -n '{"imageLayoutVersion": "1.0.0"}' > $TESTDIR/oci-layout
# Import the image.
run_buildah pull oci:$TESTDIR
# Inspect the image. We shouldn't crash.
run_buildah inspect ${configdigest}
# List images. We shouldn't crash.
run_buildah images
}
|