nixos/tests/chhoto-url: init
This commit is contained in:
parent
55e6f26bff
commit
b6ebd3bac9
@ -311,6 +311,7 @@ in
|
|||||||
cfssl = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix;
|
cfssl = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix;
|
||||||
cgit = runTest ./cgit.nix;
|
cgit = runTest ./cgit.nix;
|
||||||
charliecloud = runTest ./charliecloud.nix;
|
charliecloud = runTest ./charliecloud.nix;
|
||||||
|
chhoto-url = runTest ./chhoto-url.nix;
|
||||||
chromadb = runTest ./chromadb.nix;
|
chromadb = runTest ./chromadb.nix;
|
||||||
chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { };
|
chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { };
|
||||||
chrony = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./chrony.nix;
|
chrony = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./chrony.nix;
|
||||||
|
|||||||
60
nixos/tests/chhoto-url.nix
Normal file
60
nixos/tests/chhoto-url.nix
Normal 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
|
||||||
|
'';
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
lib,
|
lib,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
fetchFromGitHub,
|
fetchFromGitHub,
|
||||||
|
nixosTests,
|
||||||
nix-update-script,
|
nix-update-script,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
@ -30,7 +31,10 @@ rustPlatform.buildRustPackage (finalAttrs: {
|
|||||||
cp -r ${finalAttrs.src}/resources $out/share/chhoto-url/resources
|
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 = {
|
meta = {
|
||||||
description = "Simple, blazingly fast, selfhosted URL shortener with no unnecessary features";
|
description = "Simple, blazingly fast, selfhosted URL shortener with no unnecessary features";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user