From 8cff7c9e6951462aef44e6a1f6050dc45dfd53f2 Mon Sep 17 00:00:00 2001 From: Julien Malka Date: Sun, 15 Oct 2023 10:40:11 +0200 Subject: [PATCH] tests/ferretdb: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/ferretdb.nix | 64 +++++++++++++++++++++++++ pkgs/servers/nosql/ferretdb/default.nix | 3 ++ 3 files changed, 68 insertions(+) create mode 100644 nixos/tests/ferretdb.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 61cd7a3e0c7f..dac3e1d6973d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -274,6 +274,7 @@ in { fcitx5 = handleTest ./fcitx5 {}; fenics = handleTest ./fenics.nix {}; ferm = handleTest ./ferm.nix {}; + ferretdb = handleTest ./ferretdb.nix {}; firefox = handleTest ./firefox.nix { firefoxPackage = pkgs.firefox; }; firefox-beta = handleTest ./firefox.nix { firefoxPackage = pkgs.firefox-beta; }; firefox-devedition = handleTest ./firefox.nix { firefoxPackage = pkgs.firefox-devedition; }; diff --git a/nixos/tests/ferretdb.nix b/nixos/tests/ferretdb.nix new file mode 100644 index 000000000000..9ad7397ade80 --- /dev/null +++ b/nixos/tests/ferretdb.nix @@ -0,0 +1,64 @@ +{ system ? builtins.currentSystem +, pkgs ? import ../.. { inherit system; } +, ... +}: +let + lib = pkgs.lib; + testScript = '' + machine.start() + machine.wait_for_unit("ferretdb.service") + machine.wait_for_open_port(27017) + machine.succeed("mongosh --eval 'use myNewDatabase;' --eval 'db.myCollection.insertOne( { x: 1 } );'") + ''; +in +with import ../lib/testing-python.nix { inherit system; }; +{ + + postgresql = makeTest + { + inherit testScript; + name = "ferretdb-postgresql"; + meta.maintainers = with lib.maintainers; [ julienmalka ]; + + nodes.machine = + { pkgs, ... }: + { + services.ferretdb = { + enable = true; + settings.FERRETDB_HANDLER = "pg"; + settings.FERRETDB_POSTGRESQL_URL = "postgres://ferretdb@localhost/ferretdb?host=/run/postgresql"; + }; + + systemd.services.ferretdb.serviceConfig = { + Requires = "postgresql.service"; + After = "postgresql.service"; + }; + + services.postgresql = { + enable = true; + ensureDatabases = [ "ferretdb" ]; + ensureUsers = [{ + name = "ferretdb"; + ensurePermissions."DATABASE ferretdb" = "ALL PRIVILEGES"; + }]; + }; + + environment.systemPackages = with pkgs; [ mongosh ]; + }; + }; + + sqlite = makeTest + { + inherit testScript; + name = "ferretdb-sqlite"; + meta.maintainers = with lib.maintainers; [ julienmalka ]; + + nodes.machine = + { pkgs, ... }: + { + services.ferretdb.enable = true; + + environment.systemPackages = with pkgs; [ mongosh ]; + }; + }; +} diff --git a/pkgs/servers/nosql/ferretdb/default.nix b/pkgs/servers/nosql/ferretdb/default.nix index 0fba93fb5b56..c59678418c31 100644 --- a/pkgs/servers/nosql/ferretdb/default.nix +++ b/pkgs/servers/nosql/ferretdb/default.nix @@ -1,6 +1,7 @@ { lib , buildGo121Module , fetchFromGitHub +, nixosTests }: buildGo121Module rec { @@ -34,6 +35,8 @@ buildGo121Module rec { $out/bin/ferretdb --version | grep ${version} ''; + passthru.tests = nixosTests.ferretdb; + meta = with lib; { description = "A truly Open Source MongoDB alternative"; homepage = "https://www.ferretdb.io/";