Skip to content

Commit

Permalink
tests: add a test for snapctl is-connected --pid
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenstridge committed Aug 20, 2020
1 parent 223a672 commit ee670df
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/main/snapctl-is-connected-pid/task.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/main/snapctl-is-connected-pid/test-snap1/bin/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "service running"
exec sleep infinity
21 changes: 21 additions & 0 deletions tests/main/snapctl-is-connected-pid/test-snap1/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec snapctl "$@"
20 changes: 20 additions & 0 deletions tests/main/snapctl-is-connected-pid/test-snap2/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ee670df

Please sign in to comment.