From 719e06be2b97aded9023f40c505b8a291b034847 Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Thu, 21 Apr 2022 02:08:02 +0100 Subject: [PATCH] make vmTestLocal and vmTestRemote This creates and uses a function named mkNixinateTest which takes a buildOn argument. This expects to be either "local" or "remote". This means we can make a test for both use cases of Nixinate. One where we build on the remote machine, and one where we build locally and push to the remote machine. These tests are then added to the top level of the tests folder and are imported by the flake.nix --- tests/default.nix | 3 +- tests/vmTest/default.nix | 89 +++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/tests/default.nix b/tests/default.nix index 93de21b..0826e0e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,5 @@ { pkgs, makeTest, inputs }: { - vmTest = import ./vmTest { inherit pkgs makeTest inputs; }; + vmTestLocal = (import ./vmTest { inherit pkgs makeTest inputs; }).local; + vmTestRemote = (import ./vmTest { inherit pkgs makeTest inputs; }).remote; } diff --git a/tests/vmTest/default.nix b/tests/vmTest/default.nix index 5c86485..cbbcedb 100644 --- a/tests/vmTest/default.nix +++ b/tests/vmTest/default.nix @@ -54,51 +54,56 @@ let }; deployScript = inputs.self.nixinate.${pkgs.hostPlatform.system} (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }); exampleSystem = (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }).nixosConfigurations.nixinatee.config.system.build.toplevel; -in -makeTest { - nodes = { - nixinatee = { ... }: { - imports = [ - ./nixinateeBase.nix - ]; - virtualisation = { - writableStore = true; - }; - }; - nixinator = { ... }: { - virtualisation = { - additionalPaths = [ - (allDrvOutputs exampleSystem) + mkNixinateTest = buildOn: makeTest { + nodes = { + nixinatee = { ... }: { + imports = [ + ./nixinateeBase.nix ]; + virtualisation = { + writableStore = true; + }; }; - nix = { - extraOptions = - let empty_registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; in - '' - experimental-features = nix-command flakes - flake-registry = ${empty_registry} - ''; - registry.nixpkgs.flake = inputs.nixpkgs; + nixinator = { ... }: { + virtualisation = { + additionalPaths = [ + (allDrvOutputs exampleSystem) + ] + ++ pkgs.lib.optional (buildOn == "remote") exampleFlake; + }; + nix = { + extraOptions = + let empty_registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; in + '' + experimental-features = nix-command flakes + flake-registry = ${empty_registry} + ''; + registry.nixpkgs.flake = inputs.nixpkgs; + }; }; }; + testScript = + '' + start_all() + nixinatee.wait_for_unit("sshd.service") + nixinator.wait_for_unit("multi-user.target") + nixinator.succeed("mkdir ~/.ssh/") + nixinator.succeed("ssh-keyscan -H nixinatee >> ~/.ssh/known_hosts") + nixinator.succeed("exec ${deployScript.nixinate.nixinatee.program} >&2") + nixinatee.wait_for_unit("nginx.service") + nixinatee.wait_for_open_port("80") + with subtest("Check that Nginx webserver can be reached by deployer after deployment"): + assert "Welcome to nginx!" in nixinator.succeed( + "curl -sSf http:/nixinatee/ | grep title" + ) + with subtest("Check that Nginx webserver can be reached by deployee after deployment"): + assert "Welcome to nginx!" in nixinatee.succeed( + "curl -sSf http:/127.0.0.1/ | grep title" + ) + ''; }; - testScript = - '' - start_all() - nixinatee.wait_for_unit("sshd.service") - nixinator.wait_for_unit("multi-user.target") - nixinator.succeed("mkdir ~/.ssh/") - nixinator.succeed("ssh-keyscan -H nixinatee >> ~/.ssh/known_hosts") - nixinator.succeed("exec ${deployScript.nixinate.nixinatee.program} >&2") - nixinatee.wait_for_unit("nginx.service") - nixinatee.wait_for_open_port("80") - with subtest("Check that Nginx webserver can be reached by deployer after deployment"): - assert "Welcome to nginx!" in nixinator.succeed( - "curl -sSf http:/nixinatee/ | grep title" - ) - with subtest("Check that Nginx webserver can be reached by deployee after deployment"): - assert "Welcome to nginx!" in nixinatee.succeed( - "curl -sSf http:/127.0.0.1/ | grep title" - ) - ''; +in +{ + local = (mkNixinateTest "local"); + remote = (mkNixinateTest "remote"); }