summaryrefslogtreecommitdiff
path: root/test/apiv2
diff options
context:
space:
mode:
Diffstat (limited to 'test/apiv2')
-rw-r--r--test/apiv2/01-basic.at8
-rw-r--r--test/apiv2/20-containers.at10
-rw-r--r--test/apiv2/30-volumes.at66
-rwxr-xr-xtest/apiv2/test-apiv233
4 files changed, 85 insertions, 32 deletions
diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at
index 9d4b04edb..f550d5fc3 100644
--- a/test/apiv2/01-basic.at
+++ b/test/apiv2/01-basic.at
@@ -59,7 +59,10 @@ t GET info 200 \
.DefaultRuntime~.*$runtime \
.MemTotal~[0-9]\\+
-# Timing: make sure server stays responsive
+# Timing: make sure server stays responsive.
+# Because /info may need to check storage, it may be slow the first time.
+# Let's invoke it once to prime caches, then run ten queries in a timed loop.
+t GET info 200
t0=$SECONDS
for i in $(seq 1 10); do
# FIXME: someday: refactor t(), separate out the 'curl' logic so we
@@ -70,7 +73,8 @@ t1=$SECONDS
delta_t=$((t1 - t2))
# Desired number of seconds in which we expect to run.
-want=7
+# FIXME: 10 seconds is a lot! PR #8076 opened to investigate why.
+want=10
if [ $delta_t -le $want ]; then
_show_ok 1 "Time for ten /info requests ($delta_t seconds) <= ${want}s"
else
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index 7fbcd2e9c..c7055dfc4 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -206,16 +206,6 @@ t POST containers/${cid_top}/stop "" 204
t DELETE containers/$cid 204
t DELETE containers/$cid_top 204
-# test the apiv2 create, shouldn't ignore the ENV and WORKDIR from the image
-t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","Env":["testKey1"]' 201 \
- .Id~[0-9a-f]\\{64\\}
-cid=$(jq -r '.Id' <<<"$output")
-t GET containers/$cid/json 200 \
- .Config.Env~.*REDIS_VERSION= \
- .Config.Env~.*testKey1= \
- .Config.WorkingDir="/data" # default is /data
-t DELETE containers/$cid 204
-
# test the WORKDIR and StopSignal
t POST containers/create '"Image":"'$ENV_WORKDIR_IMG'","WorkingDir":"/dataDir","StopSignal":"9"' 201 \
.Id~[0-9a-f]\\{64\\}
diff --git a/test/apiv2/30-volumes.at b/test/apiv2/30-volumes.at
index b599680e3..2c38954b6 100644
--- a/test/apiv2/30-volumes.at
+++ b/test/apiv2/30-volumes.at
@@ -3,12 +3,64 @@
# volume-related tests
#
-#
-# FIXME: endpoints seem to be unimplemented, return 404
-#
-if false; then
-t GET libpod/volumes/json 200 null
-t POST libpod/volumes/create name=foo 201
-fi
+## create volume
+t GET libpod/info 200
+volumepath=$(jq -r ".store.volumePath" <<<"$output")
+t POST libpod/volumes/create name=foo1 201 \
+ .Name=foo1 \
+ .Driver=local \
+ .Mountpoint=$volumepath/foo1/_data \
+ .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.* \
+ .Labels={} \
+ .Options=null
+t POST libpod/volumes/create '' 201
+t POST libpod/volumes/create \
+ '"Name":"foo2","Label":{"testlabel":"testonly"},"Options":{"type":"tmpfs","o":"nodev,noexec"}}' 201 \
+ .Name=foo2 \
+ .Labels.testlabel=testonly \
+ .Options.type=tmpfs \
+ .Options.o=nodev,noexec
+
+# Negative test
+# We have created a volume named "foo1"
+t POST libpod/volumes/create name=foo1 500 \
+ .cause="volume already exists" \
+ .message~.* \
+ .response=500
+
+## list volume
+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":["notexist"]}'
+t GET libpod/volumes/json?filters=%7B%22name%22%3A%5B%22notexists%22%5D%7D 200 length=0
+
+## inspect volume
+t GET libpod/volumes/foo1/json 200 \
+ .Name=foo1 \
+ .Mountpoint=$volumepath/foo1/_data \
+ .CreatedAt~[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}.*
+t GET libpod/volumes/notexist/json 404 \
+ .cause="no such volume" \
+ .message~.* \
+ .response=404
+
+## Remove volumes
+t DELETE libpod/volumes/foo1 204
+#After remove foo1 volume, this volume should not exist
+t GET libpod/volumes/foo1/json 404
+# Negative test
+t DELETE libpod/volumes/foo1 404 \
+ .cause="no such volume" \
+ .message~.* \
+ .response=404
+
+## Prune volumes
+t POST libpod/volumes/prune "" 200
+#After prune volumes, there should be no volume existing
+t GET libpod/volumes/json 200 length=0
# vim: filetype=sh
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index 78325eb24..c8ca9df3f 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -179,7 +179,7 @@ function t() {
# POST requests require an extra params arg
if [[ $method = "POST" ]]; then
curl_args="-d $(jsonify $1)"
- testname="$testname [$1]"
+ testname="$testname [$curl_args]"
shift
fi
@@ -204,21 +204,30 @@ function t() {
echo "-------------------------------------------------------------" >>$LOG
echo "\$ $testname" >>$LOG
rm -f $WORKDIR/curl.*
- curl -s -X $method ${curl_args} \
- -H 'Content-type: application/json' \
- --dump-header $WORKDIR/curl.headers.out \
- -o $WORKDIR/curl.result.out "$url"
-
- if [[ $? -eq 7 ]]; then
- echo "FATAL: curl failure on $url - cannot continue" >&2
+ # -s = silent, but --write-out 'format' gives us important response data
+ response=$(curl -s -X $method ${curl_args} \
+ -H 'Content-type: application/json' \
+ --dump-header $WORKDIR/curl.headers.out \
+ --write-out '%{http_code}^%{content_type}^%{time_total}' \
+ -o $WORKDIR/curl.result.out "$url")
+
+ # Any error from curl is instant bad news, from which we can't recover
+ rc=$?
+ if [[ $rc -ne 0 ]]; then
+ echo "FATAL: curl failure ($rc) on $url - cannot continue" >&2
exit 1
fi
- cat $WORKDIR/curl.headers.out >>$LOG 2>/dev/null || true
+ # Show returned headers (without trailing ^M or empty lines) in log file.
+ # Sometimes -- I can't remember why! -- we don't get headers.
+ if [[ -e $WORKDIR/curl.headers.out ]]; then
+ tr -d '\015' < $WORKDIR/curl.headers.out | egrep '.' >>$LOG
+ fi
- # Log results, if text. If JSON, filter through jq for readability.
- content_type=$(sed -ne 's/^Content-Type:[ ]\+//pi' <$WORKDIR/curl.headers.out)
+ IFS='^' read actual_code content_type time_total <<<"$response"
+ printf "X-Response-Time: ${time_total}s\n\n" >>$LOG
+ # Log results, if text. If JSON, filter through jq for readability.
if [[ $content_type =~ /octet ]]; then
output="[$(file --brief $WORKDIR/curl.result.out)]"
echo "$output" >>$LOG
@@ -233,10 +242,8 @@ function t() {
fi
# Test return code
- actual_code=$(head -n1 $WORKDIR/curl.headers.out | awk '/^HTTP/ { print $2}')
is "$actual_code" "$expected_code" "$testname : status"
-
# Special case: 204/304, by definition, MUST NOT return content (rfc2616)
if [[ $expected_code = 204 || $expected_code = 304 ]]; then
if [ -n "$*" ]; then