aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2018-12-11 00:51:48 +0100
committerRobert Helgesson <robert@rycee.net>2018-12-11 00:57:58 +0100
commit6d56abcec1d3f742c83d684927e8255bc676a995 (patch)
tree0efb5fa27eefe6f4422045397d746f9d8dbd52b8
parent5d63abb473d930a78661a74e26b9f997d7b3ccd6 (diff)
tests: add initial test framework
-rw-r--r--.travis.yml3
-rw-r--r--default.nix4
-rw-r--r--tests/default.nix23
-rw-r--r--tests/modules/programs/git-expected.conf23
-rw-r--r--tests/modules/programs/git-with-str-extra-config-expected.conf5
-rw-r--r--tests/modules/programs/git-with-str-extra-config.nix22
-rw-r--r--tests/modules/programs/git.nix40
-rw-r--r--tests/modules/xresources-expected.conf5
-rw-r--r--tests/modules/xresources.nix22
9 files changed, 146 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml
index a9f775579ca..80dde569d88 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,4 +8,5 @@ before_script:
- mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/$USER
script:
- nix-shell . -A install
+ - nix-shell . -A install
+ - nix-shell . -A tests.run.all
diff --git a/default.nix b/default.nix
index 9ae18232316..bedc57779b4 100644
--- a/default.nix
+++ b/default.nix
@@ -11,4 +11,8 @@ rec {
};
nixos = import ./nixos;
+
+ tests = import ./tests {
+ inherit pkgs;
+ };
}
diff --git a/tests/default.nix b/tests/default.nix
new file mode 100644
index 00000000000..a17bdadbbb5
--- /dev/null
+++ b/tests/default.nix
@@ -0,0 +1,23 @@
+{ pkgs ? import <nixpkgs> {} }:
+
+let
+
+ nmt = pkgs.fetchFromGitLab {
+ owner = "rycee";
+ repo = "nmt";
+ rev = "4d7b4bb34ed9df333b5aa54509e50881f3a59939";
+ sha256 = "1rha4n5xafxwa5gbrjwnm63z944jr27gv71krkzzmb5wapi1r36m";
+ };
+
+in
+
+import nmt {
+ inherit pkgs;
+ modules = import ../modules/modules.nix { inherit pkgs; lib = pkgs.lib; };
+ testedAttrPath = [ "home" "activationPackage" ];
+ tests = {
+ "git/with-most-options" = ./modules/programs/git.nix;
+ "git/with-str-extra-config" = ./modules/programs/git-with-str-extra-config.nix;
+ xresources = ./modules/xresources.nix;
+ };
+}
diff --git a/tests/modules/programs/git-expected.conf b/tests/modules/programs/git-expected.conf
new file mode 100644
index 00000000000..d2c48f76e91
--- /dev/null
+++ b/tests/modules/programs/git-expected.conf
@@ -0,0 +1,23 @@
+[alias]
+a1=foo
+a2=bar
+
+[commit]
+gpgSign=true
+
+[extra]
+name=value
+
+[gpg]
+program=path-to-gpg
+
+[user]
+email=user@example.org
+name=John Doe
+signingKey=00112233445566778899AABBCCDDEEFF
+
+[include]
+path = ~/path/to/config.inc
+
+[includeIf "gitdir:~/src/dir"]
+path = ~/path/to/conditional.inc
diff --git a/tests/modules/programs/git-with-str-extra-config-expected.conf b/tests/modules/programs/git-with-str-extra-config-expected.conf
new file mode 100644
index 00000000000..957438de13a
--- /dev/null
+++ b/tests/modules/programs/git-with-str-extra-config-expected.conf
@@ -0,0 +1,5 @@
+This can be anything.
+
+[user]
+email=user@example.org
+name=John Doe
diff --git a/tests/modules/programs/git-with-str-extra-config.nix b/tests/modules/programs/git-with-str-extra-config.nix
new file mode 100644
index 00000000000..734c5ee764c
--- /dev/null
+++ b/tests/modules/programs/git-with-str-extra-config.nix
@@ -0,0 +1,22 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+ config = {
+ programs.git = {
+ enable = true;
+ extraConfig = ''
+ This can be anything.
+ '';
+ userEmail = "user@example.org";
+ userName = "John Doe";
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.config/git/config
+ assertFileContent home-files/.config/git/config \
+ ${./git-with-str-extra-config-expected.conf}
+ '';
+ };
+}
diff --git a/tests/modules/programs/git.nix b/tests/modules/programs/git.nix
new file mode 100644
index 00000000000..29f3d17ebd5
--- /dev/null
+++ b/tests/modules/programs/git.nix
@@ -0,0 +1,40 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+ config = {
+ programs.git = {
+ enable = true;
+ aliases = {
+ a1 = "foo";
+ a2 = "bar";
+ };
+ extraConfig = {
+ extra = {
+ name = "value";
+ };
+ };
+ ignores = [ "*~" "*.swp" ];
+ includes = [
+ { path = "~/path/to/config.inc"; }
+ {
+ path = "~/path/to/conditional.inc";
+ condition = "gitdir:~/src/dir";
+ }
+ ];
+ signing = {
+ gpgPath = "path-to-gpg";
+ key = "00112233445566778899AABBCCDDEEFF";
+ signByDefault = true;
+ };
+ userEmail = "user@example.org";
+ userName = "John Doe";
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.config/git/config
+ assertFileContent home-files/.config/git/config ${./git-expected.conf}
+ '';
+ };
+}
diff --git a/tests/modules/xresources-expected.conf b/tests/modules/xresources-expected.conf
new file mode 100644
index 00000000000..20b47e5080b
--- /dev/null
+++ b/tests/modules/xresources-expected.conf
@@ -0,0 +1,5 @@
+Test*boolean1: true
+Test*boolean2: false
+Test*int: 10
+Test*list: list-str, true, false, 10
+Test*string: test-string
diff --git a/tests/modules/xresources.nix b/tests/modules/xresources.nix
new file mode 100644
index 00000000000..f73e326f31e
--- /dev/null
+++ b/tests/modules/xresources.nix
@@ -0,0 +1,22 @@
+{ config, lib, ... }:
+
+with lib;
+
+{
+ config = {
+ xresources = {
+ properties = {
+ "Test*string" = "test-string";
+ "Test*boolean1" = true;
+ "Test*boolean2" = false;
+ "Test*int" = 10;
+ "Test*list" = [ "list-str" true false 10 ];
+ };
+ };
+
+ nmt.script = ''
+ assertFileExists home-files/.Xresources
+ assertFileContent home-files/.Xresources ${./xresources-expected.conf}
+ '';
+ };
+}