From cb50679f0e9cc9e5711e229c15e71817ecd46d14 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 3 Jun 2020 23:12:06 +0200 Subject: [PATCH] nixos/tests/pinnwand: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/pinnwand.nix | 86 +++++++++++++++++++++++++++++++ pkgs/servers/pinnwand/default.nix | 4 +- pkgs/servers/pinnwand/steck.nix | 2 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/pinnwand.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 31dad3be8145..3ca48dff3ed4 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -268,6 +268,7 @@ in pgjwt = handleTest ./pgjwt.nix {}; pgmanage = handleTest ./pgmanage.nix {}; php = handleTest ./php {}; + pinnwand = handleTest ./pinnwand.nix {}; plasma5 = handleTest ./plasma5.nix {}; plotinus = handleTest ./plotinus.nix {}; podman = handleTestOn ["x86_64-linux"] ./podman.nix {}; diff --git a/nixos/tests/pinnwand.nix b/nixos/tests/pinnwand.nix new file mode 100644 index 000000000000..2204e74b2c28 --- /dev/null +++ b/nixos/tests/pinnwand.nix @@ -0,0 +1,86 @@ +import ./make-test-python.nix ({ pkgs, ...}: +let + pythonEnv = pkgs.python3.withPackages (py: with py; [ appdirs toml ]); + + port = 8000; + baseUrl = "http://server:${toString port}"; + + configureSteck = pkgs.writeScript "configure.py" '' + #!${pythonEnv.interpreter} + import appdirs + import toml + import os + + CONFIG = { + "base": "${baseUrl}/", + "confirm": False, + "magic": True, + "ignore": True + } + + os.makedirs(appdirs.user_config_dir('steck')) + with open(os.path.join(appdirs.user_config_dir('steck'), 'steck.toml'), "w") as fd: + toml.dump(CONFIG, fd) + ''; +in +{ + name = "pinnwand"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers =[ hexa ]; + }; + + nodes = { + server = { config, ... }: + { + networking.firewall.allowedTCPPorts = [ + port + ]; + + services.pinnwand = { + enable = true; + port = port; + }; + }; + + client = { pkgs, ... }: + { + environment.systemPackages = [ pkgs.steck ]; + }; + }; + + testScript = '' + start_all() + + server.wait_for_unit("pinnwand.service") + client.wait_for_unit("network.target") + + # create steck.toml config file + client.succeed("${configureSteck}") + + # wait until the server running pinnwand is reachable + client.wait_until_succeeds("ping -c1 server") + + # make sure pinnwand is listening + server.wait_until_succeeds("ss -lnp | grep ${toString port}") + + # send the contents of /etc/machine-id + response = client.succeed("steck paste /etc/machine-id") + + # parse the steck response + raw_url = None + removal_link = None + for line in response.split("\n"): + if line.startswith("View link:"): + raw_url = f"${baseUrl}/raw/{line.split('/')[-1]}" + if line.startswith("Removal link:"): + removal_link = line.split(":", 1)[1] + + # check whether paste matches what we sent + client.succeed(f"curl {raw_url} > /tmp/machine-id") + client.succeed("diff /tmp/machine-id /etc/machine-id") + + # remove paste and check that it's not available any more + client.succeed(f"curl {removal_link}") + client.fail(f"curl --fail {raw_url}") + ''; +}) diff --git a/pkgs/servers/pinnwand/default.nix b/pkgs/servers/pinnwand/default.nix index 563c539c825e..436a599b17e0 100644 --- a/pkgs/servers/pinnwand/default.nix +++ b/pkgs/servers/pinnwand/default.nix @@ -1,4 +1,4 @@ -{ lib, python3, fetchFromGitHub }: +{ lib, python3, fetchFromGitHub, nixosTests }: let python = python3.override { @@ -35,6 +35,8 @@ in with python.pkgs; buildPythonApplication rec { $out/bin/pinnwand --help > /dev/null ''; + passthru.tests = nixosTests.pinnwand; + meta = with lib; { homepage = "https://supakeen.com/project/pinnwand/"; license = licenses.mit; diff --git a/pkgs/servers/pinnwand/steck.nix b/pkgs/servers/pinnwand/steck.nix index 642c72326f4d..09b20efc36ee 100644 --- a/pkgs/servers/pinnwand/steck.nix +++ b/pkgs/servers/pinnwand/steck.nix @@ -19,6 +19,8 @@ python3Packages.buildPythonApplication rec { toml ]; + passthru.tests = nixosTests.pinnwand; + meta = with lib; { homepage = "https://github.com/supakeen/steck"; license = licenses.mit;