about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorTuomas Tynkkynen <tuomas@tuxera.com>2018-02-03 02:50:21 +0200
committerTuomas Tynkkynen <tuomas@tuxera.com>2018-02-03 02:50:21 +0200
commit10c8e6d0c590d6c83aa2efee7f701983440cca78 (patch)
treeb79325512b90438381604e1487ce0c1b63771f2f /nixos/tests
parent2fb4606f38deefa76da5d853645739f2faa315de (diff)
parentc70c9649eaca0409b7104a02193cd81ee8e5103a (diff)
downloadnixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar.gz
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar.bz2
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar.lz
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar.xz
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.tar.zst
nixlib-10c8e6d0c590d6c83aa2efee7f701983440cca78.zip
Merge remote-tracking branch 'upstream/master' into staging
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/home-assistant.nix41
-rw-r--r--nixos/tests/make-test.nix2
-rw-r--r--nixos/tests/networking.nix43
3 files changed, 85 insertions, 1 deletions
diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix
new file mode 100644
index 000000000000..0e2fee8e808d
--- /dev/null
+++ b/nixos/tests/home-assistant.nix
@@ -0,0 +1,41 @@
+import ./make-test.nix ({ pkgs, ... }:
+
+let
+  configDir = "/var/lib/foobar";
+
+in {
+  name = "home-assistant";
+
+  nodes = {
+    hass =
+      { config, pkgs, ... }:
+      {
+        services.home-assistant = {
+          inherit configDir;
+          enable = true;
+          config = {
+            homeassistant = {
+              name = "Home";
+              time_zone = "UTC";
+            };
+            frontend = { };
+            http = { };
+          };
+        };
+      };
+    };
+
+  testScript = ''
+    startAll;
+    $hass->waitForUnit("home-assistant.service");
+    
+    # Since config is specified using a Nix attribute set,
+    # configuration.yaml is a link to the Nix store
+    $hass->succeed("test -L ${configDir}/configuration.yaml");
+
+    # Check that Home Assistant's web interface and API can be reached
+    $hass->waitForOpenPort(8123);
+    $hass->succeed("curl --fail http://localhost:8123/states");
+    $hass->succeed("curl --fail http://localhost:8123/api/ | grep 'API running'");
+  '';
+})
diff --git a/nixos/tests/make-test.nix b/nixos/tests/make-test.nix
index f3e26aa7e74d..ee4ba310ad50 100644
--- a/nixos/tests/make-test.nix
+++ b/nixos/tests/make-test.nix
@@ -2,4 +2,4 @@ f: { system ? builtins.currentSystem, ... } @ args:
 
 with import ../lib/testing.nix { inherit system; };
 
-makeTest (if builtins.isFunction f then f (args // { inherit pkgs; inherit (pkgs) lib; }) else f)
+makeTest (if pkgs.lib.isFunction f then f (args // { inherit pkgs; inherit (pkgs) lib; }) else f)
diff --git a/nixos/tests/networking.nix b/nixos/tests/networking.nix
index 7708775f73f3..182328b32962 100644
--- a/nixos/tests/networking.nix
+++ b/nixos/tests/networking.nix
@@ -433,6 +433,49 @@ let
           $client2->succeed("ip addr show dev vlan >&2");
         '';
     };
+    virtual = {
+      name = "Virtual";
+      machine = {
+        networking.interfaces."tap0" = {
+          ip4 = [ { address = "192.168.1.1"; prefixLength = 24; } ];
+          ip6 = [ { address = "2001:1470:fffd:2096::"; prefixLength = 64; } ];
+          virtual = true;
+        };
+        networking.interfaces."tun0" = {
+          ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
+          ip6 = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
+          virtual = true;
+        };
+      };
+
+      testScript = ''
+        my $targetList = <<'END';
+        tap0: tap UNKNOWN_FLAGS:800 user 0
+        tun0: tun UNKNOWN_FLAGS:800 user 0
+        END
+
+        # Wait for networking to come up
+        $machine->start;
+        $machine->waitForUnit("network.target");
+
+        # Test interfaces set up
+        my $list = $machine->succeed("ip tuntap list | sort");
+        "$list" eq "$targetList" or die(
+          "The list of virtual interfaces does not match the expected one:\n",
+          "Result:\n", "$list\n",
+          "Expected:\n", "$targetList\n"
+        );
+
+        # Test interfaces clean up
+        $machine->succeed("systemctl stop network-addresses-tap0");
+        $machine->succeed("systemctl stop network-addresses-tun0");
+        my $residue = $machine->succeed("ip tuntap list");
+        $residue eq "" or die(
+          "Some virtual interface has not been properly cleaned:\n",
+          "$residue\n"
+        );
+      '';
+    };
   };
 
 in mapAttrs (const (attrs: makeTest (attrs // {