mirror of
https://github.com/containers/podman.git
synced 2025-09-10 04:12:20 +08:00

When I originally wrote this code I had no idea what POST would look like so I did a sloppy job, deferring making it usable. Now that we have some real-world examples in place, I have a better understanding of what params look like and how to make tests more readable/maintainable. (Deferring isn't always bad: one of my early ideas was to separate params using commas; that would've been a disaster because some JSON values, such as arrays, include commas). This commit implements a better way of dealing with POST: * The main concept is still 'key=value' * When value is a JSON object (dictionary, array), it can be quoted. * Multiple params are simply separated by spaces. The 3-digit HTTP code is a prominent, readable separator between POST params and expected results. The parsing code is a little uglier, but test developers need never see that. The important thing is that writing tests is now easier. * POST params can be empty (this removes the need for a useless '') I snuck in one unrelated change: one of the newly-added tests, .NetworkSettings, was failing when run rootless (which is how I test on my setup). I made it conditional. Signed-off-by: Ed Santiago <santiago@redhat.com>
68 lines
1.9 KiB
Bash
68 lines
1.9 KiB
Bash
# -*- sh -*-
|
|
#
|
|
# Tests for more image-related endpoints
|
|
#
|
|
|
|
red='\e[31m'
|
|
nc='\e[0m'
|
|
|
|
podman pull -q $IMAGE
|
|
|
|
t GET libpod/images/json 200 \
|
|
.[0].Id~[0-9a-f]\\{64\\}
|
|
iid=$(jq -r '.[0].Id' <<<"$output")
|
|
|
|
# Retrieve the image tree
|
|
t GET libpod/images/$IMAGE/tree 200 \
|
|
.Tree~^Image
|
|
|
|
# Tag nonesuch image
|
|
t POST "libpod/images/nonesuch/tag?repo=myrepo&tag=mytag" 404
|
|
|
|
# Tag the image
|
|
t POST "libpod/images/$IMAGE/tag?repo=localhost:5000/myrepo&tag=mytag" 201
|
|
|
|
t GET libpod/images/$IMAGE/json 200 \
|
|
.RepoTags[1]=localhost:5000/myrepo:mytag
|
|
|
|
# Run registry container
|
|
podman run -d --name registry -p 5000:5000 quay.io/libpod/registry:2.6 /entrypoint.sh /etc/docker/registry/config.yml
|
|
wait_for_port localhost 5000
|
|
|
|
# Push to local registry and check output
|
|
while read -r LINE
|
|
do
|
|
if echo "${LINE}" | jq --exit-status 'select( .status != null) | select ( .status | contains("digest: sha256:"))' &>/dev/null; then
|
|
GOT_DIGEST="1"
|
|
fi
|
|
done < <(curl -sL "http://$HOST:$PORT/images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" -XPOST)
|
|
if [ -z "${GOT_DIGEST}" ] ; then
|
|
echo -e "${red}not ok: did not found digest in output${nc}" 1>&2;
|
|
fi
|
|
|
|
# Push to local registry
|
|
t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" 200
|
|
|
|
# Untag the image
|
|
t POST "libpod/images/$iid/untag?repo=localhost:5000/myrepo&tag=mytag" 201
|
|
|
|
# Try to push non-existing image
|
|
t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" 200
|
|
jq -re 'select(.errorDetail)' <<<"$output" &>/dev/null || echo -e "${red}not ok: error message not found in output${nc}" 1>&2
|
|
|
|
t GET libpod/images/$IMAGE/json 200 \
|
|
.RepoTags[-1]=$IMAGE
|
|
|
|
# Remove the registry container
|
|
t DELETE libpod/containers/registry?force=true 204
|
|
|
|
# Remove images
|
|
t DELETE libpod/images/$IMAGE 200 \
|
|
.ExitCode=0
|
|
t DELETE libpod/images/quay.io/libpod/registry:2.6 200 \
|
|
.ExitCode=0
|
|
|
|
if [ -z "${GOT_DIGEST}" ] ; then
|
|
exit 1;
|
|
fi
|