From 321d84756348aceca915e4bbba2f3cd7d33f646d Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 5 Dec 2021 01:14:12 -0800 Subject: [PATCH] integration-tests: Add flakes test --- integration-tests/default.nix | 3 ++- integration-tests/flakes/default.nix | 34 ++++++++++++++++++++++++++++ integration-tests/flakes/flake.nix | 15 ++++++++++++ integration-tests/flakes/hive.nix | 21 +++++++++++++++++ integration-tests/flakes/probe.nix | 1 + integration-tests/tools.nix | 6 +++-- 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 integration-tests/flakes/default.nix create mode 100644 integration-tests/flakes/flake.nix create mode 100644 integration-tests/flakes/hive.nix create mode 100644 integration-tests/flakes/probe.nix diff --git a/integration-tests/default.nix b/integration-tests/default.nix index b0e6ece..b1b08a3 100644 --- a/integration-tests/default.nix +++ b/integration-tests/default.nix @@ -1,6 +1,7 @@ { apply = import ./apply; apply-local = import ./apply-local; - parallel = import ./parallel; exec = import ./exec; + flakes = import ./flakes; + parallel = import ./parallel; } diff --git a/integration-tests/flakes/default.nix b/integration-tests/flakes/default.nix new file mode 100644 index 0000000..d3865d6 --- /dev/null +++ b/integration-tests/flakes/default.nix @@ -0,0 +1,34 @@ +let + tools = import ../tools.nix { + targets = [ "alpha" ]; + }; +in tools.makeTest { + name = "colmena-flakes"; + + bundle = ./.; + + testScript = '' + import re + + with subtest("Lock flake dependencies"): + # --impure required for path:/nixpkgs which is a symlink to a store path + deployer.succeed("cd /tmp/bundle && nix --experimental-features \"nix-command flakes\" flake lock --impure") + + with subtest("Deploy with a plain flake without git"): + deployer.succeed("cd /tmp/bundle && ${tools.colmenaExec} apply --on @target") + alpha.succeed("grep FIRST /etc/deployment") + + with subtest("Deploy with a git flake"): + deployer.succeed("sed -i s/FIRST/SECOND/g /tmp/bundle/probe.nix") + + # don't put probe.nix in source control - should fail + deployer.succeed("cd /tmp/bundle && git init && git add flake.nix flake.lock hive.nix tools.nix") + logs = deployer.fail("cd /tmp/bundle && run-copy-stderr ${tools.colmenaExec} apply --on @target") + assert re.search(r"probe.nix.*No such file or directory", logs) + + # now it should succeed + deployer.succeed("cd /tmp/bundle && git add probe.nix") + deployer.succeed("cd /tmp/bundle && ${tools.colmenaExec} apply --on @target") + alpha.succeed("grep SECOND /etc/deployment") + ''; +} diff --git a/integration-tests/flakes/flake.nix b/integration-tests/flakes/flake.nix new file mode 100644 index 0000000..ef89a92 --- /dev/null +++ b/integration-tests/flakes/flake.nix @@ -0,0 +1,15 @@ +{ + description = "A simple deployment"; + + inputs = { + nixpkgs.url = "path:/nixpkgs"; + }; + + outputs = { self, nixpkgs }: let + pkgs = import nixpkgs { + system = "x86_64-linux"; + }; + in { + colmena = import ./hive.nix { inherit pkgs; }; + }; +} diff --git a/integration-tests/flakes/hive.nix b/integration-tests/flakes/hive.nix new file mode 100644 index 0000000..cff56a9 --- /dev/null +++ b/integration-tests/flakes/hive.nix @@ -0,0 +1,21 @@ +{ pkgs }: + +let + tools = import ./tools.nix { + insideVm = true; + targets = [ "alpha" ]; + }; +in { + meta = { + nixpkgs = tools.pkgs; + }; + + deployer = tools.getStandaloneConfigFor "deployer"; + alpha = { + imports = [ + (tools.getStandaloneConfigFor "alpha") + ]; + + environment.etc."deployment".text = import ./probe.nix; + }; +} diff --git a/integration-tests/flakes/probe.nix b/integration-tests/flakes/probe.nix new file mode 100644 index 0000000..ede6c7d --- /dev/null +++ b/integration-tests/flakes/probe.nix @@ -0,0 +1 @@ +"FIRST" diff --git a/integration-tests/tools.nix b/integration-tests/tools.nix index b61560f..3f43e1b 100644 --- a/integration-tests/tools.nix +++ b/integration-tests/tools.nix @@ -61,10 +61,12 @@ let ]; }; - environment.systemPackages = [ + environment.systemPackages = with pkgs; [ + git # for git flake tests + # HACK: copy stderr to both stdout and stderr # (the test framework only captures stdout, and only stderr appears on screen during the build) - (pkgs.writeShellScriptBin "run-copy-stderr" '' + (writeShellScriptBin "run-copy-stderr" '' exec "$@" 2> >(tee /dev/stderr) '') ];