nixosTests.silverbullet: init

This commit is contained in:
Manuel Sanchez Pinar 2024-03-16 17:12:16 +01:00
parent a1301766eb
commit b8f91b87a3
No known key found for this signature in database
2 changed files with 48 additions and 0 deletions

View File

@ -786,6 +786,7 @@ in {
shattered-pixel-dungeon = handleTest ./shattered-pixel-dungeon.nix {};
shiori = handleTest ./shiori.nix {};
signal-desktop = handleTest ./signal-desktop.nix {};
silverbullet = handleTest ./silverbullet.nix {};
simple = handleTest ./simple.nix {};
sing-box = handleTest ./sing-box.nix {};
slimserver = handleTest ./slimserver.nix {};

View File

@ -0,0 +1,47 @@
import ./make-test-python.nix ({ lib, ... }: {
name = "silverbullet";
meta.maintainers = with lib.maintainers; [ aorith ];
nodes.simple = { ... }: {
services.silverbullet.enable = true;
};
nodes.configured = { pkgs, ... }: {
users.users.test.isNormalUser = true;
users.groups.test = { };
services.silverbullet = {
enable = true;
package = pkgs.silverbullet;
listenPort = 3001;
listenAddress = "localhost";
spaceDir = "/home/test/silverbullet";
user = "test";
group = "test";
envFile = pkgs.writeText "silverbullet.env" ''
SB_USER=user:password
SB_AUTH_TOKEN=test
'';
extraArgs = [ "--reindex" "--db /home/test/silverbullet/custom.db" ];
};
};
testScript = { nodes, ... }: ''
PORT = ${builtins.toString nodes.simple.services.silverbullet.listenPort}
ADDRESS = "${nodes.simple.services.silverbullet.listenAddress}"
SPACEDIR = "${nodes.simple.services.silverbullet.spaceDir}"
simple.wait_for_unit("silverbullet.service")
simple.wait_for_open_port(PORT)
simple.succeed(f"curl --max-time 5 -s -v -o /dev/null --fail http://{ADDRESS}:{PORT}/")
simple.succeed(f"test -d '{SPACEDIR}'")
PORT = ${builtins.toString nodes.configured.services.silverbullet.listenPort}
ADDRESS = "${nodes.configured.services.silverbullet.listenAddress}"
SPACEDIR = "${nodes.configured.services.silverbullet.spaceDir}"
configured.wait_for_unit("silverbullet.service")
configured.wait_for_open_port(PORT)
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
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
configured.succeed(f"test -d '{SPACEDIR}'")
'';
})