aboutsummaryrefslogtreecommitdiffstats
path: root/tests/default.nix
blob: 686b130ac2b098fd14a01aba8a9c8cedd5d20a41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# NixOS VM tests for populate: one test per source type, one for features
# spanning sources, one for edge cases of flakes, one for staying inside the
# target directory, and one for writeDeploy's arguments to nixos-rebuild.
# Build all with nix-build tests, or one with, e.g., nix-build tests -A flake.
# The exhaustive tests add the combinations of options that no code path
# tells apart from the ones the others cover; build them with nix-build tests
# -A exhaustive, or one with, e.g., nix-build tests -A exhaustive.flake.  jq runs populate's jq programs for flakes
# without VMs.
{ pkgs ? import ../pkgs {} }:

let
  # HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically,
  # and its parent.  fixtures.sh fails if HEAD differs, naming the actual one.
  gitHead = "e42d44ef9cdb76ba5a84dff4c89c38222703bf0c";
  gitFirst = "8d47013fa0888948cf0ffcc4e3c69a7b5f180562";

  # rsync versions the scenarios depending on rsync's version run with.
  # callPackage adds override and overrideDerivation, which aren't versions.
  rsyncs = pkgs.lib.filterAttrs
    (_: pkgs.lib.isDerivation)
    (pkgs.callPackage ./rsync.nix {});

  # The scenarios, with populate using rsync.
  scenariosWith = rsync: import ./scenarios.nix {
    inherit (pkgs) lib;
    krops = import ../lib;
    populate = pkgs.populate.override { inherit rsync; };
    inherit (pkgs.krops) writeDeploy;
    url = "http://deployer:8000";
    gitUrl = "git://deployer/gitsrc.git";
    remoteHost = "target";
    agePath = "${pkgs.age}/bin/age";
    inherit gitHead gitFirst;
    rsyncVersion = rsync.version;
  };
  scenarios = scenariosWith pkgs.rsync;
  flakeJq = import ../pkgs/populate/flake-jq.nix;
  # VM tests of those of the groups of scenarios that are, or aren't,
  # exhaustive, named after the groups with prefix in front.
  testsOf = exhaustive: prefix: pkgs.lib.mapAttrs
    (name: scenarios: import ./vm.nix {
      inherit pkgs gitHead scenarios;
      name = prefix + name;
    })
    (pkgs.lib.filterAttrs (_: scenarios: scenarios != [])
      (builtins.mapAttrs
        (_: builtins.filter (scenario: scenario.exhaustive == exhaustive))
        scenarios));
in
  testsOf false ""
  # An attribute set without recurseForDerivations, so nix-build tests
  # doesn't build them.
  // { exhaustive = testsOf true "exhaustive-"; }
  // pkgs.lib.mapAttrs'
    (version: rsync: {
      name = "rsync-${builtins.replaceStrings [ "." ] [ "-" ] version}";
      value = import ./vm.nix {
        inherit pkgs gitHead rsync;
        name = "rsync-${version}";
        scenarios = builtins.filter
          (scenario: pkgs.lib.hasInfix "insecureLinks" scenario.name)
          (scenariosWith rsync).file;
      };
    })
    rsyncs
  // {
    # Lock files in the shapes different versions of Nix write.
    jq = pkgs.runCommand "krops-jq" {
      nativeBuildInputs = [ pkgs.jq pkgs.nix ];
    } ''
      sh ${./jq.sh} ${pkgs.linkFarm "krops-flake-jq" (map
        (name: { name = "${name}.jq"; path = pkgs.writeText "${name}.jq" flakeJq.${name}; })
        [ "selected" "selfIsRemote" "selfLocked" ]
        ++ [{
          name = "metadataSubdir.nix";
          path = pkgs.writeText "metadataSubdir.nix" flakeJq.metadataSubdir;
        }])}
      touch $out
    '';
  }