Skip to content

Commit

Permalink
tests: add standalone test cases for operations_get
Browse files Browse the repository at this point in the history
  • Loading branch information
AuruTus committed Aug 2, 2023
1 parent 09ecaed commit d496f40
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions test/suites/operations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
test_operations_get_all() {
assert_get_all_operations() {
(
set -e
echo "==> get all-projects operations normally"
local 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 -F 'status_code' | wc -l)
test ${result} -eq 1 || false
)
}

ensure_import_testimage

# create container
local 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() {
# query param for project name
local project=$1
(
set -e
echo "==> get ${project} operations normally"
local result=$(lxc query "/1.0/operations?project=${project}" | jq '.success[0]' | wc -l)
test ${result} -eq 1 || echo 1

echo "==> get ${project} operations recursively"
result=$(lxc query "/1.0/operations?recursion=1&project=${project}" | jq '.success[0]' | grep -F 'status_code' | wc -l)
test ${result} -eq 1 || echo 2
)
}

ensure_import_testimage

local project="default"

# create container
local 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}
}

0 comments on commit d496f40

Please sign in to comment.