From 65d1f12e813ffb905d7d4c222233282a2594da4a Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 5 Jan 2021 17:44:01 +0100 Subject: [PATCH] Add NixOS integration test --- test.nix | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test.nix diff --git a/test.nix b/test.nix new file mode 100644 index 0000000..35a9ab7 --- /dev/null +++ b/test.nix @@ -0,0 +1,55 @@ +let + port = 8082; +in +import ({ pkgs, ... }: +{ + nodes = { + server = { + imports = [ ./module.nix ]; + + services.bang-evaluator = { + enable = true; + listenAddress = ":${toString port}"; + }; + + networking.firewall.allowedTCPPorts = [ port ]; + }; + client = { }; + }; + + testScript = '' + from urllib.parse import urlencode + + + def evalSearch(query, engine="https://duckduckgo.com/?q=%s"): + query_params = { + "query": query, + "engine": engine, + } + return client.succeed( + " ".join( + [ + "${pkgs.curl}/bin/curl", + "-s", + "-o/dev/null", + "-w", + "%{redirect_url}", + f"'http://server:${toString port}/eval?{urlencode(query_params)}'", + ] + ) + ) + + + start_all() + server.wait_for_open_port(${toString port}) + client.wait_for_unit("multi-user.target") + + assert evalSearch("foo") == "https://duckduckgo.com/?q=foo" + assert evalSearch("foo !wde") == "https://de.wikipedia.org/w/index.php?search=foo" + assert evalSearch("!wde foo") == "https://de.wikipedia.org/w/index.php?search=foo" + assert ( + evalSearch("foo", engine="https://startpage.com/sp/search?query=%s") + == "https://startpage.com/sp/search?query=foo" + ) + ''; +})