diff options
Diffstat (limited to 'nixos-tests')
-rw-r--r-- | nixos-tests/distributed-test.nix | 90 | ||||
-rw-r--r-- | nixos-tests/onboarding.json | 33 | ||||
-rw-r--r-- | nixos-tests/postgres-smoke-test.nix | 49 | ||||
-rw-r--r-- | nixos-tests/smoke-test.nix | 54 |
4 files changed, 226 insertions, 0 deletions
diff --git a/nixos-tests/distributed-test.nix b/nixos-tests/distributed-test.nix new file mode 100644 index 0000000..11c2dba --- /dev/null +++ b/nixos-tests/distributed-test.nix @@ -0,0 +1,90 @@ +# This doesn't seem to work for some reason. I wonder why. +# The VMs themselves don't want to launch properly. +kittybox: +{ lib, system, ... }: let + kittyboxModule = { config, pkgs, lib, ... }: { + imports = [ kittybox.nixosModules.default commonModule ]; + + services.kittybox = { + enable = true; + backendUri = "file:///srv/kittybox/data"; + blobstoreUri = "file:///srv/kittybox/media"; + }; + + environment.systemPackages = with pkgs; [ xh ]; + + virtualisation.fileSystems."/srv" = { + fsType = "nfs"; + options = [ "vers=4" ]; + device = "primrose:/"; + }; + + systemd.services.kittybox = { + bindsTo = [ "srv.mount" ]; + after = [ "srv.mount" ]; + serviceConfig = { + DynamicUser = lib.mkForce false; + User = "kittybox"; + Group = "kittybox"; + }; + }; + }; + commonModule = { + users.users.kittybox = { + isSystemUser = true; + uid = 990; + group = "kittybox"; + }; + users.groups.kittybox.gid = 990; + networking.firewall.enable = false; + }; +in { + name = "kittybox-distributed"; + + nodes = { + primrose = { config, pkgs, lib, ... }: { + imports = [ commonModule ]; + services.nfs.server.enable = true; + services.nfs.server.createMountPoints = true; + services.nfs.server.exports = '' + /srv 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0) + ''; + systemd.tmpfiles.rules = [ + "d /srv/kittybox 1750 kittybox root -" + "d /srv/kittybox/data 1750 kittybox root -" + "d /srv/kittybox/media 1750 kittybox root -" + ]; + }; + longiflorum = { config, pkgs, lib, ... }: { + imports = [ kittyboxModule ]; + }; + amaranthus = { config, pkgs, lib, ... }: { + imports = [ kittyboxModule ]; + }; + hydrangea = { config, pkgs, lib, ... }: { + imports = [ kittyboxModule ]; + }; + }; + + testScript = '' + primary = primrose; + servants = [longiflorum, amaranthus, hydrangea]; + + primary.wait_for_unit("nfs-server") + primary.succeed("systemctl start network-online.target") + primary.wait_for_unit("network-online.target") + + start_all() + + for machine in servants: + machine.wait_for_open_port(8080) + + # Onboarding + servants[0].copy_from_host("${./onboarding.json}", "/root/onboarding.json") + servants[0].succeed("xh --follow http://localhost:8080/.kittybox/onboarding -j @/root/onboarding.json") + + # Check that all machines got this address onboarded + for machine in servants: + machine.succeed("xh http://localhost:8080/ | grep 'vestige of the past long gone'") + ''; +} diff --git a/nixos-tests/onboarding.json b/nixos-tests/onboarding.json new file mode 100644 index 0000000..04acbf8 --- /dev/null +++ b/nixos-tests/onboarding.json @@ -0,0 +1,33 @@ +{ + "user": { + "type": [ + "h-card" + ], + "properties": { + "name": [ + "Vika" + ], + "pronoun": [ + "she/her" + ], + "url": [ + "https://twitter.com/VikaNezrimaya" + ], + "note": [ + "Just a simple girl. Do I even exist or am I a vestige of the past long gone?" + ] + } + }, + "first_post": { + "type": [ + "h-entry" + ], + "properties": { + "content": [ + "Hello!" + ] + } + }, + "blog_name": "Test Hideout", + "feeds": [] +} diff --git a/nixos-tests/postgres-smoke-test.nix b/nixos-tests/postgres-smoke-test.nix new file mode 100644 index 0000000..51d53c7 --- /dev/null +++ b/nixos-tests/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'") +''; +} diff --git a/nixos-tests/smoke-test.nix b/nixos-tests/smoke-test.nix new file mode 100644 index 0000000..b043a31 --- /dev/null +++ b/nixos-tests/smoke-test.nix @@ -0,0 +1,54 @@ +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"; + }; + } ]; + }; + + systemd.services.kittybox.wants = [ "postgresql.service" ]; + systemd.services.kittybox.after = [ "postgresql.service" ]; + systemd.services.kittybox.wantedBy = lib.mkForce []; + + services.kittybox = { + enable = true; + logLevel = "info,kittybox=debug,retainer::cache=warn,h2=warn,rustls=warn"; + }; + + environment.systemPackages = with pkgs; [ + xh + ]; + }; + }; + + # TODO: Make e2e tests for authentication endpoints and such + # Potentially using WebDriver + # Could also be implemented with fantoccini + testScript = '' + kittybox.wait_for_unit("default.target") + with subtest("Ensure that Kittybox service is socket activated..."): + kittybox.fail("systemctl is-active kittybox.service") + kittybox.succeed("systemctl is-active kittybox.socket") + + with subtest("Verify that Kittybox starts correctly..."): + kittybox.succeed("xh --no-check-status http://localhost:8080/.kittybox/micropub") + kittybox.succeed("systemctl is-active kittybox.service") + + 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'") +''; +} |