diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/default.nix | 3 | ||||
| -rw-r--r-- | tests/scenarios.nix | 44 |
2 files changed, 34 insertions, 13 deletions
diff --git a/tests/default.nix b/tests/default.nix index fa82e3a..08f95a6 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -70,7 +70,8 @@ let # Names of the scenarios of the smoke test, besides populate's. smokeNames = import (populateTests + "/smoke.nix") ++ [ - "deploy-local-buildTarget0-etcFlake0-flakefile" + "deploy-local-buildTarget0-etcFlake0-flakefile-targetString0" + "deploy-remote-buildTarget0-etcFlake0-flakenone-targetString1" "deploy-sudo-allocateTTY" ]; diff --git a/tests/scenarios.nix b/tests/scenarios.nix index e61d25b..0e90284 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -5,10 +5,17 @@ { targets, ... }@args: let - inherit (args) lib gitHead gitUrl; - inherit (lib) concatStringsSep optional optionalAttrs optionals optionalString; + inherit (args) lib gitHead gitUrl remoteHost; + inherit (lib) concatMap concatStringsSep optional optionalAttrs optionals optionalString; inherit (import ../pkgs/populate/tests/builder.nix (removeAttrs args [ "targets" ])) alt drawInputs matrix scenario targetKinds twice; + + # The target of a kind for a path, as a string, which can't say to use + # sudo. + targetString = targetKind: path: { + local = path; + remote = "root@${remoteHost}${path}"; + }.${targetKind}; in { @@ -16,11 +23,13 @@ in # writeDeploy's arguments to nixos-rebuild, which a stand-in records. # flake is what gets deployed: nothing, or a flake from a file, git, or # flake source, or one whose inputs get drawn from a source, by rewriting - # its lock file or through a generated flake. + # its lock file or through a generated flake. targetString gives the + # target as a string, which populate and populate shell get as it is. deploy = matrix "deploy" { flake = [ "none" "file" "git" "source" "rewrite" "generated" ]; etcFlake = [ false true ]; buildTarget = [ false true ]; + targetString = [ false true ]; } (flags: ctx: let target = targets.${ctx.targetKind} ctx.path; buildTarget = targets.local "${ctx.path}-build"; @@ -42,11 +51,15 @@ in if flags.flake == "generated" then ".populate/flakes/x" else "x"; scheme = if flags.flake == "git" then "git+file" else "path"; in - # The local target can't have another build target. - if flags.buildTarget && ctx.targetKind == "local" then null else { + # The local target can't have another build target, and a string can't + # say to use sudo. + if flags.buildTarget && ctx.targetKind == "local" || + flags.targetString && ctx.targetKind == "sudo" then null else { node = if flags.buildTarget then "deployer" else null; - # /etc/nixos/flake.nix only matters if no flake gets deployed. - exhaustive = flags.etcFlake && flags.flake != "none"; + # /etc/nixos/flake.nix only matters if no flake gets deployed, and + # how the target is given not for what gets deployed. + exhaustive = flags.etcFlake && flags.flake != "none" || + flags.targetString && flags.flake != "none"; # Each scenario creates or removes /etc/nixos/flake.nix. prepare = '' rm -f /tmp/nixos-rebuild.log @@ -74,6 +87,8 @@ in flake = if flags.flake == "none" then null else "x"; } // optionalAttrs flags.buildTarget { inherit buildTarget; + } // optionalAttrs flags.targetString { + target = targetString ctx.targetKind ctx.path; }; check = '' expect_eq user "$(sed -n 1p /tmp/nixos-rebuild.log)" 0 @@ -91,16 +106,21 @@ in # writeDeploy with allocateTTY: nixos-rebuild's output is a terminal on # the local target. ssh allocates one on remote targets only if its own - # input is a terminal, which the tests' isn't. - ++ map (targetKind: scenario { - name = "deploy-${targetKind}-allocateTTY"; + # input is a terminal, which the tests' isn't. Whether the target is + # local, populate shell decides, also for a target string. + ++ concatMap (targetKind: map (string: scenario (rec { + name = "deploy-${targetKind}${optionalString string "-string"}-allocateTTY"; inherit targetKind; prepare = '' rm -f /tmp/nixos-rebuild.log /etc/nixos/flake.nix ''; phases = [{ sources.x.file = "/fixtures/alt"; - deploy.allocateTTY = true; + deploy = { + allocateTTY = true; + } // optionalAttrs string { + target = targetString targetKind "/var/krops/${name}"; + }; check = '' expect_eq arguments "$(sed -n 3p /tmp/nixos-rebuild.log)" switch expect_eq terminal "$(sed -n 4p /tmp/nixos-rebuild.log)" ${ @@ -108,6 +128,6 @@ in } ''; }]; - }) targetKinds; + })) (if targetKind == "sudo" then [ false ] else [ false true ])) targetKinds; } |
