2014-08-24 19:18:18 +02:00
|
|
|
<section xmlns="http://docbook.org/ns/docbook"
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
version="5.0"
|
|
|
|
xml:id="sec-writing-nixos-tests">
|
2018-05-02 01:57:09 +02:00
|
|
|
<title>Writing Tests</title>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
2018-05-02 01:57:09 +02:00
|
|
|
<para>
|
|
|
|
A NixOS test is a Nix expression that has the following structure:
|
2014-08-24 19:18:18 +02:00
|
|
|
<programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
import ./make-test-python.nix {
|
2014-08-24 19:18:18 +02:00
|
|
|
|
|
|
|
# Either the configuration of a single machine:
|
|
|
|
machine =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ <replaceable>configuration…</replaceable>
|
|
|
|
};
|
|
|
|
|
|
|
|
# Or a set of machines:
|
|
|
|
nodes =
|
|
|
|
{ <replaceable>machine1</replaceable> =
|
|
|
|
{ config, pkgs, ... }: { <replaceable>…</replaceable> };
|
|
|
|
<replaceable>machine2</replaceable> =
|
|
|
|
{ config, pkgs, ... }: { <replaceable>…</replaceable> };
|
|
|
|
…
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
2019-11-04 23:50:50 +01:00
|
|
|
<replaceable>Python code…</replaceable>
|
2014-08-24 19:18:18 +02:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
</programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
The attribute <literal>testScript</literal> is a bit of Python code that
|
2019-09-19 19:17:30 +02:00
|
|
|
executes the test (described below). During the test, it will start one or
|
|
|
|
more virtual machines, the configuration of which is described by the
|
|
|
|
attribute <literal>machine</literal> (if you need only one machine in your
|
|
|
|
test) or by the attribute <literal>nodes</literal> (if you need multiple
|
|
|
|
machines). For instance,
|
|
|
|
<filename
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix">login.nix</filename>
|
|
|
|
only needs a single machine to test whether users can log in on the virtual
|
|
|
|
console, whether device ownership is correctly maintained when switching
|
|
|
|
between consoles, and so on. On the other hand,
|
|
|
|
<filename
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nfs.nix">nfs.nix</filename>,
|
|
|
|
which tests NFS client and server functionality in the Linux kernel
|
|
|
|
(including whether locks are maintained across server crashes), requires
|
|
|
|
three machines: a server and two clients.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
2014-08-24 19:18:18 +02:00
|
|
|
|
2018-05-02 01:57:09 +02:00
|
|
|
<para>
|
|
|
|
There are a few special NixOS configuration options for test VMs:
|
2014-08-24 19:18:18 +02:00
|
|
|
<!-- FIXME: would be nice to generate this automatically. -->
|
2018-05-02 01:57:09 +02:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<option>virtualisation.memorySize</option>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The memory of the VM in megabytes.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<option>virtualisation.vlans</option>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
The virtual networks to which the VM is connected. See
|
|
|
|
<filename
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nat.nix">nat.nix</filename>
|
|
|
|
for an example.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<option>virtualisation.writableStore</option>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
By default, the Nix store in the VM is not writable. If you enable this
|
|
|
|
option, a writable union file system is mounted on top of the Nix store
|
|
|
|
to make it appear writable. This is necessary for tests that run Nix
|
|
|
|
operations that modify the store.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2019-09-19 19:17:30 +02:00
|
|
|
For more options, see the module
|
|
|
|
<filename
|
2018-05-02 01:57:09 +02:00
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/qemu-vm.nix">qemu-vm.nix</filename>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-11-04 23:50:50 +01:00
|
|
|
The test script is a sequence of Python statements that perform various
|
2019-09-19 19:17:30 +02:00
|
|
|
actions, such as starting VMs, executing commands in the VMs, and so on. Each
|
|
|
|
virtual machine is represented as an object stored in the variable
|
2019-11-04 23:50:50 +01:00
|
|
|
<literal><replaceable>name</replaceable></literal> if this is also the
|
|
|
|
identifier of the machine in the declarative config.
|
|
|
|
If you didn't specify multiple machines using the <literal>nodes</literal>
|
|
|
|
attribute, it is just <literal>machine</literal>.
|
|
|
|
The following example starts the machine, waits until it has finished booting,
|
|
|
|
then executes a command and checks that the output is more-or-less correct:
|
2014-08-24 19:18:18 +02:00
|
|
|
<programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("default.target")
|
|
|
|
if not "Linux" in machine.succeed("uname"):
|
|
|
|
raise Exception("Wrong OS")
|
2014-08-24 19:18:18 +02:00
|
|
|
</programlisting>
|
2019-09-19 19:17:30 +02:00
|
|
|
The first line is actually unnecessary; machines are implicitly started when
|
2019-11-04 23:50:50 +01:00
|
|
|
you first execute an action on them (such as <literal>wait_for_unit</literal>
|
2019-09-19 19:17:30 +02:00
|
|
|
or <literal>succeed</literal>). If you have multiple machines, you can speed
|
|
|
|
up the test by starting them in parallel:
|
2014-08-24 19:18:18 +02:00
|
|
|
<programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
start_all()
|
2014-08-24 19:18:18 +02:00
|
|
|
</programlisting>
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following methods are available on machine objects:
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>start</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Start the virtual machine. This method is asynchronous — it does not
|
|
|
|
wait for the machine to finish booting.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
2017-11-23 15:06:32 +01:00
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>shutdown</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Shut down the machine, waiting for the VM to exit.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>crash</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
2018-01-04 12:57:15 +01:00
|
|
|
<listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
<para>
|
|
|
|
Simulate a sudden power failure, by telling the VM to exit immediately.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>block</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Simulate unplugging the Ethernet cable that connects the machine to the
|
|
|
|
other machines.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>unblock</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Undo the effect of <methodname>block</methodname>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>screenshot</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Take a picture of the display of the virtual machine, in PNG format. The
|
|
|
|
screenshot is linked from the HTML log.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>get_screen_text</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Return a textual representation of what is currently visible on the
|
|
|
|
machine's screen using optical character recognition.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
This requires passing <option>enableOCR</option> to the test attribute
|
|
|
|
set.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>send_monitor_command</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Send a command to the QEMU monitor. This is rarely used, but allows doing
|
|
|
|
stuff such as attaching virtual USB disks to a running machine.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>send_keys</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Simulate pressing keys on the virtual keyboard, e.g.,
|
2019-11-04 23:50:50 +01:00
|
|
|
<literal>send_keys("ctrl-alt-delete")</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>send_chars</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Simulate typing a sequence of characters on the virtual keyboard, e.g.,
|
2019-11-04 23:50:50 +01:00
|
|
|
<literal>send_keys("foobar\n")</literal> will type the string
|
2019-09-19 19:17:30 +02:00
|
|
|
<literal>foobar</literal> followed by the Enter key.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>execute</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Execute a shell command, returning a list
|
|
|
|
<literal>(<replaceable>status</replaceable>,
|
|
|
|
<replaceable>stdout</replaceable>)</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>succeed</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Execute a shell command, raising an exception if the exit status is not
|
|
|
|
zero, otherwise returning the standard output.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>fail</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Like <methodname>succeed</methodname>, but raising an exception if the
|
|
|
|
command returns a zero status.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_until_succeeds</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Repeat a shell command with 1-second intervals until it succeeds.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_until_fails</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Repeat a shell command with 1-second intervals until it fails.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_unit</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Wait until the specified systemd unit has reached the “active” state.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_file</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Wait until the specified file exists.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_open_port</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Wait until a process is listening on the given TCP port (on
|
|
|
|
<literal>localhost</literal>, at least).
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_closed_port</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Wait until nobody is listening on the given TCP port.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_x</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Wait until the X11 server is accepting connections.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_text</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Wait until the supplied regular expressions matches the textual contents
|
|
|
|
of the screen by using optical character recognition (see
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>get_screen_text</methodname>).
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
This requires passing <option>enableOCR</option> to the test attribute
|
|
|
|
set.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>wait_for_window</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Wait until an X11 window has appeared whose name matches the given
|
2019-11-04 23:50:50 +01:00
|
|
|
regular expression, e.g., <literal>wait_for_window("Terminal")</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
2019-11-04 23:50:50 +01:00
|
|
|
<methodname>copy_file_from_host</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Copies a file from host to machine, e.g.,
|
2019-11-04 23:50:50 +01:00
|
|
|
<literal>copy_file_from_host("myfile", "/etc/my/important/file")</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
The first argument is the file on the host. The file needs to be
|
|
|
|
accessible while building the nix derivation. The second argument is the
|
|
|
|
location of the file on the machine.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2018-06-01 03:03:51 +02:00
|
|
|
<term>
|
|
|
|
<methodname>systemctl</methodname>
|
2018-05-02 01:57:09 +02:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
Runs <literal>systemctl</literal> commands with optional support for
|
|
|
|
<literal>systemctl --user</literal>
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
machine.systemctl("list-jobs --no-pager") # runs `systemctl list-jobs --no-pager`
|
|
|
|
machine.systemctl("list-jobs --no-pager", "any-user") # spawns a shell for `any-user` and runs `systemctl --user list-jobs --no-pager`
|
2019-06-17 12:01:51 +02:00
|
|
|
</programlisting>
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
2018-01-04 12:57:15 +01:00
|
|
|
</listitem>
|
2018-05-02 01:57:09 +02:00
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
2018-01-04 12:57:15 +01:00
|
|
|
|
2018-05-02 01:57:09 +02:00
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
To test user units declared by <literal>systemd.user.services</literal> the
|
2019-11-04 23:50:50 +01:00
|
|
|
optional <literal>user</literal> argument can be used:
|
2018-05-02 01:57:09 +02:00
|
|
|
<programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
machine.start()
|
|
|
|
machine.wait_for_x()
|
|
|
|
machine.wait_for_unit("xautolock.service", "x-session-user")
|
2019-06-17 12:01:51 +02:00
|
|
|
</programlisting>
|
2019-11-04 23:50:50 +01:00
|
|
|
This applies to <literal>systemctl</literal>, <literal>get_unit_info</literal>,
|
|
|
|
<literal>wait_for_unit</literal>, <literal>start_job</literal> and
|
|
|
|
<literal>stop_job</literal>.
|
2018-05-02 01:57:09 +02:00
|
|
|
</para>
|
2019-12-22 14:50:08 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
For faster dev cycles it's also possible to disable the code-linters (this shouldn't
|
|
|
|
be commited though):
|
|
|
|
<programlisting>
|
|
|
|
import ./make-test-python.nix {
|
|
|
|
skipLint = true;
|
|
|
|
machine =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ <replaceable>configuration…</replaceable>
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
<replaceable>Python code…</replaceable>
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
2017-11-23 15:06:32 +01:00
|
|
|
</section>
|