mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
APIv2 tests: make more maintainable
While I wasn't looking, some completely unreadable cruft crept in here, and it's totally my fault: I never knew you could pass JSON to a GET query. Everyone who DID know that, did so, but had to URL-escape it into a completely gobbledygook mess to make curl happy. Solution: trivial, do the URL-escaping in 't' itself. I just never realized that was needed. I'm so sorry. I hope this helps. Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
@ -206,9 +206,9 @@ t GET 'containers/json?limit=0&all=1' 200 \
|
||||
t GET containers/json?limit=2 200 length=2
|
||||
|
||||
# Filter with two ids should return both container
|
||||
t GET "containers/json?filters=%7B%22id%22%3A%5B%22${cid}%22%2C%22${cid_top}%22%5D%7D&all=1" 200 length=2
|
||||
t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"]}&all=1' 200 length=2
|
||||
# Filter with two ids and status running should return only 1 container
|
||||
t GET "containers/json?filters=%7B%22id%22%3A%5B%22${cid}%22%2C%22${cid_top}%22%5D%2C%22status%22%3A%5B%22running%22%5D%7D&all=1" 200 \
|
||||
t GET containers/json?filters='{"id":["'${cid}'","'${cid_top}'"],"status":["running"]}&all=1' 200 \
|
||||
length=1 \
|
||||
.[0].Id=${cid_top}
|
||||
|
||||
|
@ -45,18 +45,17 @@ t GET libpod/volumes/json 200 \
|
||||
.[0].Name~.* \
|
||||
.[0].Mountpoint~.* \
|
||||
.[0].CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
|
||||
# -G --data-urlencode 'filters={"name":["foo1"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22foo1%22%5D%7D 200 length=1 .[0].Name=foo1
|
||||
# -G --data-urlencode 'filters={"name":["foo1","foo2"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22name%22%3A%20%5B%22foo1%22%2C%20%22foo2%22%5D%7D 200 length=2 .[0].Name=foo1 .[1].Name=foo2
|
||||
# -G --data-urlencode 'filters={"name":["nonexistent"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22nonexistent%22%5D%7D 200 length=0
|
||||
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=2
|
||||
# -G --data-urlencode 'filters={"label":["testlabel=testonly"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel=testonly%22%5D%7D 200 length=1
|
||||
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=1
|
||||
t GET libpod/volumes/json?filters='{"name":["foo1"]}' 200 \
|
||||
length=1 \
|
||||
.[0].Name=foo1
|
||||
t GET libpod/volumes/json?filters='{"name":%20["foo1",%20"foo2"]}' 200 \
|
||||
length=2 \
|
||||
.[0].Name=foo1 \
|
||||
.[1].Name=foo2
|
||||
t GET libpod/volumes/json?filters='{"name":["nonexistent"]}' 200 length=0
|
||||
t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=2
|
||||
t GET libpod/volumes/json?filters='{"label":["testlabel=testonly"]}' 200 length=1
|
||||
t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=1
|
||||
|
||||
## inspect volume
|
||||
t GET libpod/volumes/foo1/json 200 \
|
||||
@ -79,16 +78,12 @@ t DELETE libpod/volumes/foo1 404 \
|
||||
.response=404
|
||||
|
||||
## Prune volumes with label matching 'testlabel1=testonly'
|
||||
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
||||
t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D "" 200
|
||||
# -G --data-urlencode 'filters={"label":["testlabel1=testonly"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D 200 length=0
|
||||
t POST libpod/volumes/prune?filters='{"label":["testlabel1=testonly"]}' "" 200
|
||||
t GET libpod/volumes/json?filters='{"label":["testlabel1=testonly"]}' 200 length=0
|
||||
|
||||
## Prune volumes with label matching 'testlabel'
|
||||
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
||||
t POST libpod/volumes/prune?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D "" 200
|
||||
# -G --data-urlencode 'filters={"label":["testlabel"]}'
|
||||
t GET libpod/volumes/json?filters=%7B%22label%22:%5B%22testlabel%22%5D%7D 200 length=0
|
||||
t POST libpod/volumes/prune?filters='{"label":["testlabel"]}' "" 200
|
||||
t GET libpod/volumes/json?filters='{"label":["testlabel"]}' 200 length=0
|
||||
|
||||
## Prune volumes
|
||||
t POST libpod/volumes/prune "" 200
|
||||
|
@ -7,57 +7,52 @@ t GET networks/non-existing-network 404 \
|
||||
.cause='network not found'
|
||||
|
||||
t POST libpod/networks/create?name=network1 '' 200 \
|
||||
.Filename~.*/network1\\.conflist
|
||||
.Filename~.*/network1\\.conflist
|
||||
|
||||
# --data '{"Subnet":{"IP":"10.10.254.0","Mask":[255,255,255,0]},"Labels":{"abc":"val"}}'
|
||||
t POST libpod/networks/create?name=network2 '"Subnet":{"IP":"10.10.254.0","Mask":[255,255,255,0]},"Labels":{"abc":"val"}' 200 \
|
||||
.Filename~.*/network2\\.conflist
|
||||
.Filename~.*/network2\\.conflist
|
||||
|
||||
# test for empty mask
|
||||
t POST libpod/networks/create '"Subnet":{"IP":"10.10.1.0","Mask":[]}' 500 \
|
||||
.cause~'.*cannot be empty'
|
||||
.cause~'.*cannot be empty'
|
||||
# test for invalid mask
|
||||
t POST libpod/networks/create '"Subnet":{"IP":"10.10.1.0","Mask":[0,255,255,0]}' 500 \
|
||||
.cause~'.*mask is invalid'
|
||||
.cause~'.*mask is invalid'
|
||||
|
||||
# network list
|
||||
t GET libpod/networks/json 200
|
||||
# filters={"name":["network1"]}
|
||||
t GET libpod/networks/json?filters=%7B%22name%22%3A%5B%22network1%22%5D%7D 200 \
|
||||
length=1 \
|
||||
.[0].Name=network1
|
||||
t GET libpod/networks/json?filters='{"name":["network1"]}' 200 \
|
||||
length=1 \
|
||||
.[0].Name=network1
|
||||
t GET networks 200
|
||||
|
||||
#network list docker endpoint
|
||||
#filters={"name":["network1","network2"]}
|
||||
t GET networks?filters=%7B%22name%22%3A%5B%22network1%22%2C%22network2%22%5D%7D 200 \
|
||||
length=2
|
||||
#filters={"name":["network"]}
|
||||
t GET networks?filters=%7B%22name%22%3A%5B%22network%22%5D%7D 200 \
|
||||
length=2
|
||||
# filters={"label":["abc"]}
|
||||
t GET networks?filters=%7B%22label%22%3A%5B%22abc%22%5D%7D 200 \
|
||||
length=1
|
||||
# filters={"label":{"abc":true}} old docker filter type see #9526
|
||||
t GET networks?filters=%7B%22label%22%3A%7B%22abc%22%3Atrue%7D%7D 200 \
|
||||
length=1
|
||||
# id filter filters={"id":["a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1"]}
|
||||
t GET networks?filters=%7B%22id%22%3A%5B%22a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1%22%5D%7D 200 \
|
||||
length=1 \
|
||||
.[0].Name=network1 \
|
||||
.[0].Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1
|
||||
# invalid filter filters={"dangling":["1"]}
|
||||
t GET networks?filters=%7B%22dangling%22%3A%5B%221%22%5D%7D 500 \
|
||||
.cause='invalid filter "dangling"'
|
||||
t GET networks?filters='{"name":["network1","network2"]}' 200 \
|
||||
length=2
|
||||
t GET networks?filters='{"name":["network"]}' 200 \
|
||||
length=2
|
||||
t GET networks?filters='{"label":["abc"]}' 200 \
|
||||
length=1
|
||||
# old docker filter type see #9526
|
||||
t GET networks?filters='{"label":{"abc":true}}' 200 \
|
||||
length=1
|
||||
t GET networks?filters='{"id":["a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1"]}' 200 \
|
||||
length=1 \
|
||||
.[0].Name=network1 \
|
||||
.[0].Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1
|
||||
# invalid filter
|
||||
t GET networks?filters='{"dangling":["1"]}' 500 \
|
||||
.cause='invalid filter "dangling"'
|
||||
# (#9293 with no networks the endpoint should return empty array instead of null)
|
||||
t GET networks?filters=%7B%22name%22%3A%5B%22doesnotexists%22%5D%7D 200 \
|
||||
"[]"
|
||||
t GET networks?filters='{"name":["doesnotexists"]}' 200 \
|
||||
"[]"
|
||||
|
||||
# network inspect docker
|
||||
t GET networks/a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 200 \
|
||||
.Name=network1 \
|
||||
.Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 \
|
||||
.Scope=local
|
||||
.Name=network1 \
|
||||
.Id=a7662f44d65029fd4635c91feea3d720a57cef52e2a9fcc7772b69072cc1ccd1 \
|
||||
.Scope=local
|
||||
|
||||
# network create docker
|
||||
t POST networks/create '"Name":"net3","IPAM":{"Config":[]}' 201
|
||||
@ -66,11 +61,11 @@ t DELETE networks/net3 204
|
||||
|
||||
# clean the network
|
||||
t DELETE libpod/networks/network1 200 \
|
||||
.[0].Name~network1 \
|
||||
.[0].Err=null
|
||||
.[0].Name~network1 \
|
||||
.[0].Err=null
|
||||
t DELETE libpod/networks/network2 200 \
|
||||
.[0].Name~network2 \
|
||||
.[0].Err=null
|
||||
.[0].Name~network2 \
|
||||
.[0].Err=null
|
||||
|
||||
|
||||
# vim: filetype=sh
|
||||
|
@ -49,18 +49,16 @@ t GET libpod/system/df 200 '.Volumes | length=3'
|
||||
|
||||
# Prune volumes
|
||||
|
||||
# -G --data-urlencode 'volumes=true&filters={"label":["testlabel1=idontmatch"]}'
|
||||
t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1=idontmatch%22%5D%7D' params='' 200
|
||||
t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1=idontmatch"]}' params='' 200
|
||||
|
||||
# nothing should have been pruned
|
||||
t GET system/df 200 '.Volumes | length=3'
|
||||
t GET libpod/system/df 200 '.Volumes | length=3'
|
||||
|
||||
# -G --data-urlencode 'volumes=true&filters={"label":["testlabel1=testonly"]}'
|
||||
# only foo3 should be pruned because of filter
|
||||
t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1=testonly%22%5D%7D' params='' 200 .VolumePruneReports[0].Id=foo3
|
||||
t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1=testonly"]}' params='' 200 .VolumePruneReports[0].Id=foo3
|
||||
# only foo2 should be pruned because of filter
|
||||
t POST 'libpod/system/prune?volumes=true&filters=%7B%22label%22:%5B%22testlabel1%22%5D%7D' params='' 200 .VolumePruneReports[0].Id=foo2
|
||||
t POST 'libpod/system/prune?volumes=true&filters={"label":["testlabel1"]}' params='' 200 .VolumePruneReports[0].Id=foo2
|
||||
# foo1, the last remaining volume should be pruned without any filters applied
|
||||
t POST 'libpod/system/prune?volumes=true' params='' 200 .VolumePruneReports[0].Id=foo1
|
||||
|
||||
|
@ -25,7 +25,7 @@ t GET secrets 200\
|
||||
length=1
|
||||
|
||||
# secret list unsupported filters
|
||||
t GET secrets?filters=%7B%22name%22%3A%5B%22foo1%22%5D%7D 400
|
||||
t GET secrets?filters='{"name":["foo1"]}' 400
|
||||
|
||||
# secret rm
|
||||
t DELETE secrets/mysecret 204
|
||||
|
@ -188,6 +188,13 @@ function t() {
|
||||
# entrypoint path can include a descriptive comment; strip it off
|
||||
path=${path%% *}
|
||||
|
||||
# path may include JSONish params that curl will barf on; url-encode them
|
||||
path="${path//'['/%5B}"
|
||||
path="${path//']'/%5D}"
|
||||
path="${path//'{'/%7B}"
|
||||
path="${path//'}'/%7D}"
|
||||
path="${path//':'/%3A}"
|
||||
|
||||
# curl -X HEAD but without --head seems to wait for output anyway
|
||||
if [[ $method == "HEAD" ]]; then
|
||||
curl_args="--head"
|
||||
|
Reference in New Issue
Block a user