Add NixOS integration test
This commit is contained in:
parent
d3c0d9f786
commit
65d1f12e81
55
test.nix
Normal file
55
test.nix
Normal file
|
@ -0,0 +1,55 @@
|
|||
let
|
||||
port = 8082;
|
||||
in
|
||||
import <nixpkgs/nixos/tests/make-test-python.nix> ({ 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"
|
||||
)
|
||||
'';
|
||||
})
|
Loading…
Reference in a new issue