treefmt v2.4.1traversed 87 files emitted 63 files for processing formatted 63 files (3 changed) in 203ms M lib/zfs-storage/tests/eval-tests.nix M lib/zfs-storage/tests/flake-module.nix M lib/zfs-storage/tests/vm-runtime/service.nix diff --git a/lib/zfs-storage/tests/eval-tests.nix b/lib/zfs-storage/tests/eval-tests.nix index 2333693..88de88a 100644 --- a/lib/zfs-storage/tests/eval-tests.nix +++ b/lib/zfs-storage/tests/eval-tests.nix @@ -16,23 +16,25 @@ let # Used to evaluate raw inputs *through* the submodule types so that # defaults surface (owner, zfs, mode) exactly as a real consumer sees # them. - mountsType = lib.types.attrsOf (lib.types.submodule { - options = { - path = lib.mkOption { type = lib.types.str; }; - mode = lib.mkOption { - type = lib.types.str; - default = "0750"; - }; - owner = lib.mkOption { - type = zfsStorage.types.owner; - default = { }; - }; - zfs = lib.mkOption { - type = zfsStorage.types.zfs; - default = { }; + mountsType = lib.types.attrsOf ( + lib.types.submodule { + options = { + path = lib.mkOption { type = lib.types.str; }; + mode = lib.mkOption { + type = lib.types.str; + default = "0750"; + }; + owner = lib.mkOption { + type = zfsStorage.types.owner; + default = { }; + }; + zfs = lib.mkOption { + type = zfsStorage.types.zfs; + default = { }; + }; }; - }; - }); + } + ); evalMounts = raw: @@ -50,7 +52,9 @@ let # A single fully-defaulted mount, used by the defaults tests. defaultedMounts = evalMounts { - m = { path = "/x"; }; + m = { + path = "/x"; + }; }; in { @@ -166,7 +170,9 @@ in }; }; # zfs.enable defaults to false → this entry must be dropped. - drop = { path = "/srv/b"; }; + drop = { + path = "/srv/b"; + }; }); expected = { "srv-a" = { @@ -188,32 +194,38 @@ in # ── mkDiskoDatasets key convention ──────────────────────────────── testMkDiskoKey = { - expr = builtins.attrNames (zfsStorage.mkDiskoDatasets (evalMounts { - m = { - path = "/srv/a"; - zfs = { - enable = true; - pool = "pool1"; - dataset = "data/a"; + expr = builtins.attrNames ( + zfsStorage.mkDiskoDatasets (evalMounts { + m = { + path = "/srv/a"; + zfs = { + enable = true; + pool = "pool1"; + dataset = "data/a"; + }; }; - }; - })); + }) + ); expected = [ "pool1/data/a" ]; }; # Disabled mount does not leak into mkDiskoDatasets output. testMkDiskoFiltersDisabled = { - expr = builtins.attrNames (zfsStorage.mkDiskoDatasets (evalMounts { - keep = { - path = "/srv/a"; - zfs = { - enable = true; - pool = "p"; - dataset = "a"; + expr = builtins.attrNames ( + zfsStorage.mkDiskoDatasets (evalMounts { + keep = { + path = "/srv/a"; + zfs = { + enable = true; + pool = "p"; + dataset = "a"; + }; }; - }; - drop = { path = "/srv/b"; }; - })); + drop = { + path = "/srv/b"; + }; + }) + ); expected = [ "p/a" ]; }; @@ -324,7 +336,9 @@ in dataset = "a"; }; }; - drop = { path = "/srv/b"; }; + drop = { + path = "/srv/b"; + }; }); expected = [ "d /srv/a 0750 app app -" ]; }; @@ -345,7 +359,9 @@ in dataset = "a"; }; }; - off = { path = "/var/cache/app"; }; + off = { + path = "/var/cache/app"; + }; }); in builtins.sort (a: b: a.label < b.label) out; diff --git a/lib/zfs-storage/tests/flake-module.nix b/lib/zfs-storage/tests/flake-module.nix index 0130c40..3ef9e55 100644 --- a/lib/zfs-storage/tests/flake-module.nix +++ b/lib/zfs-storage/tests/flake-module.nix @@ -34,50 +34,49 @@ in nix-unit.tests.zfs-storage = import ./eval-tests.nix { inherit (pkgs) lib; }; # `nix flake check` coverage. - checks = - { - # Eval tests: force every assertion at Nix eval time. Mirrors the - # `eval-tests-import-flake` pattern in `tests/flake-module.nix`. - eval-tests-zfs-storage = - let - tests = import ./eval-tests.nix { inherit (pkgs) lib; }; - results = lib.mapAttrs ( - name: test: - let - pass = test.expr == test.expected; - in - if pass then - "pass" - else - throw "eval test '${name}' failed:\n expr: ${builtins.toJSON test.expr}\n expected: ${builtins.toJSON test.expected}" - ) tests; - summary = lib.concatStringsSep "\n" ( - lib.mapAttrsToList (name: status: " ${name}: ${status}") results - ); - in - pkgs.runCommand "eval-tests-zfs-storage" { inherit summary; } '' - echo "All zfs-storage eval tests passed:" - echo "$summary" - echo "" - echo "${toString (builtins.length (builtins.attrNames tests))} tests passed." - touch $out - ''; - } - # Test 2: build-only structural check that `mkDiskoDatasets` output - # is a shape disko-zfs accepts. Forces `system.build.diskoScript` to - # build; does NOT execute it. Linux-only because disko-zfs is Linux. - // lib.optionalAttrs pkgs.stdenv.isLinux { - zfs-storage-disko-build = - let - machine = inputs.nixpkgs.lib.nixosSystem { - inherit system; - modules = [ (import ./disko-build/machine.nix { inherit inputs; }) ]; - }; - in - pkgs.runCommand "zfs-storage-disko-build" { } '' - cp ${machine.config.system.build.diskoScript} $out - ''; - }; + checks = { + # Eval tests: force every assertion at Nix eval time. Mirrors the + # `eval-tests-import-flake` pattern in `tests/flake-module.nix`. + eval-tests-zfs-storage = + let + tests = import ./eval-tests.nix { inherit (pkgs) lib; }; + results = lib.mapAttrs ( + name: test: + let + pass = test.expr == test.expected; + in + if pass then + "pass" + else + throw "eval test '${name}' failed:\n expr: ${builtins.toJSON test.expr}\n expected: ${builtins.toJSON test.expected}" + ) tests; + summary = lib.concatStringsSep "\n" ( + lib.mapAttrsToList (name: status: " ${name}: ${status}") results + ); + in + pkgs.runCommand "eval-tests-zfs-storage" { inherit summary; } '' + echo "All zfs-storage eval tests passed:" + echo "$summary" + echo "" + echo "${toString (builtins.length (builtins.attrNames tests))} tests passed." + touch $out + ''; + } + # Test 2: build-only structural check that `mkDiskoDatasets` output + # is a shape disko-zfs accepts. Forces `system.build.diskoScript` to + # build; does NOT execute it. Linux-only because disko-zfs is Linux. + // lib.optionalAttrs pkgs.stdenv.isLinux { + zfs-storage-disko-build = + let + machine = inputs.nixpkgs.lib.nixosSystem { + inherit system; + modules = [ (import ./disko-build/machine.nix { inherit inputs; }) ]; + }; + in + pkgs.runCommand "zfs-storage-disko-build" { } '' + cp ${machine.config.system.build.diskoScript} $out + ''; + }; # Test 1: VM, runtime side, no disko. Linux-only via the # `optionalAttrs pkgs.stdenv.isLinux` gate inside `clan-nixos-test.nix`. diff --git a/lib/zfs-storage/tests/vm-runtime/service.nix b/lib/zfs-storage/tests/vm-runtime/service.nix index 2e0050b..b92399c 100644 --- a/lib/zfs-storage/tests/vm-runtime/service.nix +++ b/lib/zfs-storage/tests/vm-runtime/service.nix @@ -23,23 +23,25 @@ { options.mounts = lib.mkOption { default = { }; - type = lib.types.attrsOf (lib.types.submodule { - options = { - path = lib.mkOption { type = lib.types.str; }; - mode = lib.mkOption { - type = lib.types.str; - default = "0750"; + type = lib.types.attrsOf ( + lib.types.submodule { + options = { + path = lib.mkOption { type = lib.types.str; }; + mode = lib.mkOption { + type = lib.types.str; + default = "0750"; + }; + owner = lib.mkOption { + type = zfsStorage.types.owner; + default = { }; + }; + zfs = lib.mkOption { + type = zfsStorage.types.zfs; + default = { }; + }; }; - owner = lib.mkOption { - type = zfsStorage.types.owner; - default = { }; - }; - zfs = lib.mkOption { - type = zfsStorage.types.zfs; - default = { }; - }; - }; - }); + } + ); }; };