Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
826de13
meta module: add tests
ericsagnes Sep 1, 2016
cc9398d
release.nix: add callTest' function
ericsagnes Sep 1, 2016
3d5b554
avahi test: move to module
ericsagnes Sep 1, 2016
03425d4
cadvisor test: move to module
ericsagnes Sep 1, 2016
f233a8b
cjdns test: move to module
ericsagnes Sep 1, 2016
3be0d7c
containers tests: move to module
ericsagnes Sep 1, 2016
5666941
gocd-agent test: move to module
ericsagnes Sep 1, 2016
67699e0
gocd-server test: move to module
ericsagnes Sep 1, 2016
ce4e31e
gnome3 test: move to module
ericsagnes Sep 1, 2016
7780ce3
grsecurity: move test to module
ericsagnes Sep 1, 2016
38d49bf
i3wm: move test to module
ericsagnes Sep 1, 2016
7104800
influxdb test: move to module
ericsagnes Sep 2, 2016
287eea1
jenkins test: move to module
ericsagnes Sep 2, 2016
e2cc198
kde4 test: move to module
ericsagnes Sep 2, 2016
7d7bffe
kubernetes test: move to module
ericsagnes Sep 2, 2016
dd8929d
mathics test: move to module
ericsagnes Sep 2, 2016
9c41ea4
munin test: move to module
ericsagnes Sep 2, 2016
0a12c9d
mysql tests: move to module
ericsagnes Sep 2, 2016
91d38a5
openssh test: move to module
ericsagnes Sep 2, 2016
4640164
peerflix test: move to module
ericsagnes Sep 2, 2016
eb837ff
postgresql test: move to module
ericsagnes Sep 2, 2016
dac531e
pump.io test: move to module
ericsagnes Sep 2, 2016
0ecc0f9
sddm test: move to module
ericsagnes Sep 2, 2016
67f5b2a
kde5 test: move to module
ericsagnes Sep 2, 2016
21beb7e
smokeping test: move to module
ericsagnes Sep 2, 2016
e6afde7
taskserver test: move to module
ericsagnes Sep 2, 2016
8f21ce0
tomcat test: move to module
ericsagnes Sep 2, 2016
9d3901c
udisks2 test: move to module
ericsagnes Sep 2, 2016
54e3acc
xfce test: move to module
ericsagnes Sep 2, 2016
ed99e49
docker test: move to module
ericsagnes Sep 2, 2016
9ad66fe
etcd test: move to module
ericsagnes Sep 2, 2016
6828a32
fleet test: move to module
ericsagnes Sep 2, 2016
68440fb
panamax test: move to module
ericsagnes Sep 2, 2016
6a47c39
ferm test: move to module
ericsagnes Sep 4, 2016
5b9528e
quagga test: move to module
ericsagnes Sep 4, 2016
712bb01
postgis test: move to module
ericsagnes Sep 4, 2016
eef17af
release.nix tests: use callTest'
ericsagnes Sep 2, 2016
fe4b551
release-combined.nix: update module tests attribute path
ericsagnes Sep 3, 2016
14cb1b5
nixos/tests/*: adapt to callTest'
ericsagnes Sep 3, 2016
b41cc96
virtualbox test: move to module
ericsagnes Sep 4, 2016
4e97e48
cassandra test: move to module
ericsagnes Sep 4, 2016
1c5e32b
emacs-daemon test: move to module
ericsagnes Sep 4, 2016
008a08e
gitlab test: move to module
ericsagnes Sep 4, 2016
4c1a3e5
haka test: move to module
ericsagnes Sep 4, 2016
79cc80e
lightdm test: move to module
ericsagnes Sep 4, 2016
9ce477e
logstash test: move to module
ericsagnes Sep 4, 2016
cb2bbd8
mesos test: move to module
ericsagnes Sep 4, 2016
f3574ef
rabbitmq test: move to module
ericsagnes Sep 4, 2016
eb9f8e4
riak test: move to module
ericsagnes Sep 4, 2016
c10764e
slurm test: move to module
ericsagnes Sep 4, 2016
81b9043
make-test.nix: remove file
ericsagnes Sep 3, 2016
88a73b2
callTest: move to lib
ericsagnes Sep 2, 2016
149531e
callTest: allow tests to be run interactively
ericsagnes Sep 3, 2016
d744e18
nix-run-test: init
ericsagnes Sep 3, 2016
b4e036b
running test manual: update with nix-run-test
ericsagnes Sep 3, 2016
fb3a567
release.nix: add a way to blacklist module tests
ericsagnes Sep 3, 2016
a812b6f
release.nix: blacklist some module tests
ericsagnes Sep 4, 2016
e524277
mongodb test: move to module
ericsagnes Sep 23, 2016
bbd357b
samba test: move to module
ericsagnes Oct 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let
# domain-specific
sandbox = import ./sandbox.nix;
fetchers = import ./fetchers.nix;
testing = import ./testing {};

in
{ inherit trivial
Expand All @@ -40,7 +41,7 @@ in
modules options types
licenses platforms systems
debug misc
sandbox fetchers;
sandbox fetchers testing;
}
# !!! don't include everything at top-level; perhaps only the most
# commonly used functions.
Expand Down
75 changes: 75 additions & 0 deletions lib/testing/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{ supportedSystems ? [ builtins.currentSystem ] }:

with {
inherit (builtins) getAttr;
inherit (import ../attrsets.nix) mapAttrs genAttrs isDerivation;
inherit (import ../customisation.nix) hydraJob;
inherit (import ../trivial.nix) id;
};

rec {

/* Call a test file

The called test file should contain a function that returns:
- a single test set
- a set of tests sets
- a test derivation, eg runInMachine

Examples:

a. Call a test:
callTest ./nixos/tests/simple.nix {};

b. Call a test for only x86_64-linux:
callTest ./nixos/tests/simple.nix { systems = [ "x86_64-linux" ]; };

c. Call a test with custom parameters:
callTest ./nixos/tests/nfs.nix { version = 3; };

d. Call a test from the command line with nix-build:
$ nix-build -E 'with import <nixpkgs/lib/testing> {}; callTest ./nixos/tests/simple.nix {}'

*/

callTest = file: { systems ? supportedSystems, interactive ? false, ... } @ args:
let
# raw test function
testFn = import file;
# pkgs needed to dummy evaluate the test, not used in the final test
pkgs = import ../.. { system = "x86_64-linux"; };
# basic arguments
testArgs = rec { inherit pkgs; inherit (pkgs) lib; } // args;
# test applied with basic arguments
dummyTest = testFn testArgs;
# check if the test is a derivation like in runInMachine
drvTest = isDerivation dummyTest;
# to check if it is a single test or multiple tests
singleTest = dummyTest ? "testScript";
# generate the tests with makeTest function
mkTest = { system ? builtins.currentSystem, ... } @ args:
let testLib = import ./testing.nix { inherit system; };
# pkgs coming from testing.nix for the system tested
pkgsSet = { inherit testLib pkgs; };
test = testFn (args // pkgsSet);
in if drvTest then test
else if singleTest
then testLib.makeTest test
else mapAttrs (k: v: testLib.makeTest v) test;
# function to prepare the test
prepTestFn = if interactive
then (getAttr "driver")
else hydraJob;
# check unsupported cases
runCheck = f: if (drvTest && interactive)
then builtins.abort "Derivation tests cannot be run interactively"
else f;
# generate test jobs for systems
testForSys = f: genAttrs systems (system: prepTestFn( f( mkTest({ inherit system; } // testArgs)) ) );
# fully prepared test
test = if (drvTest || singleTest)
then testForSys id
else mapAttrs (k: _: testForSys (getAttr k)) dummyTest;
in runCheck test;

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nixos/lib/testing.nix → lib/testing/testing.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ system, minimal ? false, config ? {} }:

with import ./build-vms.nix { inherit system minimal config; };
with import ../../nixos/lib/build-vms.nix { inherit system minimal config; };
with pkgs;

rec {
Expand Down
21 changes: 19 additions & 2 deletions nixos/doc/manual/development/meta-attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<para><literal>meta</literal> is a top level attribute like
<literal>options</literal> and <literal>config</literal>. Available
meta-attributes are <literal>maintainers</literal> and
<literal>doc</literal>.</para>
meta-attributes are <literal>maintainers</literal>,
<literal>doc</literal> and <literal>tests</literal>.</para>

<para>Each of the meta-attributes must be defined at most once per module
file.</para>
Expand All @@ -35,6 +35,10 @@
maintainers = with lib.maintainers; [ ericsagnes ]; <co
xml:id='modules-meta-1' />
doc = ./default.xml; <co xml:id='modules-meta-2' />
tests = { <co xml:id='modules-meta-3' />
containers-ipv4 = ./tests/containers-ipv4.nix;
containers-ipv6 = ./tests/containers-ipv6.nix;
};
};
}
</programlisting>
Expand All @@ -57,6 +61,19 @@
<programlisting>$ nix-build nixos/release.nix -A manual</programlisting>
</callout>

<callout arearefs='modules-meta-3'>
<para>
<varname>tests</varname> is a set of which keys are test names and values
point to a test file. All the tests declared via this attribute are
automatically included in
<filename xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/release.nix">release.nix</filename>'s
<literal>tests.module</literal> set.
It is important to check that newly added and modified test are not
breaking by running them:
</para>
<programlisting>$ nix-build nixos/release.nix -A tests.module.TEST_NAME</programlisting>
</callout>

</calloutlist>

</section>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
particularly useful when developing or debugging a test:

<screen>
$ nix-build nixos/tests/login.nix -A driver
$ nix-run-test --interactive nixos/tests/login.nix
$ ./result/bin/nixos-test-driver
starting VDE switch for network 1
&gt;
Expand All @@ -31,7 +31,7 @@ test (e.g. to debug the test script).</para>
<para>To just start and experiment with the VMs, run:

<screen>
$ nix-build nixos/tests/login.nix -A driver
$ nix-run-test --interactive nixos/tests/login.nix
$ ./result/bin/nixos-run-vms
</screen>

Expand Down
9 changes: 5 additions & 4 deletions nixos/doc/manual/development/running-nixos-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

<title>Running Tests</title>

<para>You can run tests using <command>nix-build</command>. For
example, to run the test <filename
<para>You can run tests using <command>nix-run-test</command>.
<command>nix-run-test</command> is available in nixpkgs.
For example, to run the test <filename
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/login.nix">login.nix</filename>,
you just do:

<screen>
$ nix-build '&lt;nixpkgs/nixos/tests/login.nix>'
$ nix-run-test '&lt;nixpkgs/nixos/tests/login.nix>'
</screen>

or, if you don’t want to rely on <envar>NIX_PATH</envar>:

<screen>
$ cd /my/nixpkgs/nixos/tests
$ nix-build login.nix
$ nix-run-test login.nix
running the VM test script
machine: QEMU running (pid 8841)
Expand Down
5 changes: 3 additions & 2 deletions nixos/doc/manual/development/writing-nixos-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<para>A NixOS test is a Nix expression that has the following structure:

<programlisting>
import ./make-test.nix {
{ pkgs, ... }:
{

# Either the configuration of a single machine:
machine =
Expand Down Expand Up @@ -266,4 +267,4 @@ startAll;

</para>

</section>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

let nodes = import networkExpr; in

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

(makeTest { inherit nodes; testScript = ""; }).driver
16 changes: 13 additions & 3 deletions nixos/modules/misc/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ let
[{ inherit (def) file; value = def'; }]) def.value) defs));
};

docFile = types.path // {
file = types.path // {
# Returns tuples of
# { file = "module location"; value = <path/to/doc.xml>; }
# { file = "module location"; value = <path/to/file.ext>; }
merge = loc: defs: defs;
};
in
Expand All @@ -45,7 +45,7 @@ in
};

doc = mkOption {
type = docFile;
type = file;
internal = true;
example = "./meta.xml";
description = ''
Expand All @@ -54,6 +54,16 @@ in
'';
};

tests = mkOption {
type = with types; attrsOf file;
internal = true;
example = literalExample "./test.nix";
description = ''
Tests for the module. Tests get added to the tests attribute of release.nix with the test name prepended by "module-".
This option should be defined at most once per module.
'';
};

};
};

Expand Down
3 changes: 3 additions & 0 deletions nixos/modules/security/grsecurity.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ in
meta = {
maintainers = with maintainers; [ joachifm ];
doc = ./grsecurity.xml;
tests = {
grsecurity = ./tests/grsecurity.nix;
};
};

options.security.grsecurity = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Basic test to make sure grsecurity works

import ./make-test.nix ({ pkgs, ...} : {
{ pkgs, ...} : {
name = "grsecurity";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ copumpkin joachifm ];
Expand Down Expand Up @@ -43,4 +43,4 @@ import ./make-test.nix ({ pkgs, ...} : {
$machine->succeed("[ -c /dev/grsec ]");
};
'';
})
}
4 changes: 4 additions & 0 deletions nixos/modules/services/amqp/rabbitmq.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ in {

};

meta.tests = {
rabbitmq = ./tests/rabbitmq.nix;
};

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This test runs rabbitmq and checks if rabbitmq is up and running.

import ./make-test.nix ({ pkgs, ... }: {
{ pkgs, ... }: {
name = "rabbitmq";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ eelco chaoflow offline ];
Expand All @@ -18,4 +18,4 @@ import ./make-test.nix ({ pkgs, ... }: {
$one->waitForUnit("rabbitmq.service");
$one->waitUntilSucceeds("su -s ${pkgs.stdenv.shell} rabbitmq -c \"rabbitmqctl status\"");
'';
})
}
4 changes: 4 additions & 0 deletions nixos/modules/services/cluster/fleet.nix
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ in {
environment.systemPackages = [ pkgs.fleet ];
users.extraGroups.fleet.gid = config.ids.gids.fleet;
};

meta.tests = {
fleet = ./tests/fleet.nix;
};
}
4 changes: 4 additions & 0 deletions nixos/modules/services/cluster/kubernetes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,8 @@ in {
})

];

meta.tests = {
kubernetes = ./tests/kubernetes.nix;
};
}
4 changes: 4 additions & 0 deletions nixos/modules/services/cluster/panamax.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,8 @@ in {
environment.systemPackages = [ panamax_api panamax_ui ];
users.extraGroups.panamax.gid = config.ids.gids.panamax;
};

meta.tests = {
panamax = ./tests/panamax.nix;
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : rec {
{ pkgs, ...} : rec {
name = "simple";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ offline ];
Expand Down Expand Up @@ -73,4 +73,4 @@ import ./make-test.nix ({ pkgs, ...} : rec {
$node1->succeed("fleetctl stop hello.service");
$node1->succeed("fleetctl destroy hello.service");
'';
})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This test runs two node kubernetes cluster and checks if simple redis pod works

import ./make-test.nix ({ pkgs, ...} : rec {
{ pkgs, ...} : rec {
name = "kubernetes";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ offline ];
Expand Down Expand Up @@ -179,4 +179,4 @@ import ./make-test.nix ({ pkgs, ...} : rec {
}

'';
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : {
{ pkgs, ...} : {
name = "panamax";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ offline ];
Expand All @@ -18,4 +18,4 @@ import ./make-test.nix ({ pkgs, ...} : {
$machine->succeed("curl --fail http://localhost:8888/ > /dev/null");
$machine->shutdown;
'';
})
}
4 changes: 4 additions & 0 deletions nixos/modules/services/computing/slurm/slurm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ in

};

meta.tests = {
slurm = ./test.nix;
};

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }:
{ pkgs, ... }:
let mungekey = "mungeverryweakkeybuteasytointegratoinatest";
slurmconfig = {
client.enable = true;
Expand Down Expand Up @@ -77,4 +77,4 @@ in {
$control->succeed("srun -N 3 hostname | sort | uniq | wc -l | xargs test 3 -eq");
};
'';
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,8 @@ in {
};
};
};

meta.tests = {
gocd-agent = ./test.nix;
};
}
Loading