1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3 inherit (import ./ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey;
11 meta.maintainers = with lib.maintainers; [ dadada ];
13 client = { pkgs, ... }: {
14 environment.systemPackages = with pkgs; [
19 environment.etc.sshKey = {
20 source = snakeOilPrivateKey;
28 services.soft-serve = {
32 ssh.listen_addr = ":${toString sshPort}";
33 git.listen_addr = ":${toString gitPort}";
34 http.listen_addr = ":${toString httpPort}";
35 stats.listen_addr = ":${toString statsPort}";
36 initial_admin_keys = [ snakeOilPublicKey ];
39 networking.firewall.allowedTCPPorts = [ sshPort httpPort statsPort ];
46 SSH_PORT = ${toString sshPort}
47 HTTP_PORT = ${toString httpPort}
48 STATS_PORT = ${toString statsPort}
49 KEY = "${snakeOilPublicKey}"
50 SSH_KEY = "/etc/sshKey"
51 SSH_COMMAND = f"ssh -p {SSH_PORT} -i {SSH_KEY} -o StrictHostKeyChecking=no"
52 TEST_DIR = "/tmp/test"
53 GIT = f"git -C {TEST_DIR}"
55 for machine in client, server:
56 machine.wait_for_unit("network.target")
58 server.wait_for_unit("soft-serve.service")
59 server.wait_for_open_port(SSH_PORT)
61 with subtest("Get info"):
62 status, test = client.execute(f"{SSH_COMMAND} server info")
64 raise Exception("Failed to get SSH info")
65 key = " ".join(KEY.split(" ")[0:2])
67 raise Exception("Admin key must be configured correctly")
69 with subtest("Create user"):
70 client.succeed(f"{SSH_COMMAND} server user create beatrice")
71 client.succeed(f"{SSH_COMMAND} server user info beatrice")
73 with subtest("Create repo"):
74 client.succeed(f"git init {TEST_DIR}")
75 client.succeed(f"{GIT} config --global user.email you@example.com")
76 client.succeed(f"touch {TEST_DIR}/foo")
77 client.succeed(f"{GIT} add foo")
78 client.succeed(f"{GIT} commit --allow-empty -m test")
79 client.succeed(f"{GIT} remote add origin git@server:test")
80 client.succeed(f"GIT_SSH_COMMAND='{SSH_COMMAND}' {GIT} push -u origin master")
81 client.execute("rm -r /tmp/test")
83 server.wait_for_open_port(HTTP_PORT)
85 with subtest("Clone over HTTP"):
86 client.succeed(f"curl --connect-timeout 10 http://server:{HTTP_PORT}/")
87 client.succeed(f"git clone http://server:{HTTP_PORT}/test /tmp/test")
88 client.execute("rm -r /tmp/test")
90 with subtest("Clone over SSH"):
91 client.succeed(f"GIT_SSH_COMMAND='{SSH_COMMAND}' git clone git@server:test /tmp/test")
92 client.execute("rm -r /tmp/test")
94 with subtest("Get stats over HTTP"):
95 server.wait_for_open_port(STATS_PORT)
96 status, test = client.execute(f"curl --connect-timeout 10 http://server:{STATS_PORT}/metrics")
98 raise Exception("Failed to get metrics from status port")
99 if not "go_gc_duration_seconds_count" in test:
100 raise Exception("Metrics did not contain key 'go_gc_duration_seconds_count'")