Skip to content

Commit

Permalink
tests: add standalone test cases for operations_get
Browse files Browse the repository at this point in the history
Signed-off-by: Aurutus <emslhy@hotmail.com>
  • Loading branch information
AuruTus committed Aug 3, 2023
1 parent 76320de commit e58eeb7
Show file tree
Hide file tree
Showing 2 changed files with 64 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
62 changes: 62 additions & 0 deletions test/suites/operations.sh
Original file line number Diff line number Diff line change
@@ -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}
}

0 comments on commit e58eeb7

Please sign in to comment.