1 import ./make-test-python.nix ({ lib, ... }: {
3 meta.maintainers = with lib.maintainers; [ aorith ];
5 nodes.simple = { ... }: {
6 services.silverbullet.enable = true;
9 nodes.configured = { pkgs, ... }: {
10 users.users.test.isNormalUser = true;
11 users.groups.test = { };
13 services.silverbullet = {
15 package = pkgs.silverbullet;
17 listenAddress = "localhost";
18 spaceDir = "/home/test/silverbullet";
21 envFile = pkgs.writeText "silverbullet.env" ''
25 extraArgs = [ "--reindex" "--db /home/test/silverbullet/custom.db" ];
29 testScript = { nodes, ... }: ''
30 PORT = ${builtins.toString nodes.simple.services.silverbullet.listenPort}
31 ADDRESS = "${nodes.simple.services.silverbullet.listenAddress}"
32 SPACEDIR = "${nodes.simple.services.silverbullet.spaceDir}"
33 simple.wait_for_unit("silverbullet.service")
34 simple.wait_for_open_port(PORT)
35 simple.succeed(f"curl --max-time 5 -s -v -o /dev/null --fail http://{ADDRESS}:{PORT}/")
36 simple.succeed(f"test -d '{SPACEDIR}'")
38 PORT = ${builtins.toString nodes.configured.services.silverbullet.listenPort}
39 ADDRESS = "${nodes.configured.services.silverbullet.listenAddress}"
40 SPACEDIR = "${nodes.configured.services.silverbullet.spaceDir}"
41 configured.wait_for_unit("silverbullet.service")
42 configured.wait_for_open_port(PORT)
43 assert int(configured.succeed(f"curl --max-time 5 -s -o /dev/null -w '%{{http_code}}' -XPUT -d 'test' --fail http://{ADDRESS}:{PORT}/test.md -H'Authorization: Bearer test'")) == 200
44 assert int(configured.fail(f"curl --max-time 5 -s -o /dev/null -w '%{{http_code}}' -XPUT -d 'test' --fail http://{ADDRESS}:{PORT}/test.md -H'Authorization: Bearer wrong'")) == 401
45 configured.succeed(f"test -d '{SPACEDIR}'")