diff --git a/.packit.yaml b/.packit.yaml index 28f985dd..d5d7f522 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -18,4 +18,15 @@ jobs: - job: copr_build trigger: pull_request targets: - - fedora-all + - fedora-all-aarch64 + - fedora-all-ppc64le + - fedora-all-s390x + - fedora-all-x86_64 + +- job: tests + trigger: pull_request + fmf_path: test/integration/ + tmt_plan: upstream-ci + targets: + - fedora-all-aarch64 + - fedora-all-x86_64 diff --git a/test/integration/.fmf/version b/test/integration/.fmf/version new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/test/integration/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/test/integration/README b/test/integration/README new file mode 100644 index 00000000..5a6d7fb4 --- /dev/null +++ b/test/integration/README @@ -0,0 +1,54 @@ +# polkit integration test suite + +polkit's integration test suite uses TMT (Test Management Tool [0]) to organize and run tests. Since TMT +offers a _lot_ of features, this document pinpoints the most _interesting_ ones to get stuff up and running +quickly. + +## How to contribute + +Creating a new test case is pretty simple: + +``` +$ cd test/integration +$ tmt test create --template=shell test/name +Test directory '/home/.../polkit/test/integration/test/name' created. +Test metadata '/home/.../polkit/test/integration/test/name/main.fmf' created. +Test script '/home/.../polkit/test/integration/test/name/test.sh' created. +``` + +The newly created `test.sh` will be the actual test case, and `main.fmf` contains the test metadata, including +test summary & description, test dependencies, runtime, and so on. See [1] for more details. + +After tweaking the test metadata it's usually a good idea to run `tmt lint test/name` to make sure that the +configuration is still valid: + +``` +$ tmt lint test/name +/test/name +pass C000 fmf node passes schema validation +pass C001 summary key is set and is reasonably long +... +``` + +To check if the test itself works as expected you can use `tmt run`: + +``` +$ cd test/name +$ tmt run -vvv --all provision --how local tests --name . +... +total: 1 test passed +``` + +The `tmt run` command is _very_ customizable (as is the rest of `tmt`). In this particular example we tell it +to run all steps (`--all`) and override the `provision` and `tests` steps to run just one particular test on +the local machine. As in previous cases, check the `tmt` documentation [0] and examples [2] for more details. + +## Links + +[0] https://tmt.readthedocs.io/en/stable/overview.html + +[1] https://tmt.readthedocs.io/en/stable/spec/tests.html + +[2] https://tmt.readthedocs.io/en/stable/examples.html#run + + diff --git a/test/integration/main.fmf b/test/integration/main.fmf new file mode 100644 index 00000000..2cc69b80 --- /dev/null +++ b/test/integration/main.fmf @@ -0,0 +1,2 @@ +require: + - polkit diff --git a/test/integration/plans/upstream-ci.fmf b/test/integration/plans/upstream-ci.fmf new file mode 100644 index 00000000..ba267ab8 --- /dev/null +++ b/test/integration/plans/upstream-ci.fmf @@ -0,0 +1,11 @@ +# vi: set sw=2 ts=2 et ft=yaml tw=80: + +# This plan discovers and executes all (enabled) integration tests + +summary: Upstream integration test suite +/: + inherit: false +discover: + how: fmf +execute: + how: tmt diff --git a/test/integration/systemd/main.fmf b/test/integration/systemd/main.fmf new file mode 100644 index 00000000..f3aef084 --- /dev/null +++ b/test/integration/systemd/main.fmf @@ -0,0 +1,2 @@ +summary: Check integration with systemd +test: ./test.sh diff --git a/test/integration/systemd/rules/start-restart-stop-unit.rules b/test/integration/systemd/rules/start-restart-stop-unit.rules new file mode 100644 index 00000000..26cbb505 --- /dev/null +++ b/test/integration/systemd/rules/start-restart-stop-unit.rules @@ -0,0 +1,8 @@ +polkit.addRule(function(action, subject) { + if (action.id == "org.freedesktop.systemd1.manage-units") { + if (subject.user == "polkit-testuser" && action.lookup("unit") == "start-restart-stop.service" && + (action.lookup("verb") == "restart" || action.lookup("verb") == "stop" || action.lookup("verb") == "start")) { + return polkit.Result.YES; + } + } +}); diff --git a/test/integration/systemd/test.sh b/test/integration/systemd/test.sh new file mode 100755 index 00000000..c0f6f015 --- /dev/null +++ b/test/integration/systemd/test.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -eux +set -o pipefail + +TEST_RULES="$PWD/rules" +TEST_USER="polkit-testuser" + +at_exit() { + set +e + + : "Cleanup" + userdel -rf "$TEST_USER" + rm -f /etc/polkit-1/rules.d/99-test.rules + systemctl restart polkit +} + +trap at_exit EXIT + +: "Setup" +mkdir -p /run/systemd/system/ +useradd "$TEST_USER" +# Close stdin, so we get an instant error (Interactive authentication required) instead of having to deal +# with an interactive authentication prompt +exec 0<&- + +: "Allow $TEST_USER to start/restart/stop a simple systemd unit" +# Use `systemctl edit --full ...` in the future +cat >/run/systemd/system/start-restart-stop.service <