Skip to content

Commit

Permalink
tests/main/component-hooks: add test showing that component hooks can…
Browse files Browse the repository at this point in the history
… run with connected plug
  • Loading branch information
andrewphelpsj committed Apr 2, 2024
1 parent a3dc648 commit 5e4f87d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions tests/main/component-hooks/snap-with-comps/meta/snap.yaml
Original file line number Diff line number Diff line change
@@ -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:
27 changes: 27 additions & 0 deletions tests/main/component-hooks/task.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5e4f87d

Please sign in to comment.