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