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 (76 lines) | stat: -rw-r--r-- 4,155 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
summary: Verify that the theme REST API endpoints function correctly

details: |
    Snapd contains dedicated API for installation of snaps providing graphical
    themes. Themes are installed and configured by the user on the host system,
    but cannot necessarily be shared with installed snaps due to API and ABI
    compatibility issues. The theme API, which is governed by a snap interface
    and is available from sufficiently privileged snaps, allows checking if a
    given theme is installed, available for installation or not available at
    all. The same API allows requesting installation of additional themes.

    The test exercises this API from a helper snap, showing that the permission
    check governed by the interface works, and that once connected, the API can
    be used to manage themes as described above.

environment:
    # not all terminals support UTF-8, but Python tries to be smart and attempts
    # to guess the encoding as if the output would go to the terminal, but in
    # fact all the test does is pipe the output to gojq
    PYTHONIOENCODING: utf-8

execute: |
    "$TESTSTOOLS"/snaps-state install-local api-client
    echo "The snapd*-control plugs on the api-client snap are initially disconnected"
    snap connections api-client | MATCH "snapd-control +api-client:snapd-control +- +-"
    snap connections api-client | MATCH "snap-themes-control +api-client:snap-themes-control +- +-"
    echo "Connect the snapd-control plug"
    snap connect api-client:snapd-control

    echo "Install the gtk-common-themes snap"
    snap install gtk-common-themes

    echo "Check for presence of a collection of themes"
    api-client '/v2/accessories/themes?gtk-theme=Yaru&gtk-theme=TraditionalHumanized&icon-theme=Yaru&icon-theme=Adwaita&sound-theme=Yaru&sound-theme=No-Such-Theme' > response.txt
    gojq . < response.txt

    gojq -r '.result."gtk-themes".Yaru' < response.txt | MATCH '^installed'
    gojq -r '.result."gtk-themes".TraditionalHumanized' < response.txt | MATCH '^available'
    gojq -r '.result."icon-themes".Yaru' < response.txt | MATCH '^installed'
    gojq -r '.result."icon-themes".Adwaita' < response.txt | MATCH '^installed'
    gojq -r '.result."sound-themes".Yaru' < response.txt | MATCH '^installed'
    gojq -r '.result."sound-themes"."No-Such-Theme"' < response.txt | MATCH '^unavailable'

    echo "We can request installation of a snap to satisfy a theme"
    api-client --method=POST /v2/accessories/themes '{"gtk-themes":["TraditionalHumanized"]}' > response.txt
    gojq . < response.txt

    echo "Wait for change to complete"
    change_id="$(gojq -r .change < response.txt)"
    snap watch "$change_id"

    echo "The snap providing the theme is now installed"
    snap list | grep gtk-theme-traditionalhumanized

    echo "The theme now reports as installed"
    api-client '/v2/accessories/themes?gtk-theme=TraditionalHumanized' > response.txt
    gojq -r '.result."gtk-themes".TraditionalHumanized' < response.txt | MATCH '^installed'

    echo "The API is also available to snaps via snapd-snap.socket, provided they have snap-themes-control plugged"
    snap disconnect api-client:snapd-control

    not api-client --socket /run/snapd-snap.socket '/v2/accessories/themes?gtk-theme=Yaru' > response.txt
    gojq -r '."status-code"' < response.txt | MATCH '^403$'

    snap connect api-client:snap-themes-control
    api-client --socket /run/snapd-snap.socket '/v2/accessories/themes?gtk-theme=Yaru' > response.txt
    gojq -r '.result."gtk-themes".Yaru' < response.txt | MATCH '^installed'

    echo "POST requests are also accepted on snapd-snap.socket"
    not api-client --socket /run/snapd-snap.socket --method=POST /v2/accessories/themes '{"gtk-themes":["TraditionalHumanized"]}' > response.txt
    gojq -r '.result.message' < response.txt | MATCH '^no snaps to install'

    echo "Information about install-themes changes can also be accessed"
    api-client --socket /run/snapd-snap.socket "/v2/accessories/changes/$change_id" > response.txt
    gojq -r .result.status < response.txt | MATCH '^Done$'
    gojq -r .result.kind < response.txt | MATCH '^install-themes$'