nixos/tests/chhoto-url: init

This commit is contained in:
Defelo 2025-07-12 16:48:06 +02:00
parent 55e6f26bff
commit b6ebd3bac9
No known key found for this signature in database
GPG Key ID: 2A05272471204DD3
3 changed files with 66 additions and 1 deletions

View File

@ -311,6 +311,7 @@ in
cfssl = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix;
cgit = runTest ./cgit.nix;
charliecloud = runTest ./charliecloud.nix;
chhoto-url = runTest ./chhoto-url.nix;
chromadb = runTest ./chromadb.nix;
chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { };
chrony = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./chrony.nix;

View File

@ -0,0 +1,60 @@
{ config, lib, ... }:
{
name = "chhoto-url";
meta.maintainers = with lib.maintainers; [ defelo ];
nodes.machine = {
services.chhoto-url = {
enable = true;
settings.port = 8000;
environmentFiles = [
(builtins.toFile "chhoto-url.env" ''
api_key=api_key
password=password
'')
];
};
};
interactive.nodes.machine = {
services.glitchtip.listenAddress = "0.0.0.0";
networking.firewall.allowedTCPPorts = [ 8000 ];
virtualisation.forwardPorts = [
{
from = "host";
host.port = 8000;
guest.port = 8000;
}
];
};
testScript = ''
import json
import re
machine.wait_for_unit("chhoto-url.service")
machine.wait_for_open_port(8000)
resp = json.loads(machine.succeed("curl localhost:8000/api/getconfig"))
assert resp["success"] is False
assert resp["reason"] == "No valid authentication was found"
resp = json.loads(machine.succeed("curl -H 'X-API-Key: api_key' localhost:8000/api/getconfig"))
expected_version = "${config.nodes.machine.services.chhoto-url.package.version}"
assert resp["version"] == expected_version
resp = json.loads(machine.succeed("curl -H 'X-API-Key: api_key' localhost:8000/api/new -d '{\"longlink\": \"https://nixos.org/\"}'"))
assert resp["success"] is True
assert (match := re.match(r"^http://localhost:8000/(.+)$", resp["shorturl"]))
slug = match[1]
resp = machine.succeed(f"curl -i {resp["shorturl"]}")
assert (match := re.search(r"(?m)^location: (.+?)\r?$", resp))
assert match[1] == "https://nixos.org/"
resp = json.loads(machine.succeed(f"curl -H 'X-API-Key: api_key' localhost:8000/api/expand -d '{slug}'"))
assert resp["success"] is True
assert resp["hits"] == 1
'';
}

View File

@ -2,6 +2,7 @@
lib,
rustPlatform,
fetchFromGitHub,
nixosTests,
nix-update-script,
}:
@ -30,7 +31,10 @@ rustPlatform.buildRustPackage (finalAttrs: {
cp -r ${finalAttrs.src}/resources $out/share/chhoto-url/resources
'';
passthru.updateScript = nix-update-script { };
passthru = {
tests = { inherit (nixosTests) chhoto-url; };
updateScript = nix-update-script { };
};
meta = {
description = "Simple, blazingly fast, selfhosted URL shortener with no unnecessary features";