File: task.yaml

package info (click to toggle)
snapd 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,412 kB
  • sloc: sh: 16,506; ansic: 16,211; python: 11,213; makefile: 1,919; exp: 190; awk: 58; xml: 22
file content (99 lines) | stat: -rw-r--r-- 4,948 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
summary: Check that snap disconnect works

details: |
    This test verifies multiple ways to invoke "snap disconnect". It
    can disconnect specific connections, or all connections to a plug,
    or a slot. Forgetting connection should be correctly saved. Both
    connections to snapd and other snaps can be disconnected.

environment:
    SNAP_FILE: "home-consumer_1.0_all.snap"

prepare: |
    echo "Install a test snap"
    snap pack "$TESTSLIB"/snaps/home-consumer
    snap install --dangerous "$SNAP_FILE"

execute: |
    inspect_connection() {
      CONN="$1"
      # shellcheck disable=SC2002,SC2016
      cat /var/lib/snapd/state.json | gojq --arg CONN "$CONN" -r '.data["conns"] | has($CONN)'
    }

    DISCONNECTED_PATTERN='-\s+home-consumer:home'

    echo "Disconnect everything from given slot"
    snap connect home-consumer:home core:home
    snap disconnect core:home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"

    echo "Disconnect everything from given slot (abbreviated)"
    snap connect home-consumer:home core:home
    snap disconnect :home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"

    echo "Disconnect everything from given slot (abbreviated) with --forget"
    snap connect home-consumer:home core:home
    snap disconnect --forget :home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"
    inspect_connection "home-consumer:home core:home" | MATCH "false"

    echo "Disconnect everything from given plug"
    snap connect home-consumer:home core:home
    snap disconnect home-consumer:home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"

    echo "Disconnect specific plug and slot"
    snap connect home-consumer:home core:home
    snap disconnect home-consumer:home core:home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"

    echo "Disconnect specific plug and slot (abbreviated)"
    snap connect home-consumer:home core:home
    snap disconnect home-consumer:home :home
    snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"

    echo "Disconnecting again using abbreviated form is handled"
    snap disconnect home-consumer:home | MATCH "No connections to disconnect"

    echo "Disconnecting without specifying the slot/plug fails"
    snap disconnect home-consumer: 2>&1 | MATCH '.*invalid value: "home-consumer:" \(want snap:name or :name\)'
    snap disconnect home-consumer 2>&1 | MATCH '.*invalid value: "home-consumer" \(want snap:name or :name\)'
    snap disconnect home-consumer:home core 2>&1 | MATCH '.*invalid value: "core" \(want snap:name or :name\)'

    # these checks rely on automatic connection of home on non-core systems
    if ! os.query is-core; then
      echo "Checking that --forget forgets connection when auto-connected"
      snap remove --purge "$SNAP_FILE"
      snap install --dangerous "$SNAP_FILE"
      snap connections home-consumer | MATCH "home-consumer:home *:home"
      snap disconnect --forget home-consumer:home :home
      snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"
      inspect_connection "home-consumer:home core:home"| MATCH "false"

      echo "Checking that --forget forgets the connection when already disconnected"
      snap remove --purge "$SNAP_FILE"
      snap install --dangerous "$SNAP_FILE"
      # home got auto-connected
      snap connections home-consumer | MATCH "home-consumer:home *:home"
      snap disconnect home-consumer:home :home
      # still remembered as automatic connection is now undesired
      inspect_connection "home-consumer:home core:home" | MATCH "true"
      snap interfaces | grep -Pzqe "$DISCONNECTED_PATTERN"
      snap disconnect --forget home-consumer:home :home
      inspect_connection "home-consumer:home core:home" | MATCH "false"
    fi

    echo "Checking that a connection for missing plug can be forgotten"
    "$TESTSTOOLS"/snaps-state install-local test-snap-producer
    "$TESTSTOOLS"/snaps-state install-local test-snap-consumer.v1
    snap connect test-snap-consumer:shared-content-plug test-snap-producer:shared-content-slot
    snap connections test-snap-consumer | MATCH "content\[mylib\] *test-snap-consumer:shared-content-plug *test-snap-producer:shared-content-slot"
    # refresh to a newer version without content plug
    "$TESTSTOOLS"/snaps-state install-local test-snap-consumer.v2
    snap connections test-snap-consumer | NOMATCH "content\[mylib\] *test-snap-consumer:shared-content-plug *test-snap-producer:shared-content-slot"
    inspect_connection "test-snap-consumer:shared-content-plug test-snap-producer:shared-content-slot" | MATCH "true"
    snap disconnect --forget test-snap-consumer:shared-content-plug test-snap-producer:shared-content-slot
    snap connections test-snap-consumer | NOMATCH "content\[mylib\] *test-snap-consumer:shared-content-plug *test-snap-producer:shared-content-slot"
    inspect_connection "test-snap-consumer:shared-content-plug test-snap-producer:shared-content-slot" | MATCH "false"