Files
podman/test/system/010-images.bats
Ed Santiago a9dbd2b3de Migrate away from docker.io
CI and system tests currently pull some images from docker.io.
Eliminate that, by:

  - building a custom image containing much of what we need
    for testing; and
  - copying other needed images to quay.io

(Reason: effective 2020-11-01 docker.io will limit the
number of image pulls).

The principal change is to create a new quay.io/libpod/testimage,
using the new test/system/build-testimage script, instead of
relying on quay.io/libpod/alpine_labels. We also switch to
using a hardcoded :YYYYMMDD tag, instead of :latest, in an
attempt to futureproof our CI. This image includes 'httpd'
from busybox-extras, which we use in our networking test
(previously we had to pull and run busybox from docker.io).

The testimage can and should be extended as needed for future
tests, e.g. adding test file content or other useful tools.

For the '--pull' tests which require actually pulling from
the registry, I've created an image with the same name but
tagged :00000000 so it will never be pulled by default.
Since this image is only used minimally, it's just busybox.

Unfortunately there remain two cases we cannot solve in
this tiny alpine-based image:

  1) docker registry
  2) systemd

For those, I've (manually) run:

    podman pull [ docker.io/library/registry:2.7 | registry.fedoraproject.org/fedora:31 ]
    podman tag !$ quay.io/...
    podman push !$

...and amended the calling tests accordingly.

I've tried to make the the smallest reasonable diff, not the
smallest possible one. I hope it's a reasonable tradeoff.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-09-08 06:06:06 -06:00

116 lines
4.0 KiB
Bash

#!/usr/bin/env bats
load helpers
@test "podman images - basic output" {
run_podman images -a
is "${lines[0]}" "REPOSITORY *TAG *IMAGE ID *CREATED *SIZE" "header line"
is "${lines[1]}" "$PODMAN_TEST_IMAGE_REGISTRY/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME *$PODMAN_TEST_IMAGE_TAG *[0-9a-f]\+" "podman images output"
}
@test "podman images - custom formats" {
tests="
--format {{.ID}} | [0-9a-f]\\\{12\\\}
--format {{.ID}} --no-trunc | sha256:[0-9a-f]\\\{64\\\}
--format {{.Repository}}:{{.Tag}} | $PODMAN_TEST_IMAGE_FQN
--format {{.Labels.created_by}} | test/system/build-testimage
--format {{.Labels.created_at}} | 20[0-9-]\\\+T[0-9:]\\\+Z
"
parse_table "$tests" | while read fmt expect; do
run_podman images $fmt
is "$output" "$expect\$" "podman images $fmt"
done
}
@test "podman images - json" {
# 'created': podman includes fractional seconds, podman-remote does not
tests="
Names[0] | $PODMAN_TEST_IMAGE_FQN
Id | [0-9a-f]\\\{64\\\}
Digest | sha256:[0-9a-f]\\\{64\\\}
CreatedAt | [0-9-]\\\+T[0-9:.]\\\+Z
Size | [0-9]\\\+
Labels.created_by | test/system/build-testimage
Labels.created_at | 20[0-9-]\\\+T[0-9:]\\\+Z
"
run_podman images -a --format json
parse_table "$tests" | while read field expect; do
actual=$(echo "$output" | jq -r ".[0].$field")
dprint "# actual=<$actual> expect=<$expect}>"
is "$actual" "$expect" "jq .$field"
done
}
@test "podman images - history output" {
# podman history is persistent: it permanently alters our base image.
# Create a dummy image here so we leave our setup as we found it.
run_podman run --name my-container $IMAGE true
run_podman commit my-container my-test-image
run_podman images my-test-image --format '{{ .History }}'
is "$output" "" "Image has empty history to begin with"
# Generate two randomish tags; 'tr' because they must be all lower-case
rand_name1="test-image-history-$(random_string 10 | tr A-Z a-z)"
rand_name2="test-image-history-$(random_string 10 | tr A-Z a-z)"
# Tag once, rmi, and make sure the tag name appears in history
run_podman tag my-test-image $rand_name1
run_podman rmi $rand_name1
run_podman images my-test-image --format '{{ .History }}'
is "$output" "localhost/${rand_name1}:latest" "image history after one tag"
# Repeat with second tag. Now both tags should be in history
run_podman tag my-test-image $rand_name2
run_podman rmi $rand_name2
run_podman images my-test-image --format '{{ .History }}'
is "$output" "localhost/${rand_name2}:latest, localhost/${rand_name1}:latest" \
"image history after two tags"
run_podman rmi my-test-image
run_podman rm my-container
}
@test "podman images - filter" {
run_podman inspect --format '{{.ID}}' $IMAGE
iid=$output
run_podman images --noheading --filter=after=$iid
is "$output" "" "baseline: empty results from filter (after)"
run_podman images --noheading --filter=before=$iid
is "$output" "" "baseline: empty results from filter (before)"
# Create a dummy container, then commit that as an image. We will
# now be able to use before/after/since queries
run_podman run --name mytinycontainer $IMAGE true
run_podman commit -q mytinycontainer mynewimage
new_iid=$output
# (refactor common options for legibility)
opts='--noheading --no-trunc --format={{.ID}}--{{.Repository}}:{{.Tag}}'
run_podman images ${opts} --filter=after=$iid
is "$output" "sha256:$new_iid--localhost/mynewimage:latest" "filter: after"
# Same thing, with 'since' instead of 'after'
run_podman images ${opts} --filter=since=$iid
is "$output" "sha256:$new_iid--localhost/mynewimage:latest" "filter: since"
run_podman images ${opts} --filter=before=mynewimage
is "$output" "sha256:$iid--$IMAGE" "filter: before"
# Clean up
run_podman rmi mynewimage
run_podman rm mytinycontainer
}
# vim: filetype=sh