From ee670df60f3f3b6465c313fb975d3dd81d89c65c Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Tue, 11 Aug 2020 17:06:55 +0800 Subject: [PATCH] tests: add a test for snapctl is-connected --pid --- tests/main/snapctl-is-connected-pid/task.yaml | 37 +++++++++++++++++++ .../test-snap1/bin/service.sh | 4 ++ .../test-snap1/meta/snap.yaml | 21 +++++++++++ .../test-snap2/bin/run-snapctl.sh | 2 + .../test-snap2/meta/snap.yaml | 20 ++++++++++ 5 files changed, 84 insertions(+) create mode 100644 tests/main/snapctl-is-connected-pid/task.yaml create mode 100755 tests/main/snapctl-is-connected-pid/test-snap1/bin/service.sh create mode 100644 tests/main/snapctl-is-connected-pid/test-snap1/meta/snap.yaml create mode 100755 tests/main/snapctl-is-connected-pid/test-snap2/bin/run-snapctl.sh create mode 100644 tests/main/snapctl-is-connected-pid/test-snap2/meta/snap.yaml diff --git a/tests/main/snapctl-is-connected-pid/task.yaml b/tests/main/snapctl-is-connected-pid/task.yaml new file mode 100644 index 000000000000..dbd931a5a221 --- /dev/null +++ b/tests/main/snapctl-is-connected-pid/task.yaml @@ -0,0 +1,37 @@ +summary: Ensure that "snapctl is-connected --pid" works. + +prepare: | + #shellcheck source=tests/lib/snaps.sh + . "$TESTSLIB"/snaps.sh + install_local test-snap1 + install_local test-snap2 + +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) + + 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" + not test-snap2.snapctl is-connected --pid "$svc_pid" bar-plug + not test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot + + echo "Disconnected interfaces are not connected to non-snap process" + not test-snap2.snapctl is-connected --pid 1 bar-plug + not test-snap2.snapctl is-connected --pid 1 foo-slot + + echo "Connect interfaces" + snap connect test-snap1:foo-plug test-snap2:foo-slot + snap connect test-snap2:bar-plug test-snap1:bar-slot + + echo "Connected interfaces report as connected to snap process" + test-snap2.snapctl is-connected --pid "$svc_pid" bar-plug + test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot + + echo "Interfaces still not connected to non-snap process" + not test-snap2.snapctl is-connected --pid 1 bar-plug + not test-snap2.snapctl is-connected --pid 1 foo-slot diff --git a/tests/main/snapctl-is-connected-pid/test-snap1/bin/service.sh b/tests/main/snapctl-is-connected-pid/test-snap1/bin/service.sh new file mode 100755 index 000000000000..9bf35c478149 --- /dev/null +++ b/tests/main/snapctl-is-connected-pid/test-snap1/bin/service.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "service running" +exec sleep infinity diff --git a/tests/main/snapctl-is-connected-pid/test-snap1/meta/snap.yaml b/tests/main/snapctl-is-connected-pid/test-snap1/meta/snap.yaml new file mode 100644 index 000000000000..afb66781d125 --- /dev/null +++ b/tests/main/snapctl-is-connected-pid/test-snap1/meta/snap.yaml @@ -0,0 +1,21 @@ +name: test-snap1 +version: 1 +summary: First test snap + +plugs: + foo-plug: + interface: content + content: foo + target: $SNAP_COMMON/foo + +slots: + bar-slot: + interface: content + content: bar + read: + - $SNAP + +apps: + svc: + command: bin/service.sh + daemon: simple diff --git a/tests/main/snapctl-is-connected-pid/test-snap2/bin/run-snapctl.sh b/tests/main/snapctl-is-connected-pid/test-snap2/bin/run-snapctl.sh new file mode 100755 index 000000000000..342b0ca89e87 --- /dev/null +++ b/tests/main/snapctl-is-connected-pid/test-snap2/bin/run-snapctl.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec snapctl "$@" diff --git a/tests/main/snapctl-is-connected-pid/test-snap2/meta/snap.yaml b/tests/main/snapctl-is-connected-pid/test-snap2/meta/snap.yaml new file mode 100644 index 000000000000..84d4d1344e72 --- /dev/null +++ b/tests/main/snapctl-is-connected-pid/test-snap2/meta/snap.yaml @@ -0,0 +1,20 @@ +name: test-snap2 +version: 1 +summary: Second test snap + +plugs: + bar-plug: + interface: content + content: bar + target: $SNAP_COMMON/bar + +slots: + foo-slot: + interface: content + content: foo + read: + - $SNAP + +apps: + snapctl: + command: bin/run-snapctl.sh