nixpkgs/nixos/tests/hledger-web.nix
Justin Humm 569940b9fd nixos/hledger-web: add stateDir, use own user, fix ExecStart
This allows for shared hledger installations, where the web interface is
available via network and multiple user share a SSH access to the
hledger user.

Also added `--serve` to the CLI options, as hledger-web tries to open a
webbrowser otherwise:

hledger-web: xdg-open: rawSystem: runInteractiveProcess: exec: does not
exist (No such file or directory)

Co-authored-by: Aaron Andersen <aaron@fosslib.net>
2021-03-26 13:45:13 +01:00

50 lines
1.5 KiB
Nix

import ./make-test-python.nix ({ pkgs, lib, ... }:
let
journal = pkgs.writeText "test.journal" ''
2010/01/10 Loan
assets:cash 500$
income:loan -500$
2010/01/10 NixOS Foundation donation
expenses:donation 250$
assets:cash -250$
'';
in
rec {
name = "hledger-web";
meta.maintainers = with lib.maintainers; [ marijanp ];
nodes = rec {
server = { config, pkgs, ... }: {
services.hledger-web = {
host = "127.0.0.1";
port = 5000;
enable = true;
};
networking.firewall.allowedTCPPorts = [ config.services.hledger-web.port ];
systemd.services.hledger-web.preStart = ''
ln -s ${journal} /var/lib/hledger-web/.hledger.journal
'';
};
apiserver = { ... }: {
imports = [ server ];
services.hledger-web.serveApi = true;
};
};
testScript = ''
start_all()
server.wait_for_unit("hledger-web.service")
server.wait_for_open_port(5000)
with subtest("Check if web UI is accessible"):
page = server.succeed("curl -L http://127.0.0.1:5000")
assert ".hledger.journal" in page
apiserver.wait_for_unit("hledger-web.service")
apiserver.wait_for_open_port(5000)
with subtest("Check if the JSON API is served"):
transactions = apiserver.succeed("curl -L http://127.0.0.1:5000/transactions")
assert "NixOS Foundation donation" in transactions
'';
})