integration-tests: Add flakes test

This commit is contained in:
Zhaofeng Li 2021-12-05 01:14:12 -08:00
parent f849a757d2
commit 321d847563
6 changed files with 77 additions and 3 deletions

View file

@ -1,6 +1,7 @@
{ {
apply = import ./apply; apply = import ./apply;
apply-local = import ./apply-local; apply-local = import ./apply-local;
parallel = import ./parallel;
exec = import ./exec; exec = import ./exec;
flakes = import ./flakes;
parallel = import ./parallel;
} }

View file

@ -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")
'';
}

View file

@ -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; };
};
}

View file

@ -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;
};
}

View file

@ -0,0 +1 @@
"FIRST"

View file

@ -61,10 +61,12 @@ let
]; ];
}; };
environment.systemPackages = [ environment.systemPackages = with pkgs; [
git # for git flake tests
# HACK: copy stderr to both stdout and stderr # HACK: copy stderr to both stdout and stderr
# (the test framework only captures stdout, and only stderr appears on screen during the build) # (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) exec "$@" 2> >(tee /dev/stderr)
'') '')
]; ];