summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorsternenseemann <git@lukasepple.de>2019-05-24 21:17:51 +0200
committersternenseemann <git@lukasepple.de>2019-12-17 14:17:03 +0100
commit25503db8e845ccfa3db20ed1049837868d53775a (patch)
tree7d89c7ca665daa10d3a5d063a74d21d0f081e952 /nixos/tests
parent6eff44f9fb5dff0ae0dffa982c3549b7091f2b67 (diff)
downloadnixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar.gz
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar.bz2
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar.lz
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar.xz
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.tar.zst
nixpkgs-25503db8e845ccfa3db20ed1049837868d53775a.zip
nixos/spacecookie: add service module and test
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/spacecookie.nix51
2 files changed, 52 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 5407a071cad..2520b844e65 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -255,6 +255,7 @@ in
   smokeping = handleTest ./smokeping.nix {};
   snapper = handleTest ./snapper.nix {};
   solr = handleTest ./solr.nix {};
+  spacecookie = handleTest ./spacecookie.nix {};
   sonarr = handleTest ./sonarr.nix {};
   strongswan-swanctl = handleTest ./strongswan-swanctl.nix {};
   sudo = handleTest ./sudo.nix {};
diff --git a/nixos/tests/spacecookie.nix b/nixos/tests/spacecookie.nix
new file mode 100644
index 00000000000..6eff32a2e75
--- /dev/null
+++ b/nixos/tests/spacecookie.nix
@@ -0,0 +1,51 @@
+let
+  gopherRoot  = "/tmp/gopher";
+  gopherHost  = "gopherd";
+  fileContent = "Hello Gopher!";
+  fileName    = "file.txt";
+in
+  import ./make-test-python.nix ({...}: {
+    name = "spacecookie";
+    nodes = {
+      ${gopherHost} = {
+        networking.firewall.allowedTCPPorts = [ 70 ];
+        systemd.services.spacecookie = {
+          preStart = ''
+            mkdir -p ${gopherRoot}/directory
+            echo "${fileContent}" > ${gopherRoot}/${fileName}
+          '';
+        };
+
+        services.spacecookie = {
+          enable = true;
+          root = gopherRoot;
+          hostname = gopherHost;
+        };
+      };
+
+      client = {};
+    };
+
+    testScript = ''
+      start_all()
+      ${gopherHost}.wait_for_open_port(70)
+      ${gopherHost}.wait_for_unit("spacecookie.service")
+      client.wait_for_unit("network.target")
+
+      fileResponse = client.succeed("curl -s gopher://${gopherHost}//${fileName}")
+
+      # the file response should return our created file exactly
+      if not (fileResponse == "${fileContent}\n"):
+          raise Exception("Unexpected file response")
+
+      # sanity check on the directory listing: we serve a directory and a file
+      # via gopher, so the directory listing should have exactly two entries,
+      # one with gopher file type 0 (file) and one with file type 1 (directory).
+      dirResponse = client.succeed("curl -s gopher://${gopherHost}")
+      dirEntries = [l[0] for l in dirResponse.split("\n") if len(l) > 0]
+      dirEntries.sort()
+
+      if not (["0", "1"] == dirEntries):
+          raise Exception("Unexpected directory response")
+    '';
+  })