| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |   gopherRoot   = "/tmp/gopher"; | 
					
						
							|  |  |  |   gopherHost   = "gopherd"; | 
					
						
							|  |  |  |   gopherClient = "client"; | 
					
						
							|  |  |  |   fileContent  = "Hello Gopher!\n"; | 
					
						
							|  |  |  |   fileName     = "file.txt"; | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  | in | 
					
						
							|  |  |  |   import ./make-test-python.nix ({...}: { | 
					
						
							|  |  |  |     name = "spacecookie"; | 
					
						
							|  |  |  |     nodes = { | 
					
						
							|  |  |  |       ${gopherHost} = { | 
					
						
							|  |  |  |         systemd.services.spacecookie = { | 
					
						
							|  |  |  |           preStart = ''
 | 
					
						
							|  |  |  |             mkdir -p ${gopherRoot}/directory | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |             printf "%s" "${fileContent}" > ${gopherRoot}/${fileName} | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |           '';
 | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         services.spacecookie = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							| 
									
										
										
										
											2021-03-10 21:56:11 +01:00
										 |  |  |           openFirewall = true; | 
					
						
							| 
									
										
										
										
											2021-03-10 22:12:36 +01:00
										 |  |  |           settings = { | 
					
						
							|  |  |  |             root = gopherRoot; | 
					
						
							|  |  |  |             hostname = gopherHost; | 
					
						
							|  |  |  |           }; | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |       ${gopherClient} = {}; | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     testScript = ''
 | 
					
						
							|  |  |  |       start_all() | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # with daemon type notify, the unit being started | 
					
						
							|  |  |  |       # should also mean the port is open | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |       ${gopherHost}.wait_for_unit("spacecookie.service") | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |       ${gopherClient}.wait_for_unit("network.target") | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |       fileResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}/0/${fileName}") | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # the file response should return our created file exactly | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |       if not (fileResponse == "${builtins.replaceStrings [ "\n" ] [ "\\n" ] fileContent}"): | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |           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). | 
					
						
							| 
									
										
										
										
											2020-12-28 00:16:26 +01:00
										 |  |  |       dirResponse = ${gopherClient}.succeed("curl -f -s gopher://${gopherHost}") | 
					
						
							| 
									
										
										
										
											2019-05-24 21:17:51 +02:00
										 |  |  |       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") | 
					
						
							|  |  |  |     '';
 | 
					
						
							|  |  |  |   }) |