diff options
author | Artturin <Artturin@artturin.com> | 2024-05-30 18:09:46 +0300 |
---|---|---|
committer | Artturin <Artturin@artturin.com> | 2024-05-30 19:11:27 +0300 |
commit | e124b02edd3f2a7ce8149e5b9cbdc577234eafaf (patch) | |
tree | ef0da47040e1f60972f34f4a5cbf852ed349cf67 /nixos/tests | |
parent | 104e6908c1b294ee2dade905915eca924a7121bd (diff) |
nixosTests.nix-misc: Split from `nixosTests.misc`
Bit weird to have nix tests in misc Add `artturin` to maintainers
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/nix/misc.nix | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a2408a43ecc92..5c0aea1bb9394 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -643,6 +643,7 @@ in { nitter = handleTest ./nitter.nix {}; nix-config = handleTest ./nix-config.nix {}; nix-ld = handleTest ./nix-ld.nix {}; + nix-misc = handleTest ./nix/misc.nix {}; nix-serve = handleTest ./nix-serve.nix {}; nix-serve-ssh = handleTest ./nix-serve-ssh.nix {}; nixops = handleTest ./nixops/default.nix {}; diff --git a/nixos/tests/nix/misc.nix b/nixos/tests/nix/misc.nix new file mode 100644 index 0000000000000..6a22ffe0d901f --- /dev/null +++ b/nixos/tests/nix/misc.nix @@ -0,0 +1,64 @@ +# Miscellaneous small tests that don't warrant their own VM run. +{ pkgs, ... }: + +let + inherit (pkgs) lib; + tests = { + default = testsForPackage { nixPackage = pkgs.nix; }; + lix = testsForPackage { nixPackage = pkgs.lix; }; + }; + + testsForPackage = args: lib.recurseIntoAttrs { + # If the attribute is not named 'test' + # You will break all the universe on the release-*.nix side of things. + # `discoverTests` relies on `test` existence to perform a `callTest`. + test = testMiscFeatures args; + passthru.override = args': testsForPackage (args // args'); + }; + + testMiscFeatures = { nixPackage, ... }: pkgs.testers.nixosTest ( + let + foo = pkgs.writeText "foo" "Hello World"; + in { + name = "${nixPackage.pname}-misc"; + meta.maintainers = with lib.maintainers; [ raitobezarius artturin ]; + + nodes.machine = + { lib, ... }: + { + system.extraDependencies = [ foo ]; + + nix.package = nixPackage; + }; + + testScript = + '' + import json + + def get_path_info(path): + result = machine.succeed(f"nix --option experimental-features nix-command path-info --json {path}") + parsed = json.loads(result) + return parsed + + with subtest("nix-db"): + out = "${foo}" + info = get_path_info(out) + print(info) + + pathinfo = info[0] if isinstance(info, list) else info[out] + + if ( + pathinfo["narHash"] + != "sha256-BdMdnb/0eWy3EddjE83rdgzWWpQjfWPAj3zDIFMD3Ck=" + ): + raise Exception("narHash not set") + + if pathinfo["narSize"] != 128: + raise Exception("narSize not set") + + with subtest("nix-db"): + machine.succeed("nix-store -qR /run/current-system | grep nixos-") + ''; + }); + in + tests |