File: task.yaml

package info (click to toggle)
snapd 2.71-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,536 kB
  • sloc: ansic: 16,114; sh: 16,105; python: 9,941; makefile: 1,890; exp: 190; awk: 40; xml: 22
file content (54 lines) | stat: -rw-r--r-- 2,164 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
summary: Check that command-chain is properly supported

details: |
    Verify the command-chain feature works as expected for hooks, apps, and
    services. Rather than running the hook, app, or service directly, the
    command-chain should be prefixed to the target command. Additionally verify
    that the command-chain is executed when running a snap with `snap run
    --shell`.

environment:
    # Ensure that running purely from the deb (without re-exec) works
    # correctly
    SNAP_REEXEC/reexec0: 0
    SNAP_REEXEC/reexec1: 1
    BREADCRUMB: /var/snap/command-chain/current/breadcrumb
    ENVDUMP: /var/snap/command-chain/current/env

prepare: |
    if [ "$SNAP_REEXEC" = "0" ] && tests.info is-snapd-from-archive; then
        tests.exec skip-test "No need to test when the snapd pkg is from the repository and reexec is disabled" && exit 0
    fi

    echo "Build command chain snap"
    snap pack command-chain
    snap install --dangerous command-chain_1.0_all.snap
    SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
    if [ "$SNAP_REEXEC" = "1" ] && [ "$SNAP_MOUNT_DIR" != "/snap" ] && [ ! -L /snap ]; then
        # reexec expects to find the snapd snap under /snap, enable it to do so
        # on distros using /var/lib/snapd/snap
        ln -sf "$SNAP_MOUNT_DIR" /snap
        tests.cleanup defer rm -f /snap
    fi

execute: |
    tests.exec is-skipped && exit 0

    echo "Test that command-chain runs for hooks"
    [ "$(cat "$BREADCRUMB")" = "chain1 chain2 configure" ]
    MATCH '^CHAIN_1_RAN=1$' < "$ENVDUMP"
    MATCH '^CHAIN_2_RAN=1$' < "$ENVDUMP"

    echo "Test that command-chain runs for apps"
    [ "$(command-chain.hello)" = "chain1 chain2 hello" ]

    echo "Test that command-chain runs for services"
    # let the logs catch up
    sleep 1
    snap logs command-chain | MATCH 'chain3 chain4 running: 0 0 1 1$'

    echo "Ensure that the command-chain is run with 'snap run --shell' as well"
    [ "$(snap run --shell command-chain.hello -c 'echo "shell"')" = "chain1 chain2 shell" ]
    env="$(snap run --shell command-chain.hello -c 'env')"
    echo "$env" | MATCH '^CHAIN_1_RAN=1$'
    echo "$env" | MATCH '^CHAIN_2_RAN=1$'