diff --git a/tests/main/component-hooks/comp-with-install-hook/meta/component.yaml b/tests/main/component-hooks/comp-with-install-hook/meta/component.yaml new file mode 100644 index 000000000000..670eadf263a1 --- /dev/null +++ b/tests/main/component-hooks/comp-with-install-hook/meta/component.yaml @@ -0,0 +1,5 @@ +component: snap-with-comps+comp-with-install-hook +type: test +version: 1.0 +summary: Component 1 +description: First component for snap-with-comps diff --git a/tests/main/component-hooks/comp-with-install-hook/meta/hooks/install b/tests/main/component-hooks/comp-with-install-hook/meta/hooks/install new file mode 100755 index 000000000000..374ef8438cda --- /dev/null +++ b/tests/main/component-hooks/comp-with-install-hook/meta/hooks/install @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +printf "GET /ip HTTP/1.0\r\n\r\n" | nc httpbin.org 80 2>&1 > "${SNAP_COMMON}/install-logs" + +touch "${SNAP_COMMON}/install-done" diff --git a/tests/main/component-hooks/snap-with-comps/meta/snap.yaml b/tests/main/component-hooks/snap-with-comps/meta/snap.yaml new file mode 100644 index 000000000000..8326d147c5a8 --- /dev/null +++ b/tests/main/component-hooks/snap-with-comps/meta/snap.yaml @@ -0,0 +1,13 @@ +name: snap-with-comps +version: 1.0 +summary: Snap with components +description: A snap that defines components +base: core22 +components: + comp-with-install-hook: + type: test + hooks: + install: + plugs: [network] +plugs: + network: diff --git a/tests/main/component-hooks/task.yaml b/tests/main/component-hooks/task.yaml new file mode 100644 index 000000000000..edd8fd9937d0 --- /dev/null +++ b/tests/main/component-hooks/task.yaml @@ -0,0 +1,27 @@ +summary: Test component hooks get run + +details: | + Verifies that component hooks run on install + +systems: [ubuntu-16.04-64, ubuntu-18.04-64, ubuntu-2*, ubuntu-core-*] + +debug: | + cat /var/snap/snap-with-comps/common/install-logs + +execute: | + snap pack snap-with-comps/ + snap pack comp-with-install-hook/ + + snap install --dangerous snap-with-comps_1.0_all.snap + change_id=$(snap install --no-wait --dangerous snap-with-comps+comp-with-install-hook_1.0.comp) + snap watch "${change_id}" + + # check component install change was as expected + snap change "${change_id}" | MATCH '^Done .*Prepare component' + snap change "${change_id}" | MATCH '^Done .*Mount component' + snap change "${change_id}" | MATCH '^Done .*Make component .* available to the system' + snap change "${change_id}" | MATCH '^Done .*Run install hook of "snap-with-comps\+comp-with-install-hook" component if present' + + # the hook writes this file if it runs (and uses the network via the network + # plug) successfully + test -f /var/snap/snap-with-comps/common/install-done