summary refs log tree commit diff
path: root/nixos/tests/spacecookie.nix
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-12-28 00:16:26 +0100
committersterni <sternenseemann@systemli.org>2021-04-10 15:44:19 +0200
commit8abd77c8118c10702d7226379649a2e63d922d5c (patch)
tree08aeca86587b14414f18011ec5afb22bbd37cdee /nixos/tests/spacecookie.nix
parent6b577f46b4d0f612321eb5ab6e410a95f0074c4a (diff)
downloadnixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar.gz
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar.bz2
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar.lz
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar.xz
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.tar.zst
nixpkgs-8abd77c8118c10702d7226379649a2e63d922d5c.zip
nixos/tests/spacecookie: refactor
* Use proper gopher urls
* The client vms name is also controlled in a single place now
* fileContent holds the precise file content now
* wait for the spacecookie unit instead of the port
  * avoids sending an empty request
  * since spacecookie is a notify service it only is fully started when
    the socket has been set up.
Diffstat (limited to 'nixos/tests/spacecookie.nix')
-rw-r--r--nixos/tests/spacecookie.nix25
1 files changed, 14 insertions, 11 deletions
diff --git a/nixos/tests/spacecookie.nix b/nixos/tests/spacecookie.nix
index 5b5022a7427..d3411da8e92 100644
--- a/nixos/tests/spacecookie.nix
+++ b/nixos/tests/spacecookie.nix
@@ -1,8 +1,9 @@
 let
-  gopherRoot  = "/tmp/gopher";
-  gopherHost  = "gopherd";
-  fileContent = "Hello Gopher!";
-  fileName    = "file.txt";
+  gopherRoot   = "/tmp/gopher";
+  gopherHost   = "gopherd";
+  gopherClient = "client";
+  fileContent  = "Hello Gopher!\n";
+  fileName     = "file.txt";
 in
   import ./make-test-python.nix ({...}: {
     name = "spacecookie";
@@ -12,7 +13,7 @@ in
         systemd.services.spacecookie = {
           preStart = ''
             mkdir -p ${gopherRoot}/directory
-            echo "${fileContent}" > ${gopherRoot}/${fileName}
+            printf "%s" "${fileContent}" > ${gopherRoot}/${fileName}
           '';
         };
 
@@ -23,25 +24,27 @@ in
         };
       };
 
-      client = {};
+      ${gopherClient} = {};
     };
 
     testScript = ''
       start_all()
-      ${gopherHost}.wait_for_open_port(70)
+
+      # with daemon type notify, the unit being started
+      # should also mean the port is open
       ${gopherHost}.wait_for_unit("spacecookie.service")
-      client.wait_for_unit("network.target")
+      ${gopherClient}.wait_for_unit("network.target")
 
-      fileResponse = client.succeed("curl -f -s gopher://${gopherHost}//${fileName}")
+      fileResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}/0/${fileName}")
 
       # the file response should return our created file exactly
-      if not (fileResponse == "${fileContent}\n"):
+      if not (fileResponse == "${builtins.replaceStrings [ "\n" ] [ "\\n" ] fileContent}"):
           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 -f -s gopher://${gopherHost}")
+      dirResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}")
       dirEntries = [l[0] for l in dirResponse.split("\n") if len(l) > 0]
       dirEntries.sort()