From d5cabc33375340fd59591dbba7c4474901bacd32 Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Thu, 19 Nov 2020 05:39:34 +0100 Subject: add test Signed-off-by: Matej Vasek --- test/apiv2/23-containersArchive.at | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/apiv2/23-containersArchive.at (limited to 'test') diff --git a/test/apiv2/23-containersArchive.at b/test/apiv2/23-containersArchive.at new file mode 100644 index 000000000..fcbc4373c --- /dev/null +++ b/test/apiv2/23-containersArchive.at @@ -0,0 +1,28 @@ +# -*- sh -*- +# +# test more container-related endpoints +# + +podman pull $IMAGE &>/dev/null + +# Ensure clean slate +podman rm -a -f &>/dev/null + +CTR="ArchiveTestingCtr" + +TMPD=$(mktemp -d) +pushd "${TMPD}" +echo "Hello!" > "hello.txt" &> /dev/null +tar --format=posix -cvf "hello.tar" "hello.txt" &> /dev/null +popd + +HELLO_TAR="${TMPD}/hello.tar" + +podman run -d --name "${CTR}" "${IMAGE}" top + +t HEAD "containers/nonExistentCtr/archive?path=%2F" 404 +t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404 +t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200 + +curl "http://127.0.0.1:$PORT/containers/${CTR}/archive?path=%2Ftmp" -X PUT --upload-file "${HELLO_TAR}" +t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 -- cgit v1.2.3-54-g00ecf From 0dcdb3cc9bfbec56ad545031f3a3472823cd6e8b Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Thu, 19 Nov 2020 18:13:04 +0100 Subject: few more tests Signed-off-by: Matej Vasek --- test/apiv2/23-containersArchive.at | 45 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/apiv2/23-containersArchive.at b/test/apiv2/23-containersArchive.at index fcbc4373c..ee3e6e104 100644 --- a/test/apiv2/23-containersArchive.at +++ b/test/apiv2/23-containersArchive.at @@ -12,7 +12,7 @@ CTR="ArchiveTestingCtr" TMPD=$(mktemp -d) pushd "${TMPD}" -echo "Hello!" > "hello.txt" &> /dev/null +echo "Hello" > "hello.txt" tar --format=posix -cvf "hello.tar" "hello.txt" &> /dev/null popd @@ -24,5 +24,46 @@ t HEAD "containers/nonExistentCtr/archive?path=%2F" 404 t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404 t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200 -curl "http://127.0.0.1:$PORT/containers/${CTR}/archive?path=%2Ftmp" -X PUT --upload-file "${HELLO_TAR}" +curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \ + -X PUT \ + -H "Content-Type: application/x-tar" \ + --upload-file "${HELLO_TAR}" &> /dev/null + + t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 + +curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" \ + --dump-header "${TMPD}/headers.txt" \ + -o "${TMPD}/body.tar" \ + -X GET &> /dev/null + +PATH_STAT="$(grep X-Docker-Container-Path-Stat "${TMPD}/headers.txt" | cut -d " " -f 2 | base64 -d --ignore-garbage)" + +ARCHIVE_TEST_ERROR="" + +red='\e[31m' +nc='\e[0m' + +if [ "$(echo "${PATH_STAT}" | jq ".name")" != '"hello.txt"' ]; then + echo -e "${red}NOK: Wrong name in X-Docker-Container-Path-Stat header.${nc}" 1>&2; + ARCHIVE_TEST_ERROR="1" +fi + +if [ "$(echo "${PATH_STAT}" | jq ".size")" != "6" ]; then + echo -e "${red}NOK: Wrong size in X-Docker-Container-Path-Stat header.${nc}" 1>&2; + ARCHIVE_TEST_ERROR="1" +fi + +if ! tar -tf "${TMPD}/body.tar" | grep "hello.txt" &> /dev/null; then + echo -e "${red}NOK: Body doesn't contain expected file.${nc}" 1>&2; + ARCHIVE_TEST_ERROR="1" +fi + +if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then + echo -e "${red}NOK: Content of file doesn't match.${nc}" 1>&2; + ARCHIVE_TEST_ERROR="1" +fi + +if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then + exit 1; +fi -- cgit v1.2.3-54-g00ecf From 24ff6f45a23d87d413aff477bd3d40993c4b2218 Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Thu, 19 Nov 2020 19:35:16 +0100 Subject: more tests Signed-off-by: Matej Vasek --- test/apiv2/23-containersArchive.at | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/apiv2/23-containersArchive.at b/test/apiv2/23-containersArchive.at index ee3e6e104..a6af6f739 100644 --- a/test/apiv2/23-containersArchive.at +++ b/test/apiv2/23-containersArchive.at @@ -3,6 +3,9 @@ # test more container-related endpoints # +red='\e[31m' +nc='\e[0m' + podman pull $IMAGE &>/dev/null # Ensure clean slate @@ -29,6 +32,10 @@ curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \ -H "Content-Type: application/x-tar" \ --upload-file "${HELLO_TAR}" &> /dev/null +if ! podman exec -it "${CTR}" "grep" "Hello" "/tmp/hello.txt" &> /dev/null ; then + echo -e "${red}NOK: The hello.txt file has not been uploaded.${nc}" 1>&2; + exit 1 +fi t HEAD "containers/${CTR}/archive?path=%2Ftmp%2Fhello.txt" 200 @@ -41,9 +48,6 @@ PATH_STAT="$(grep X-Docker-Container-Path-Stat "${TMPD}/headers.txt" | cut -d " ARCHIVE_TEST_ERROR="" -red='\e[31m' -nc='\e[0m' - if [ "$(echo "${PATH_STAT}" | jq ".name")" != '"hello.txt"' ]; then echo -e "${red}NOK: Wrong name in X-Docker-Container-Path-Stat header.${nc}" 1>&2; ARCHIVE_TEST_ERROR="1" -- cgit v1.2.3-54-g00ecf From 34931ac5dfc1b2d96e826b29bddcfcd3b0e6da35 Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Thu, 19 Nov 2020 21:20:24 +0100 Subject: test resource cleanup Signed-off-by: Matej Vasek --- test/apiv2/23-containersArchive.at | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/apiv2/23-containersArchive.at b/test/apiv2/23-containersArchive.at index a6af6f739..459800196 100644 --- a/test/apiv2/23-containersArchive.at +++ b/test/apiv2/23-containersArchive.at @@ -23,6 +23,12 @@ HELLO_TAR="${TMPD}/hello.tar" podman run -d --name "${CTR}" "${IMAGE}" top +function cleanUpArchiveTest() { + podman container stop "${CTR}" &> /dev/null + podman container rm "${CTR}" &> /dev/null + rm -fr "${TMPD}" &> /dev/null +} + t HEAD "containers/nonExistentCtr/archive?path=%2F" 404 t HEAD "containers/${CTR}/archive?path=%2Fnon%2Fexistent%2Fpath" 404 t HEAD "containers/${CTR}/archive?path=%2Fetc%2Fpasswd" 200 @@ -34,6 +40,7 @@ curl "http://$HOST:$PORT/containers/${CTR}/archive?path=%2Ftmp%2F" \ if ! podman exec -it "${CTR}" "grep" "Hello" "/tmp/hello.txt" &> /dev/null ; then echo -e "${red}NOK: The hello.txt file has not been uploaded.${nc}" 1>&2; + cleanUpArchiveTest exit 1 fi @@ -68,6 +75,7 @@ if [ "$(tar -xf "${TMPD}/body.tar" hello.txt --to-stdout)" != "Hello" ]; then ARCHIVE_TEST_ERROR="1" fi +cleanUpArchiveTest if [[ "${ARCHIVE_TEST_ERROR}" ]] ; then exit 1; fi -- cgit v1.2.3-54-g00ecf