Add vmTest for Nixinate #16

Merged
MatthewCroughan merged 4 commits from mc/tests into master 2022-04-24 23:52:18 +00:00
2 changed files with 49 additions and 43 deletions
Showing only changes of commit 719e06be2b - Show all commits

View file

@ -1,4 +1,5 @@
{ pkgs, makeTest, inputs }: { 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;
} }

View file

@ -54,51 +54,56 @@ let
}; };
deployScript = inputs.self.nixinate.${pkgs.hostPlatform.system} (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }); deployScript = inputs.self.nixinate.${pkgs.hostPlatform.system} (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; });
exampleSystem = (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }).nixosConfigurations.nixinatee.config.system.build.toplevel; exampleSystem = (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }).nixosConfigurations.nixinatee.config.system.build.toplevel;
in mkNixinateTest = buildOn: makeTest {
makeTest { nodes = {
nodes = { nixinatee = { ... }: {
nixinatee = { ... }: { imports = [
imports = [ ./nixinateeBase.nix
./nixinateeBase.nix
];
virtualisation = {
writableStore = true;
};
};
nixinator = { ... }: {
virtualisation = {
additionalPaths = [
(allDrvOutputs exampleSystem)
]; ];
virtualisation = {
writableStore = true;
};
}; };
nix = { nixinator = { ... }: {
extraOptions = virtualisation = {
let empty_registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; in additionalPaths = [
'' (allDrvOutputs exampleSystem)
experimental-features = nix-command flakes ]
flake-registry = ${empty_registry} ++ pkgs.lib.optional (buildOn == "remote") exampleFlake;
''; };
registry.nixpkgs.flake = inputs.nixpkgs; 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 "<title>Welcome to nginx!</title>" in nixinator.succeed(
"curl -sSf http:/nixinatee/ | grep title"
)
with subtest("Check that Nginx webserver can be reached by deployee after deployment"):
assert "<title>Welcome to nginx!</title>" in nixinatee.succeed(
"curl -sSf http:/127.0.0.1/ | grep title"
)
'';
}; };
testScript = in
'' {
start_all() local = (mkNixinateTest "local");
nixinatee.wait_for_unit("sshd.service") remote = (mkNixinateTest "remote");
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 "<title>Welcome to nginx!</title>" in nixinator.succeed(
"curl -sSf http:/nixinatee/ | grep title"
)
with subtest("Check that Nginx webserver can be reached by deployee after deployment"):
assert "<title>Welcome to nginx!</title>" in nixinatee.succeed(
"curl -sSf http:/127.0.0.1/ | grep title"
)
'';
} }