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