nixpkgs/nixos/tests/invidious.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.7 KiB
Nix
Raw Normal View History

2021-09-07 17:44:12 +00:00
import ./make-test-python.nix ({ pkgs, ... }: {
name = "invidious";
meta = with pkgs.lib.maintainers; {
maintainers = [ sbruder ];
};
nodes = {
postgres-tcp = { config, pkgs, ... }: {
services.postgresql = {
enable = true;
initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER kemal WITH PASSWORD 'correct horse battery staple';
CREATE DATABASE invidious WITH OWNER kemal;
'';
enableTCPIP = true;
authentication = ''
host invidious kemal samenet scram-sha-256
'';
};
networking.firewall.allowedTCPPorts = [ config.services.postgresql.port ];
2021-09-07 17:44:12 +00:00
};
machine = { config, lib, pkgs, ... }: {
services.invidious = {
enable = true;
2021-09-07 17:44:12 +00:00
};
services.postgresql.initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER kemal;
CREATE DATABASE invidious WITH OWNER kemal;
'';
specialisation = {
nginx.configuration = {
services.invidious = {
nginx.enable = true;
domain = "invidious.example.com";
2021-09-07 17:44:12 +00:00
};
services.nginx.virtualHosts."invidious.example.com" = {
forceSSL = false;
enableACME = false;
};
networking.hosts."127.0.0.1" = [ "invidious.example.com" ];
2021-09-07 17:44:12 +00:00
};
postgres-tcp.configuration = {
services.invidious = {
database = {
createLocally = false;
host = "postgres-tcp";
passwordFile = toString (pkgs.writeText "database-password" "correct horse battery staple");
};
2021-09-07 17:44:12 +00:00
};
};
2021-09-07 17:44:12 +00:00
};
};
};
testScript = { nodes, ... }: ''
def curl_assert_status_code(url, code, form=None):
assert int(machine.succeed(f"curl -s -o /dev/null -w %{{http_code}} {'-F ' + form + ' ' if form else '''}{url}")) == code
def activate_specialisation(name: str):
machine.succeed(f"${nodes.machine.config.system.build.toplevel}/specialisation/{name}/bin/switch-to-configuration test >&2")
url = "http://localhost:${toString nodes.machine.config.services.invidious.port}"
port = ${toString nodes.machine.config.services.invidious.port}
# start postgres vm now
postgres_tcp.start()
2021-09-07 17:44:12 +00:00
machine.wait_for_open_port(port)
curl_assert_status_code(f"{url}/search", 200)
activate_specialisation("nginx")
machine.wait_for_open_port(80)
curl_assert_status_code("http://invidious.example.com/search", 200)
postgres_tcp.wait_for_unit("postgresql.service")
2021-09-07 17:44:12 +00:00
activate_specialisation("postgres-tcp")
machine.wait_for_open_port(port)
curl_assert_status_code(f"{url}/search", 200)
'';
})