Skip to content

Commit

Permalink
nixos/tests/zipline: init
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Jan 12, 2025
1 parent 24f222f commit c483900
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ in {
zeronet-conservancy = handleTest ./zeronet-conservancy.nix {};
zfs = handleTest ./zfs.nix {};
zigbee2mqtt = handleTest ./zigbee2mqtt.nix {};
zipline = handleTest ./zipline.nix {};
zoneminder = handleTest ./zoneminder.nix {};
zookeeper = handleTest ./zookeeper.nix {};
zram-generator = handleTest ./zram-generator.nix {};
Expand Down
48 changes: 48 additions & 0 deletions nixos/tests/zipline.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import ./make-test-python.nix (
{ lib, ... }:
{
name = "zipline";
meta.maintainers = with lib.maintainers; [ defelo ];

nodes.machine = {
services.zipline = {
enable = true;
settings = {
CORE_HOST = "127.0.0.1";
CORE_PORT = 8000;
};
environmentFiles = [
(builtins.toFile "zipline.env" ''
CORE_SECRET=testsecret
'')
];
};

networking.hosts."127.0.0.1" = [ "zipline.local" ];
};

testScript = ''
import json
import re
machine.wait_for_unit("zipline.service")
machine.wait_for_open_port(8000)
resp = machine.succeed("curl zipline.local:8000/api/auth/login -v -X POST -H 'Content-Type: application/json' -d '{\"username\": \"administrator\", \"password\": \"password\"}' 2>&1")
assert json.loads(resp.splitlines()[-1]) == {"success": True}
assert (cookie := re.search(r"(?m)^< Set-Cookie: ([^;]*)", resp))
resp = machine.succeed(f"curl zipline.local:8000/api/user/token -H 'Cookie: {cookie[1]}' -X PATCH")
token = json.loads(resp)["success"]
resp = machine.succeed(f"curl zipline.local:8000/api/shorten -H 'Authorization: {token}' -X POST -H 'Content-Type: application/json' -d '{{\"url\": \"https://nixos.org/\", \"vanity\": \"nixos\"}}'")
url = json.loads(resp)["url"]
assert url == "http://zipline.local:8000/go/nixos"
resp = machine.succeed(f"curl -I {url}")
assert re.search(r"(?m)^HTTP/1.1 302 Found\r?$", resp)
assert (location := re.search(r"(?mi)^location: (.+?)\r?$", resp))
assert location[1] == "https://nixos.org/"
'';
}
)
5 changes: 5 additions & 0 deletions pkgs/by-name/zi/zipline/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ffmpeg,
python3,
vips,
nixosTests,
}:

let
Expand Down Expand Up @@ -134,6 +135,10 @@ stdenv.mkDerivation (finalAttrs: {
done
'';

passthru = {
tests = { inherit (nixosTests) zipline; };
};

meta = {
description = "ShareX/file upload server that is easy to use, packed with features, and with an easy setup";
changelog = "https://github.com/diced/zipline/releases/tag/v${finalAttrs.version}";
Expand Down

0 comments on commit c483900

Please sign in to comment.