at 23.11-pre 1.8 kB view raw
1let 2 gopherRoot = "/tmp/gopher"; 3 gopherHost = "gopherd"; 4 gopherClient = "client"; 5 fileContent = "Hello Gopher!\n"; 6 fileName = "file.txt"; 7in 8 import ./make-test-python.nix ({...}: { 9 name = "spacecookie"; 10 nodes = { 11 ${gopherHost} = { 12 systemd.services.spacecookie = { 13 preStart = '' 14 mkdir -p ${gopherRoot}/directory 15 printf "%s" "${fileContent}" > ${gopherRoot}/${fileName} 16 ''; 17 }; 18 19 services.spacecookie = { 20 enable = true; 21 openFirewall = true; 22 settings = { 23 root = gopherRoot; 24 hostname = gopherHost; 25 }; 26 }; 27 }; 28 29 ${gopherClient} = {}; 30 }; 31 32 testScript = '' 33 start_all() 34 35 # with daemon type notify, the unit being started 36 # should also mean the port is open 37 ${gopherHost}.wait_for_unit("spacecookie.service") 38 ${gopherClient}.wait_for_unit("network.target") 39 40 fileResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}/0/${fileName}") 41 42 # the file response should return our created file exactly 43 if not (fileResponse == "${builtins.replaceStrings [ "\n" ] [ "\\n" ] fileContent}"): 44 raise Exception("Unexpected file response") 45 46 # sanity check on the directory listing: we serve a directory and a file 47 # via gopher, so the directory listing should have exactly two entries, 48 # one with gopher file type 0 (file) and one with file type 1 (directory). 49 dirResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}") 50 dirEntries = [l[0] for l in dirResponse.split("\n") if len(l) > 0] 51 dirEntries.sort() 52 53 if not (["0", "1"] == dirEntries): 54 raise Exception("Unexpected directory response") 55 ''; 56 })