From f96b31a8a9fc0d8c4d62a29ca23a7f152a33c8b6 Mon Sep 17 00:00:00 2001 From: b12f Date: Fri, 23 Aug 2024 22:50:22 +0200 Subject: [PATCH] tests: add working test for website --- flake.nix | 11 +++++++++++ modules/core/nix.nix | 4 +++- tests/website.nix | 23 ++++++++++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index b5473e1..063589c 100644 --- a/flake.nix +++ b/flake.nix @@ -65,6 +65,7 @@ system, pkgs, config, + lib, ... }: { @@ -77,6 +78,16 @@ unstable = import inputs.unstable { inherit system; }; master = import inputs.master { inherit system; }; }; + + packages = let + nixos-lib = import (inputs.nixpkgs + "/nixos/lib") { }; + in builtins.listToAttrs ( + map (x: { + name = "test-${lib.strings.removeSuffix ".nix" x}"; + value = nixos-lib.runTest (import (./tests + "/${x}") { inherit self; inherit pkgs; inherit lib; inherit config; }); + }) (builtins.attrNames (builtins.readDir ./tests)) + ); + devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ deploy-rs diff --git a/modules/core/nix.nix b/modules/core/nix.nix index 338cdd1..936be64 100644 --- a/modules/core/nix.nix +++ b/modules/core/nix.nix @@ -6,7 +6,9 @@ ... }: { - nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ ]; + nixpkgs.config = lib.mkDefault { + allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ ]; + }; nix = { # Use default version alias for nix package diff --git a/tests/website.nix b/tests/website.nix index dc33aff..10e96a5 100644 --- a/tests/website.nix +++ b/tests/website.nix @@ -8,17 +8,26 @@ { name = "website"; - nodes.nachtigall-test = self.nixosConfigurations.nachtigall-test; - - node.specialArgs = self.outputs.nixosConfigurations.nachtigall._module.specialArgs; hostPkgs = pkgs; + node.pkgs = pkgs; + node.specialArgs = self.outputs.nixosConfigurations.nachtigall._module.specialArgs; + + nodes.nachtigall-test = { + imports = [ + self.nixosModules.home-manager + self.nixosModules.core + self.nixosModules.nginx + self.nixosModules.nginx-website + ]; + }; + enableOCR = true; testScript = '' - machine.wait_for_unit("system.slice") - machine.succeed("ping 127.0.0.1 -c 2") - machine.wait_for_unit("nginx.service") - machine.succeed("curl -H 'Host:pub.solar' http://127.0.0.1/") + nachtigall_test.wait_for_unit("system.slice") + nachtigall_test.succeed("ping 127.0.0.1 -c 2") + nachtigall_test.wait_for_unit("nginx.service") + nachtigall_test.succeed("curl -H 'Host:pub.solar' http://127.0.0.1/") ''; }