nixos/tests/linkwarden: init tests

This commit is contained in:
Jan van Brügge 2024-10-08 22:26:49 +01:00
parent 0bf693cb0f
commit 5ae9c6959e
No known key found for this signature in database
GPG key ID: 88E0BF7B7A546481
3 changed files with 66 additions and 0 deletions

View file

@ -831,6 +831,7 @@ in
lighttpd = runTest ./lighttpd.nix;
limesurvey = runTest ./limesurvey.nix;
limine = import ./limine { inherit runTest; };
linkwarden = runTest ./web-apps/linkwarden.nix;
listmonk = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./listmonk.nix { };
litellm = runTest ./litellm.nix;
litestream = runTest ./litestream.nix;

View file

@ -0,0 +1,60 @@
{ ... }:
{
name = "linkwarden-nixos";
nodes.machine =
{ pkgs, ... }:
let
secretsFile = pkgs.writeText "linkwarden-secret-env" ''
VERY_SENSITIVE_SECRET
'';
webroot = pkgs.runCommand "webroot" { } ''
mkdir $out
cd $out
echo '<!DOCTYPE html><html><body><h1>HELLO LINKWARDEN</h1></body></html>' > index.html
'';
in
{
services.linkwarden = {
enable = true;
enableRegistration = true;
secretFiles = {
NEXTAUTH_SECRET = toString secretsFile;
};
environment = {
NEXTAUTH_URL = "http://localhost:3000/api/v1/auth";
};
};
services.nginx = {
enable = true;
virtualHosts.localhost.root = webroot;
};
};
testScript = ''
import json
machine.wait_for_unit("linkwarden.service")
machine.wait_for_unit("linkwarden-worker.service")
machine.wait_for_open_port(3000)
machine.succeed("curl --fail -s http://localhost:3000/")
machine.succeed("curl -L --fail -s --data '{\"name\":\"Admin\",\"username\":\"admin\",\"password\":\"adminadmin\"}' -H 'Content-Type: application/json' -X POST http://localhost:3000/api/v1/users")
response = machine.succeed("curl -L --fail -s -c next_cookies.txt -H 'Content-Type: application/json' -X GET http://localhost:3000/api/v1/auth/csrf")
csrfToken = json.loads(response)['csrfToken']
machine.succeed("curl -L --fail -s -b next_cookies.txt -c next_cookies.txt -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'username=admin' --data-urlencode 'password=adminadmin' --data-urlencode 'csrfToken=%s' http://localhost:3000/api/v1/auth/callback/credentials" % csrfToken)
curlCmd = "curl -L --fail -s -b next_cookies.txt -H 'Content-Type: application/json' "
machine.succeed(curlCmd + "--data '{\"url\":\"http://localhost/\"}' -X POST http://localhost:3000/api/v1/links")
machine.succeed(curlCmd + "-X GET http://localhost:3000/api/v1/links")
machine.wait_for_file("/var/lib/linkwarden/archives/1/1.html")
machine.succeed("grep -q '<h1>HELLO LINKWARDEN</h1>' </var/lib/linkwarden/archives/1/1.html")
'';
}

View file

@ -5,6 +5,7 @@
fetchFromGitHub,
fetchYarnDeps,
makeBinaryWrapper,
nixosTests,
yarnConfigHook,
fetchpatch,
# dependencies
@ -188,6 +189,10 @@ stdenvNoCC.mkDerivation (finalAttrs: {
runHook postInstall
'';
passthru.tests = {
inherit (nixosTests) linkwarden;
};
meta = {
description = "Self-hosted collaborative bookmark manager to collect, organize, and preserve webpages, articles, and more...";
homepage = "https://linkwarden.app/";