git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/pinnwand: init
commitcb50679f0e9cc9e5711e229c15e71817ecd46d14 authorMartin Weinelt <hexa@darmstadt.ccc.de> dateWed 3 Jun 2020, 23:12 (6 years ago) parent607a94c
4 files changed+92−1
nixos/tests/all-tests.nix+1 nixos/tests/pinnwand.nix+86 pkgs/servers/pinnwand/default.nix+3−1 pkgs/servers/pinnwand/steck.nix+2
nixos/tests/all-tests.nix+1
@@ -268,6 +268,7 @@ in
268268 pgjwt = handleTest ./pgjwt.nix {};
269269 pgmanage = handleTest ./pgmanage.nix {};
270270 php = handleTest ./php {};
271+ pinnwand = handleTest ./pinnwand.nix {};
271272 plasma5 = handleTest ./plasma5.nix {};
272273 plotinus = handleTest ./plotinus.nix {};
273274 podman = handleTestOn ["x86_64-linux"] ./podman.nix {};
nixos/tests/pinnwand.nixnew file+86
@@ -0,0 +1,86 @@
1+import ./make-test-python.nix ({ pkgs, ...}:
2+let
3+ pythonEnv = pkgs.python3.withPackages (py: with py; [ appdirs toml ]);
4+
5+ port = 8000;
6+ baseUrl = "http://server:${toString port}";
7+
8+ configureSteck = pkgs.writeScript "configure.py" ''
9+ #!${pythonEnv.interpreter}
10+ import appdirs
11+ import toml
12+ import os
13+
14+ CONFIG = {
15+ "base": "${baseUrl}/",
16+ "confirm": False,
17+ "magic": True,
18+ "ignore": True
19+ }
20+
21+ os.makedirs(appdirs.user_config_dir('steck'))
22+ with open(os.path.join(appdirs.user_config_dir('steck'), 'steck.toml'), "w") as fd:
23+ toml.dump(CONFIG, fd)
24+ '';
25+in
26+{
27+ name = "pinnwand";
28+ meta = with pkgs.stdenv.lib.maintainers; {
29+ maintainers =[ hexa ];
30+ };
31+
32+ nodes = {
33+ server = { config, ... }:
34+ {
35+ networking.firewall.allowedTCPPorts = [
36+ port
37+ ];
38+
39+ services.pinnwand = {
40+ enable = true;
41+ port = port;
42+ };
43+ };
44+
45+ client = { pkgs, ... }:
46+ {
47+ environment.systemPackages = [ pkgs.steck ];
48+ };
49+ };
50+
51+ testScript = ''
52+ start_all()
53+
54+ server.wait_for_unit("pinnwand.service")
55+ client.wait_for_unit("network.target")
56+
57+ # create steck.toml config file
58+ client.succeed("${configureSteck}")
59+
60+ # wait until the server running pinnwand is reachable
61+ client.wait_until_succeeds("ping -c1 server")
62+
63+ # make sure pinnwand is listening
64+ server.wait_until_succeeds("ss -lnp | grep ${toString port}")
65+
66+ # send the contents of /etc/machine-id
67+ response = client.succeed("steck paste /etc/machine-id")
68+
69+ # parse the steck response
70+ raw_url = None
71+ removal_link = None
72+ for line in response.split("\n"):
73+ if line.startswith("View link:"):
74+ raw_url = f"${baseUrl}/raw/{line.split('/')[-1]}"
75+ if line.startswith("Removal link:"):
76+ removal_link = line.split(":", 1)[1]
77+
78+ # check whether paste matches what we sent
79+ client.succeed(f"curl {raw_url} > /tmp/machine-id")
80+ client.succeed("diff /tmp/machine-id /etc/machine-id")
81+
82+ # remove paste and check that it's not available any more
83+ client.succeed(f"curl {removal_link}")
84+ client.fail(f"curl --fail {raw_url}")
85+ '';
86+})
pkgs/servers/pinnwand/default.nix+3−1
@@ -1,4 +1,4 @@
1−{ lib, python3, fetchFromGitHub }:
1+{ lib, python3, fetchFromGitHub, nixosTests }:
22
33let
44 python = python3.override {
@@ -35,6 +35,8 @@ in with python.pkgs; buildPythonApplication rec {
3535 $out/bin/pinnwand --help > /dev/null
3636 '';
3737
38+ passthru.tests = nixosTests.pinnwand;
39+
3840 meta = with lib; {
3941 homepage = "https://supakeen.com/project/pinnwand/";
4042 license = licenses.mit;
pkgs/servers/pinnwand/steck.nix+2
@@ -19,6 +19,8 @@ python3Packages.buildPythonApplication rec {
1919 toml
2020 ];
2121
22+ passthru.tests = nixosTests.pinnwand;
23+
2224 meta = with lib; {
2325 homepage = "https://github.com/supakeen/steck";
2426 license = licenses.mit;