From 50c8f7d8f5f04c717ef4e72d873bf994c03efda0 Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 22 Jul 2023 13:17:56 +0300 Subject: Move NixOS tests to a separate folder to prevent clutter --- distributed-test.nix | 90 ------------------------------------- flake.nix | 6 +-- nixos-tests/distributed-test.nix | 90 +++++++++++++++++++++++++++++++++++++ nixos-tests/onboarding.json | 33 ++++++++++++++ nixos-tests/postgres-smoke-test.nix | 49 ++++++++++++++++++++ nixos-tests/smoke-test.nix | 54 ++++++++++++++++++++++ onboarding.json | 33 -------------- postgres-smoke-test.nix | 49 -------------------- smoke-test.nix | 54 ---------------------- 9 files changed, 229 insertions(+), 229 deletions(-) delete mode 100644 distributed-test.nix create mode 100644 nixos-tests/distributed-test.nix create mode 100644 nixos-tests/onboarding.json create mode 100644 nixos-tests/postgres-smoke-test.nix create mode 100644 nixos-tests/smoke-test.nix delete mode 100644 onboarding.json delete mode 100644 postgres-smoke-test.nix delete mode 100644 smoke-test.nix diff --git a/distributed-test.nix b/distributed-test.nix deleted file mode 100644 index 11c2dba..0000000 --- a/distributed-test.nix +++ /dev/null @@ -1,90 +0,0 @@ -# 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/flake.nix b/flake.nix index e258dc4..ec4d07e 100644 --- a/flake.nix +++ b/flake.nix @@ -42,9 +42,9 @@ checks = { kittybox = self.packages.${system}.kittybox; - distributed-test = pkgs.nixosTest (import ./distributed-test.nix self); - nixos-test = pkgs.nixosTest (import ./smoke-test.nix self); - nixos-test-postgres = pkgs.nixosTest (import ./postgres-smoke-test.nix self); + distributed-test = pkgs.nixosTest (import ./nixos-tests/distributed-test.nix self); + nixos-test = pkgs.nixosTest (import ./nixos-tests/smoke-test.nix self); + nixos-test-postgres = pkgs.nixosTest (import ./nixos-tests/postgres-smoke-test.nix self); dockerContainer = pkgs.callPackage ./docker.nix { inherit (self.packages.${system}) kittybox; rev = self.rev or "development"; 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'") +''; +} diff --git a/onboarding.json b/onboarding.json deleted file mode 100644 index 04acbf8..0000000 --- a/onboarding.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "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/postgres-smoke-test.nix b/postgres-smoke-test.nix deleted file mode 100644 index 51d53c7..0000000 --- a/postgres-smoke-test.nix +++ /dev/null @@ -1,49 +0,0 @@ -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/smoke-test.nix b/smoke-test.nix deleted file mode 100644 index b043a31..0000000 --- a/smoke-test.nix +++ /dev/null @@ -1,54 +0,0 @@ -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'") -''; -} -- cgit 1.4.1