From a863a2b27902d2d8b87dae07c03f94e96d06d92b Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 Jul 2023 01:39:58 +0300 Subject: Implement Postgres backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A single giga-commit that took me weeks to produce. I know, this is not exactly the best thing ever — but I wanted to experiment first before "committing" to the implementation, so that I would produce the best solution. --- postgres-smoke-test.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 postgres-smoke-test.nix (limited to 'postgres-smoke-test.nix') diff --git a/postgres-smoke-test.nix b/postgres-smoke-test.nix new file mode 100644 index 0000000..51d53c7 --- /dev/null +++ b/postgres-smoke-test.nix @@ -0,0 +1,49 @@ +kittybox: +{ lib, ... }: { + name = "nixos-kittybox"; + + nodes = { + kittybox = { config, pkgs, lib, ... }: { + imports = [ kittybox.nixosModules.default ]; + + services.postgresql = { + enable = true; + ensureDatabases = ["kittybox"]; + ensureUsers = [ { + name = "kittybox"; + ensurePermissions = { + "DATABASE kittybox" = "ALL PRIVILEGES"; + }; + } ]; + }; + + services.kittybox = { + enable = true; + logLevel = "info,kittybox=debug,retainer::cache=warn,h2=warn,rustls=warn"; + backendUri = "postgres://localhost?host=/run/postgresql&dbname=kittybox"; + }; + + systemd.services.kittybox.wants = [ "postgresql.service" ]; + systemd.services.kittybox.after = [ "postgresql.service" ]; + + environment.systemPackages = with pkgs; [ + xh + ]; + }; + }; + + # TODO: Make e2e tests for authentication endpoints and such + # Potentially using WebDriver + # Could also be implemented with fantoccini + testScript = '' + with subtest("Verify that Kittybox started correctly..."): + kittybox.wait_for_open_port(8080) + kittybox.succeed("xh --no-check-status http://localhost:8080/.kittybox/micropub") + + with subtest("Onboarding should correctly work..."): + kittybox.copy_from_host("${./onboarding.json}", "/root/onboarding.json") + kittybox.succeed("xh --follow http://localhost:8080/.kittybox/onboarding -j @/root/onboarding.json") + # Testing for a known string is the easiest way to determine that the onboarding worked + kittybox.succeed("xh http://localhost:8080/ | grep 'vestige of the past long gone'") +''; +} -- cgit 1.4.1