summaryrefslogtreecommitdiffstats
path: root/nixos/tests/installed-tests/default.nix
blob: 926722bcdeeae994bc40242e4e6a3954dcceb308 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# NixOS tests for gnome-desktop-testing-runner using software
# See https://github.com/NixOS/nixpkgs/issues/34987

{
  system ? builtins.currentSystem,
  config ? { },
  pkgs ? import ../../.. { inherit system config; },
}:

with import ../../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let

  callInstalledTest = pkgs.newScope { inherit makeInstalledTest; };

  makeInstalledTest =
    {
      # Package to test. Needs to have an installedTests output
      tested,

      # Config to inject into machine
      testConfig ? { },

      # Test script snippet to inject before gnome-desktop-testing-runner begins.
      # This is useful for extra setup the environment may need before the runner begins.
      preTestScript ? "",

      # Does test need X11?
      withX11 ? false,

      # Extra flags to pass to gnome-desktop-testing-runner.
      testRunnerFlags ? [ ],

      # Extra attributes to pass to makeTest.
      # They will be recursively merged into the attrset created by this function.
      ...
    }@args:
    makeTest (
      recursiveUpdate
        {
          name = tested.name;

          meta = {
            maintainers = tested.meta.maintainers or [ ];
          };

          nodes.machine =
            { ... }:
            {
              imports = [
                testConfig
              ]
              ++ optional withX11 ../common/x11.nix;

              environment.systemPackages = with pkgs; [ gnome-desktop-testing ];

              # The installed tests need to be added to the test VM’s closure.
              # Otherwise, their dependencies might not actually be registered
              # as valid paths in the VM’s Nix store database,
              # and `nix-store --query` commands run as part of the tests
              # (for example when building Flatpak runtimes) will fail.
              environment.variables.TESTED_PACKAGE_INSTALLED_TESTS = "${tested.installedTests}/share";
            };

          testScript =
            optionalString withX11 ''
              machine.wait_for_x()
            ''
            + optionalString (preTestScript != "") ''
              ${preTestScript}
            ''
            + ''
              machine.succeed(
                  "gnome-desktop-testing-runner ${escapeShellArgs testRunnerFlags} -d '${tested.installedTests}/share'"
              )
            '';
        }

        (
          removeAttrs args [
            "tested"
            "testConfig"
            "preTestScript"
            "withX11"
            "testRunnerFlags"
          ]
        )
    );

in

{
  appstream = callInstalledTest ./appstream.nix { };
  appstream-qt = callInstalledTest ./appstream-qt.nix { };
  colord = callInstalledTest ./colord.nix { };
  flatpak = callInstalledTest ./flatpak.nix { };
  flatpak-builder = callInstalledTest ./flatpak-builder.nix { };
  fwupd = callInstalledTest ./fwupd.nix { };
  gcab = callInstalledTest ./gcab.nix { };
  gdk-pixbuf = callInstalledTest ./gdk-pixbuf.nix { };
  geocode-glib = callInstalledTest ./geocode-glib.nix { };
  gjs = callInstalledTest ./gjs.nix { };
  glib-networking = callInstalledTest ./glib-networking.nix { };
  graphene = callInstalledTest ./graphene.nix { };
  gsconnect = callInstalledTest ./gsconnect.nix { };
  json-glib = callInstalledTest ./json-glib.nix { };
  ibus = callInstalledTest ./ibus.nix { };
  glib-testing = callInstalledTest ./glib-testing.nix { };
  libjcat = callInstalledTest ./libjcat.nix { };
  libxmlb = callInstalledTest ./libxmlb.nix { };
  malcontent = callInstalledTest ./malcontent.nix { };
  ostree = callInstalledTest ./ostree.nix { };
  pipewire = callInstalledTest ./pipewire.nix { };
  upower = callInstalledTest ./upower.nix { };
  xdg-desktop-portal = callInstalledTest ./xdg-desktop-portal.nix { };
}