about summary refs log tree commit diff
path: root/postgres-smoke-test.nix
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-07-09 01:39:58 +0300
committerVika <vika@fireburn.ru>2023-07-09 01:39:58 +0300
commita863a2b27902d2d8b87dae07c03f94e96d06d92b (patch)
tree960487de597f02f28b44d77966189d86d885e43c /postgres-smoke-test.nix
parent63148c502c11fcbe99f335c5d214fba84eda1c1c (diff)
downloadkittybox-a863a2b27902d2d8b87dae07c03f94e96d06d92b.tar.zst
Implement Postgres backend
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.
Diffstat (limited to 'postgres-smoke-test.nix')
-rw-r--r--postgres-smoke-test.nix49
1 files changed, 49 insertions, 0 deletions
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'")
+'';
+}