Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apiv2 tests: finally fix POST as originally intended #9686

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/apiv2/01-basic.at
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ done
# Garbage tests - requests that should yield errors
#
t GET /nonesuch 404
t POST /nonesuch '' 404
t POST /nonesuch 404
t GET container/nonesuch/json 404
t GET libpod/containers/nonesuch/json 404

#### FIXME: maybe someday: t GET 'libpod/containers/json?a=b' 400

# Method not allowed
t POST /_ping '' 405
t POST /_ping 405
t DELETE /_ping 405
t POST libpod/containers/json '' 405
t POST libpod/pods/abc '' 405
t POST info '' 405
t POST libpod/containers/json 405
t POST libpod/pods/abc 405
t POST info 405
t GET libpod/containers/create 405

#
Expand Down
8 changes: 4 additions & 4 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ t GET images/$iid/json 200 \
.Id=sha256:$iid \
.RepoTags[0]=$IMAGE

t POST "images/create?fromImage=alpine" '' 200 .error~null .status~".*Download complete.*"
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*Download complete.*"

t POST "images/create?fromImage=alpine&tag=latest" '' 200
t POST "images/create?fromImage=alpine&tag=latest" 200

# Make sure that new images are pulled
old_iid=$(podman image inspect --format "{{.ID}}" docker.io/library/alpine:latest)
podman rmi -f docker.io/library/alpine:latest
podman tag $IMAGE docker.io/library/alpine:latest
t POST "images/create?fromImage=alpine" '' 200 .error~null .status~".*$old_iid.*"
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*$old_iid.*"
podman untag $IMAGE docker.io/library/alpine:latest

t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" '' 200
t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" 200

# Display the image history
t GET libpod/images/nonesuch/history 404
Expand Down
10 changes: 5 additions & 5 deletions test/apiv2/12-imagesMore.at
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ t GET libpod/images/$IMAGE/tree 200 \
.Tree~^Image

# Tag nonesuch image
t POST "libpod/images/nonesuch/tag?repo=myrepo&tag=mytag" '' 404
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 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
Expand All @@ -41,13 +41,13 @@ if [ -z "${GOT_DIGEST}" ] ; then
fi

# Push to local registry
t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" '' 200
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
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
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 \
Expand Down
53 changes: 34 additions & 19 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ t GET libpod/containers/json?all=true 200 \
.[0].ExitCode=0 \
.[0].IsInfra=false

# Test compat API for Network Settings
# Test compat API for Network Settings (.Network is N/A when rootless)
network_expect=
if root; then
network_expect='.[0].NetworkSettings.Networks.podman.NetworkID=podman'
fi
t GET /containers/json?all=true 200 \
length=1 \
.[0].Id~[0-9a-f]\\{64\\} \
.[0].Image=$IMAGE \
.[0].NetworkSettings.Networks.podman.NetworkID=podman
$network_expect
Comment on lines -34 to +43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one non-param-related change, the one I snuck in. All it does is, if running rootless, skip the .NetworkSettings check but run the others.


# Make sure `limit` works.
t GET libpod/containers/json?limit=1 200 \
Expand Down Expand Up @@ -68,9 +72,9 @@ t POST libpod/containers/create?name=test_noargs Image=${IMAGE} 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
# Prior to the fix in #6835, this would fail 500 "args must not be empty"
t POST libpod/containers/${cid}/start '' 204
t POST libpod/containers/${cid}/start 204
# Container should exit almost immediately. Wait for it, confirm successful run
t POST "libpod/containers/${cid}/wait?condition=stopped&condition=exited" '' 200 '0'
t POST "libpod/containers/${cid}/wait?condition=stopped&condition=exited" 200 '0'
t GET libpod/containers/${cid}/json 200 \
.Id=$cid \
.State.Status~\\\(exited\\\|stopped\\\) \
Expand All @@ -85,15 +89,15 @@ t GET libpod/containers/json?all=true 200 \
cid=$(jq -r '.[0].Id' <<<"$output")

# No such container
t POST "libpod/commit?container=nonesuch" '' 404
t POST "libpod/commit?container=nonesuch" 404

# Comment can only be used with docker format, not OCI
cparam="repo=newrepo&comment=foo&author=bob"
t POST "libpod/commit?container=$CNAME&$cparam" '' 500 \
t POST "libpod/commit?container=$CNAME&$cparam" 500 \
.cause="messages are only compatible with the docker image format (-f docker)"

# Commit a new image from the container
t POST "libpod/commit?container=$CNAME" '' 200 \
t POST "libpod/commit?container=$CNAME" 200 \
.Id~[0-9a-f]\\{64\\}
iid=$(jq -r '.Id' <<<"$output")
t GET libpod/images/$iid/json 200 \
Expand All @@ -103,23 +107,23 @@ t GET libpod/images/$iid/json 200 \

# Commit a new image w/o tag
cparam="repo=newrepo&comment=foo&author=bob&format=docker"
t POST "libpod/commit?container=$CNAME&$cparam" '' 200
t POST "libpod/commit?container=$CNAME&$cparam" 200
t GET libpod/images/newrepo:latest/json 200 \
.RepoTags[0]=localhost/newrepo:latest \
.Author=bob \
.Comment=foo

# Commit a new image w/ specified tag and author
cparam="repo=newrepo&tag=v1&author=alice"
t POST "libpod/commit?container=$cid&$cparam&pause=false" '' 200
t POST "libpod/commit?container=$cid&$cparam&pause=false" 200
t GET libpod/images/newrepo:v1/json 200 \
.RepoTags[0]=localhost/newrepo:v1 \
.Author=alice

# Commit a new image w/ full parameters
cparam="repo=newrepo&tag=v2&comment=bar&author=eric"
cparam="$cparam&format=docker&changes=CMD=/bin/foo"
t POST "libpod/commit?container=${cid:0:12}&$cparam&pause=true" '' 200
t POST "libpod/commit?container=${cid:0:12}&$cparam&pause=true" 200
t GET libpod/images/newrepo:v2/json 200 \
.RepoTags[0]=localhost/newrepo:v2 \
.Author=eric \
Expand All @@ -143,7 +147,7 @@ cpid_file=$(jq -r '.ConmonPidFile' <<<"$output")
userdata_path=$(dirname $cpid_file)

# Initializing the container
t POST libpod/containers/myctr/init '' 204
t POST libpod/containers/myctr/init 204

# Check configuration after initializing
t GET libpod/containers/myctr/json 200 \
Expand All @@ -166,7 +170,11 @@ t DELETE libpod/containers/myctr 204

# test apiv2 create container with correct entrypoint and cmd
# --data '{"Image":"quay.io/libpod/alpine_labels:latest","Entrypoint":["echo"],"Cmd":["param1","param2"]}'
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["echo"],"Cmd":["param1","param2"]' 201 \
t POST containers/create \
Image=$IMAGE \
Entrypoint='["echo"]' \
Cmd='["param1","param2"]' \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
Expand All @@ -179,7 +187,10 @@ t GET containers/$cid/json 200 \
t DELETE containers/$cid 204

# test only set the entrypoint, Cmd should be []
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["echo","param1"]' 201 \
t POST containers/create \
Image=$IMAGE \
Entrypoint='["echo","param1"]' \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
Expand All @@ -190,14 +201,14 @@ t GET containers/$cid/json 200 \
.Args[0]="param1"

# create a running container for after
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["top"]' 201 \
t POST containers/create Image=$IMAGE Entrypoint='["top"]' 201 \
.Id~[0-9a-f]\\{64\\}
cid_top=$(jq -r '.Id' <<<"$output")
t GET containers/${cid_top}/json 200 \
.Config.Entrypoint[0]="top" \
.Config.Cmd='[]' \
.Path="top"
t POST containers/${cid_top}/start '' 204
t POST containers/${cid_top}/start 204
# make sure the container is running
t GET containers/${cid_top}/json 200 \
.State.Status="running"
Expand All @@ -219,13 +230,17 @@ t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"],"status":["runn
length=1 \
.[0].Id=${cid_top}

t POST containers/${cid_top}/stop "" 204
t POST containers/${cid_top}/stop 204

t DELETE containers/$cid 204
t DELETE containers/$cid_top 204

# test the WORKDIR and StopSignal
t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","WorkingDir":"/dataDir","StopSignal":"9"' 201 \
t POST containers/create \
Image=$ENV_WORKDIR_IMG \
WorkingDir=/dataDir \
StopSignal=9 \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
Expand All @@ -246,7 +261,7 @@ t DELETE images/${MultiTagName}?force=true 200
# vim: filetype=sh

# Test Volumes field adds an anonymous volume
t POST containers/create '"Image":"'$IMAGE'","Volumes":{"/test":{}}' 201 \
t POST containers/create Image=$IMAGE Volumes='{"/test":{}}' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
Expand All @@ -265,7 +280,7 @@ t GET containers/json 200 \
podman stop bar

# Test CPU limit (NanoCPUs)
t POST containers/create '"Image":"'$IMAGE'","HostConfig":{"NanoCpus":500000}' 201 \
t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
Expand Down
16 changes: 8 additions & 8 deletions test/apiv2/22-stop.at
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ podman pull $IMAGE &>/dev/null
# stop, by name
podman run -dt --name mytop $IMAGE top &>/dev/null

t GET libpod/containers/mytop/json 200 .State.Status=running
t POST libpod/containers/mytop/stop "" 204
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
t DELETE libpod/containers/mytop 204
t GET libpod/containers/mytop/json 200 .State.Status=running
t POST libpod/containers/mytop/stop 204
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
t DELETE libpod/containers/mytop 204

# stop, by ID
# Remember that podman() hides all output; we need to get our CID via inspect
podman run -dt --name mytop $IMAGE top

t GET libpod/containers/mytop/json 200 .State.Status=running
t GET libpod/containers/mytop/json 200 .State.Status=running
cid=$(jq -r .Id <<<"$output")
t POST libpod/containers/$cid/stop "" 204
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
t DELETE libpod/containers/mytop 204
t POST libpod/containers/$cid/stop 204
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
t DELETE libpod/containers/mytop 204
10 changes: 5 additions & 5 deletions test/apiv2/25-containersMore.at
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ t GET libpod/containers/nonesuch/exists 404
t GET libpod/containers/foo/exists 204

# Pause the container
t POST libpod/containers/foo/pause '' 204
t POST libpod/containers/foo/pause 204

t GET libpod/containers/foo/json 200 \
.Id~[0-9a-f]\\{64\\} \
Expand All @@ -27,7 +27,7 @@ t GET libpod/containers/foo/json 200 \
.Name=foo

# Unpause the container
t POST libpod/containers/foo/unpause '' 204
t POST libpod/containers/foo/unpause 204

t GET libpod/containers/foo/json 200 \
.Id~[0-9a-f]\\{64\\} \
Expand All @@ -44,11 +44,11 @@ t GET libpod/containers/foo/top 200 \
t GET libpod/containers/nonesuch/top 404

# Mount the container to host filesystem
t POST libpod/containers/foo/mount '' 200
t POST libpod/containers/foo/mount 200
like "$output" ".*merged" "Check container mount"

# Unmount the container
t POST libpod/containers/foo/unmount '' 204
t POST libpod/containers/foo/unmount 204

t DELETE libpod/containers/foo?force=true 204

Expand Down Expand Up @@ -85,7 +85,7 @@ podman run $IMAGE true
podman run $IMAGE true
podman run $IMAGE true

t POST libpod/containers/prune '' 200
t POST libpod/containers/prune 200
t GET libpod/containers/json 200 \
length=0
# vim: filetype=sh
10 changes: 5 additions & 5 deletions test/apiv2/26-containersWait.at
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ podman rm -a -f &>/dev/null

CTR="WaitTestingCtr"

t POST "containers/nonExistent/wait?condition=next-exit" '' 404
t POST "containers/nonExistent/wait?condition=next-exit" 404

podman create --name "${CTR}" --entrypoint '["sleep", "0.5"]' "${IMAGE}"

t POST "containers/${CTR}/wait?condition=non-existent-cond" '' 400
t POST "containers/${CTR}/wait?condition=non-existent-cond" 400

t POST "containers/${CTR}/wait?condition=not-running" '' 200
t POST "containers/${CTR}/wait?condition=not-running" 200

t POST "containers/${CTR}/wait?condition=next-exit" '' 200 &
t POST "containers/${CTR}/wait?condition=next-exit" 200 &
child_pid=$!
podman start "${CTR}"
wait "${child_pid}"
Expand All @@ -37,7 +37,7 @@ if kill -2 "${child_pid}" 2> "/dev/null"; then
WAIT_TEST_ERROR="1"
fi

t POST "containers/${CTR}/wait?condition=removed" '' 200 &
t POST "containers/${CTR}/wait?condition=removed" 200 &
child_pid=$!
podman container rm "${CTR}"
wait "${child_pid}"
Expand Down
Loading