···
1
+
import ./make-test-python.nix ({ pkgs, ... }: {
4
+
meta = with pkgs.lib.maintainers; {
5
+
maintainers = [ sbruder ];
8
+
machine = { config, lib, pkgs, ... }: {
9
+
services.invidious = {
14
+
nginx.configuration = {
15
+
services.invidious = {
16
+
nginx.enable = true;
17
+
domain = "invidious.example.com";
19
+
services.nginx.virtualHosts."invidious.example.com" = {
23
+
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
25
+
postgres-tcp.configuration = {
26
+
services.invidious = {
28
+
createLocally = false;
30
+
passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
33
+
# Normally not needed because when connecting to postgres over TCP/IP
34
+
# the database is most likely on another host.
35
+
systemd.services.invidious = {
36
+
after = [ "postgresql.service" ];
37
+
requires = [ "postgresql.service" ];
39
+
services.postgresql =
41
+
inherit (config.services.invidious.settings.db) dbname user;
45
+
initialScript = pkgs.writeText "init-postgres-with-password" ''
46
+
CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
47
+
CREATE DATABASE invidious;
48
+
GRANT ALL PRIVILEGES ON DATABASE invidious TO kemal;
55
+
testScript = { nodes, ... }: ''
56
+
def curl_assert_status_code(url, code, form=None):
57
+
assert int(machine.succeed(f"curl -s -o /dev/null -w %{{http_code}} {'-F ' + form + ' ' if form else '''}{url}")) == code
60
+
def activate_specialisation(name: str):
61
+
machine.succeed(f"${nodes.machine.config.system.build.toplevel}/specialisation/{name}/bin/switch-to-configuration test >&2")
64
+
url = "http://localhost:${toString nodes.machine.config.services.invidious.port}"
65
+
port = ${toString nodes.machine.config.services.invidious.port}
67
+
machine.wait_for_open_port(port)
68
+
curl_assert_status_code(f"{url}/search", 200)
70
+
activate_specialisation("nginx")
71
+
machine.wait_for_open_port(80)
72
+
curl_assert_status_code("http://invidious.example.com/search", 200)
74
+
# Remove the state so the `initialScript` gets run
75
+
machine.succeed("systemctl stop postgresql")
76
+
machine.succeed("rm -r /var/lib/postgresql")
77
+
activate_specialisation("postgres-tcp")
78
+
machine.wait_for_open_port(port)
79
+
curl_assert_status_code(f"{url}/search", 200)