From e58eeb7826d3fb90939956310aef12e54e854769 Mon Sep 17 00:00:00 2001 From: Aurutus Date: Wed, 2 Aug 2023 19:32:42 +0800 Subject: [PATCH] tests: add standalone test cases for operations_get Signed-off-by: Aurutus --- test/main.sh | 2 ++ test/suites/operations.sh | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 test/suites/operations.sh diff --git a/test/main.sh b/test/main.sh index 9157509f0600..1bbb6b4448e0 100755 --- a/test/main.sh +++ b/test/main.sh @@ -352,6 +352,8 @@ if [ "${1:-"all"}" != "cluster" ]; then run_test test_warnings "Warnings" run_test test_metrics "Metrics" run_test test_storage_volume_recover "Recover storage volumes" + run_test test_operations_get_all "operations_get_all" + run_test test_operations_get_by_project "operations_get_by_project" fi # shellcheck disable=SC2034 diff --git a/test/suites/operations.sh b/test/suites/operations.sh new file mode 100644 index 000000000000..b1406dbf174d --- /dev/null +++ b/test/suites/operations.sh @@ -0,0 +1,62 @@ +test_operations_get_all() { + assert_get_all_operations() { + ( + set -e + echo "==> get all-projects operations normally" + result="$(lxc query "/1.0/operations?all-projects=true" | jq '.success[0]' | wc -l)" + test "${result}" -eq 1 || false + + echo "==> get all-projects operations recursively" + result="$(lxc query "/1.0/operations?recursion=1&all-projects=true" | jq '.success[0]' | grep -c 'status_code')" + test "${result}" -eq 1 || false + ) + } + + ensure_import_testimage + + # create container + name=x1 + lxc launch testimage ${name} + lxc list ${name} | grep RUNNING + + # get_all_operations + lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec + sleep 1 + assert_get_all_operations + + lxc stop "${name}" --force + lxc delete "${name}" +} + +test_operations_get_by_project() { + assert_get_project_operations() { + # $1: query param for project name + ( + set -e + echo "==> get $1 operations normally" + result="$(lxc query "/1.0/operations?project=$1" | jq '.success[0]' | wc -l)" + test "${result}" -eq 1 || false + + echo "==> get $1 operations recursively" + result="$(lxc query "/1.0/operations?recursion=1&project=$1" | jq '.success[0]' | grep -c 'status_code')" + test "${result}" -eq 1 || false + ) + } + + ensure_import_testimage + + project="default" + + # create container + name=x1 + lxc launch testimage ${name} --project ${project} + lxc list ${name} --project ${project} | grep RUNNING + + # get opetaions with project name + lxc query -X POST -d '{\"command\":[\"touch\",\"/root/foo1\"],\"record-output\":false}' /1.0/instances/${name}/exec?project=${project} + sleep 1 + assert_get_project_operations ${project} + + lxc stop "${name}" --force --project ${project} + lxc delete "${name}" --project ${project} +}