Skip to content

Commit 81737b3

Browse files
authored
Merge pull request #9686 from edsantiago/apiv2_jsonify
apiv2 tests: finally fix POST as originally intended
2 parents 8d33bfa + 258749e commit 81737b3

15 files changed

+186
-131
lines changed

test/apiv2/01-basic.at

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ done
3030
# Garbage tests - requests that should yield errors
3131
#
3232
t GET /nonesuch 404
33-
t POST /nonesuch '' 404
33+
t POST /nonesuch 404
3434
t GET container/nonesuch/json 404
3535
t GET libpod/containers/nonesuch/json 404
3636

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

3939
# Method not allowed
40-
t POST /_ping '' 405
40+
t POST /_ping 405
4141
t DELETE /_ping 405
42-
t POST libpod/containers/json '' 405
43-
t POST libpod/pods/abc '' 405
44-
t POST info '' 405
42+
t POST libpod/containers/json 405
43+
t POST libpod/pods/abc 405
44+
t POST info 405
4545
t GET libpod/containers/create 405
4646

4747
#

test/apiv2/10-images.at

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ t GET images/$iid/json 200 \
4141
.Id=sha256:$iid \
4242
.RepoTags[0]=$IMAGE
4343

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

46-
t POST "images/create?fromImage=alpine&tag=latest" '' 200
46+
t POST "images/create?fromImage=alpine&tag=latest" 200
4747

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

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

5757
# Display the image history
5858
t GET libpod/images/nonesuch/history 404

test/apiv2/12-imagesMore.at

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ t GET libpod/images/$IMAGE/tree 200 \
1717
.Tree~^Image
1818

1919
# Tag nonesuch image
20-
t POST "libpod/images/nonesuch/tag?repo=myrepo&tag=mytag" '' 404
20+
t POST "libpod/images/nonesuch/tag?repo=myrepo&tag=mytag" 404
2121

2222
# Tag the image
23-
t POST "libpod/images/$IMAGE/tag?repo=localhost:5000/myrepo&tag=mytag" '' 201
23+
t POST "libpod/images/$IMAGE/tag?repo=localhost:5000/myrepo&tag=mytag" 201
2424

2525
t GET libpod/images/$IMAGE/json 200 \
2626
.RepoTags[1]=localhost:5000/myrepo:mytag
@@ -41,13 +41,13 @@ if [ -z "${GOT_DIGEST}" ] ; then
4141
fi
4242

4343
# Push to local registry
44-
t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" '' 200
44+
t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" 200
4545

4646
# Untag the image
47-
t POST "libpod/images/$iid/untag?repo=localhost:5000/myrepo&tag=mytag" '' 201
47+
t POST "libpod/images/$iid/untag?repo=localhost:5000/myrepo&tag=mytag" 201
4848

4949
# Try to push non-existing image
50-
t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" '' 200
50+
t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" 200
5151
jq -re 'select(.errorDetail)' <<<"$output" &>/dev/null || echo -e "${red}not ok: error message not found in output${nc}" 1>&2
5252

5353
t GET libpod/images/$IMAGE/json 200 \

test/apiv2/20-containers.at

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ t GET libpod/containers/json?all=true 200 \
3131
.[0].ExitCode=0 \
3232
.[0].IsInfra=false
3333

34-
# Test compat API for Network Settings
34+
# Test compat API for Network Settings (.Network is N/A when rootless)
35+
network_expect=
36+
if root; then
37+
network_expect='.[0].NetworkSettings.Networks.podman.NetworkID=podman'
38+
fi
3539
t GET /containers/json?all=true 200 \
3640
length=1 \
3741
.[0].Id~[0-9a-f]\\{64\\} \
3842
.[0].Image=$IMAGE \
39-
.[0].NetworkSettings.Networks.podman.NetworkID=podman
43+
$network_expect
4044

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

8791
# No such container
88-
t POST "libpod/commit?container=nonesuch" '' 404
92+
t POST "libpod/commit?container=nonesuch" 404
8993

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

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

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

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

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

145149
# Initializing the container
146-
t POST libpod/containers/myctr/init '' 204
150+
t POST libpod/containers/myctr/init 204
147151

148152
# Check configuration after initializing
149153
t GET libpod/containers/myctr/json 200 \
@@ -167,7 +171,11 @@ t DELETE libpod/containers/bogus 404
167171

168172
# test apiv2 create container with correct entrypoint and cmd
169173
# --data '{"Image":"quay.io/libpod/alpine_labels:latest","Entrypoint":["echo"],"Cmd":["param1","param2"]}'
170-
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["echo"],"Cmd":["param1","param2"]' 201 \
174+
t POST containers/create \
175+
Image=$IMAGE \
176+
Entrypoint='["echo"]' \
177+
Cmd='["param1","param2"]' \
178+
201 \
171179
.Id~[0-9a-f]\\{64\\}
172180
cid=$(jq -r '.Id' <<<"$output")
173181
t GET containers/$cid/json 200 \
@@ -180,7 +188,10 @@ t GET containers/$cid/json 200 \
180188
t DELETE containers/$cid 204
181189

182190
# test only set the entrypoint, Cmd should be []
183-
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["echo","param1"]' 201 \
191+
t POST containers/create \
192+
Image=$IMAGE \
193+
Entrypoint='["echo","param1"]' \
194+
201 \
184195
.Id~[0-9a-f]\\{64\\}
185196
cid=$(jq -r '.Id' <<<"$output")
186197
t GET containers/$cid/json 200 \
@@ -191,14 +202,14 @@ t GET containers/$cid/json 200 \
191202
.Args[0]="param1"
192203

193204
# create a running container for after
194-
t POST containers/create '"Image":"'$IMAGE'","Entrypoint":["top"]' 201 \
205+
t POST containers/create Image=$IMAGE Entrypoint='["top"]' 201 \
195206
.Id~[0-9a-f]\\{64\\}
196207
cid_top=$(jq -r '.Id' <<<"$output")
197208
t GET containers/${cid_top}/json 200 \
198209
.Config.Entrypoint[0]="top" \
199210
.Config.Cmd='[]' \
200211
.Path="top"
201-
t POST containers/${cid_top}/start '' 204
212+
t POST containers/${cid_top}/start 204
202213
# make sure the container is running
203214
t GET containers/${cid_top}/json 200 \
204215
.State.Status="running"
@@ -220,13 +231,17 @@ t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"],"status":["runn
220231
length=1 \
221232
.[0].Id=${cid_top}
222233

223-
t POST containers/${cid_top}/stop "" 204
234+
t POST containers/${cid_top}/stop 204
224235

225236
t DELETE containers/$cid 204
226237
t DELETE containers/$cid_top 204
227238

228239
# test the WORKDIR and StopSignal
229-
t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","WorkingDir":"/dataDir","StopSignal":"9"' 201 \
240+
t POST containers/create \
241+
Image=$ENV_WORKDIR_IMG \
242+
WorkingDir=/dataDir \
243+
StopSignal=9 \
244+
201 \
230245
.Id~[0-9a-f]\\{64\\}
231246
cid=$(jq -r '.Id' <<<"$output")
232247
t GET containers/$cid/json 200 \
@@ -247,7 +262,7 @@ t DELETE images/${MultiTagName}?force=true 200
247262
# vim: filetype=sh
248263

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

268283
# Test CPU limit (NanoCPUs)
269-
t POST containers/create '"Image":"'$IMAGE'","HostConfig":{"NanoCpus":500000}' 201 \
284+
t POST containers/create Image=$IMAGE HostConfig='{"NanoCpus":500000}' 201 \
270285
.Id~[0-9a-f]\\{64\\}
271286
cid=$(jq -r '.Id' <<<"$output")
272287
t GET containers/$cid/json 200 \

test/apiv2/22-stop.at

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ podman pull $IMAGE &>/dev/null
88
# stop, by name
99
podman run -dt --name mytop $IMAGE top &>/dev/null
1010

11-
t GET libpod/containers/mytop/json 200 .State.Status=running
12-
t POST libpod/containers/mytop/stop "" 204
13-
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
14-
t DELETE libpod/containers/mytop 204
11+
t GET libpod/containers/mytop/json 200 .State.Status=running
12+
t POST libpod/containers/mytop/stop 204
13+
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
14+
t DELETE libpod/containers/mytop 204
1515

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

20-
t GET libpod/containers/mytop/json 200 .State.Status=running
20+
t GET libpod/containers/mytop/json 200 .State.Status=running
2121
cid=$(jq -r .Id <<<"$output")
22-
t POST libpod/containers/$cid/stop "" 204
23-
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
24-
t DELETE libpod/containers/mytop 204
22+
t POST libpod/containers/$cid/stop 204
23+
t GET libpod/containers/mytop/json 200 .State.Status~\\\(exited\\\|stopped\\\)
24+
t DELETE libpod/containers/mytop 204

test/apiv2/25-containersMore.at

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ t GET libpod/containers/nonesuch/exists 404
1717
t GET libpod/containers/foo/exists 204
1818

1919
# Pause the container
20-
t POST libpod/containers/foo/pause '' 204
20+
t POST libpod/containers/foo/pause 204
2121

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

2929
# Unpause the container
30-
t POST libpod/containers/foo/unpause '' 204
30+
t POST libpod/containers/foo/unpause 204
3131

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

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

5050
# Unmount the container
51-
t POST libpod/containers/foo/unmount '' 204
51+
t POST libpod/containers/foo/unmount 204
5252

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

@@ -85,7 +85,7 @@ podman run $IMAGE true
8585
podman run $IMAGE true
8686
podman run $IMAGE true
8787

88-
t POST libpod/containers/prune '' 200
88+
t POST libpod/containers/prune 200
8989
t GET libpod/containers/json 200 \
9090
length=0
9191
# vim: filetype=sh

test/apiv2/26-containersWait.at

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ podman rm -a -f &>/dev/null
1313

1414
CTR="WaitTestingCtr"
1515

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

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

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

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

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

40-
t POST "containers/${CTR}/wait?condition=removed" '' 200 &
40+
t POST "containers/${CTR}/wait?condition=removed" 200 &
4141
child_pid=$!
4242
podman container rm "${CTR}"
4343
wait "${child_pid}"

0 commit comments

Comments
 (0)