Skip to content

Commit

Permalink
tests: spread test cleanups suggested by @zyga
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge committed Aug 28, 2020
1 parent 352e7de commit 819ab76
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions tests/main/snapctl-is-connected-pid/task.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
summary: Ensure that "snapctl is-connected --pid" works.

prepare: |
tests.cleanup prepare
#shellcheck source=tests/lib/snaps.sh
. "$TESTSLIB"/snaps.sh
install_local test-snap1
Expand All @@ -14,44 +15,37 @@ prepare: |
# we still want to verify if the basics do work if the user
# symlinks /snap to $SNAP_MOUNT_DIR themselves
ln -sf $SNAP_MOUNT_DIR /snap
tests.cleanup defer rm -f /snap
;;
esac
restore: |
case "$SPREAD_SYSTEM" in
fedora-*|arch-*|centos-*)
rm -f /snap
;;
esac
tests.cleanup.restore
execute: |
echo "The test-snap1 service is running"
systemctl is-active snap.test-snap1.svc.service
svc_pid=$(systemctl show --property=MainPID snap.test-snap1.svc.service | cut -d = -f 2)
fail() {
expect_status() {
expected="$1"
shift
if "$@"; then
echo "Expected command to fail"
exit 1
else
err="$?"
test "$err" -eq "$expected"
fi
# Temporarily turn off "set -e" so we can check the exit status
set +e; "$@"; local ret=$?; set -e
test "$ret" -eq "$expected"
}
echo "Plugs and slots are initially disconnected"
not test-snap2.snapctl is-connected bar-plug
not test-snap2.snapctl is-connected foo-slot
echo "Disconnected interfaces are not connected to a snap process"
fail 1 test-snap2.snapctl is-connected --pid "$svc_pid" bar-plug
fail 1 test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot
expect_status 1 test-snap2.snapctl is-connected --pid "$svc_pid" bar-plug
expect_status 1 test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot
echo "Disconnected interfaces are not connected to non-snap process"
fail 10 test-snap2.snapctl is-connected --pid 1 bar-plug
fail 10 test-snap2.snapctl is-connected --pid 1 foo-slot
expect_status 10 test-snap2.snapctl is-connected --pid 1 bar-plug
expect_status 10 test-snap2.snapctl is-connected --pid 1 foo-slot
echo "Connect interfaces"
snap connect test-snap1:foo-plug test-snap2:foo-slot
Expand All @@ -62,8 +56,8 @@ execute: |
test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot
echo "Interfaces still not connected to non-snap process"
fail 10 test-snap2.snapctl is-connected --pid 1 bar-plug
fail 10 test-snap2.snapctl is-connected --pid 1 foo-slot
expect_status 10 test-snap2.snapctl is-connected --pid 1 bar-plug
expect_status 10 test-snap2.snapctl is-connected --pid 1 foo-slot
# The remaining tests rely on classic confinement, so skip Ubuntu Core
if [[ "$SPREAD_SYSTEM" = ubuntu-core-* ]]; then
Expand All @@ -79,7 +73,7 @@ execute: |
classic_pid=$(systemctl show --property=MainPID snap.test-snap-classic.svc.service | cut -d = -f 2)
echo "Unconnected classic snaps report a special exit code"
fail 11 test-snap2.snapctl is-connected --pid "$classic_pid" foo-slot
expect_status 11 test-snap2.snapctl is-connected --pid "$classic_pid" foo-slot
echo "But still reports success when connected"
snap connect test-snap-classic:foo-plug test-snap2:foo-slot
Expand Down

0 comments on commit 819ab76

Please sign in to comment.