Unverified Commit 7c503a8a authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

Merge pull request #315927 from Artturin/movetestsnix1

nixosTests.nix-misc: split from nixosTests.misc
parents 8ef802dd 413707f4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ in rec {
        (onSystems ["x86_64-linux"] "nixos.tests.installer.swraid")
        (onSystems ["x86_64-linux"] "nixos.tests.installer.zfsroot")
        (onSystems ["x86_64-linux"] "nixos.tests.nixos-rebuild-specialisations")
        (onFullSupported "nixos.tests.nix-misc.default")
        (onFullSupported "nixos.tests.ipv6")
        (onFullSupported "nixos.tests.keymap.azerty")
        (onFullSupported "nixos.tests.keymap.colemak")
+1 −0
Original line number Diff line number Diff line
@@ -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 {};
+136 −185
Original line number Diff line number Diff line
# 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
import ./make-test-python.nix ({ lib, pkgs, ...} : let
  foo = pkgs.writeText "foo" "Hello World";
in {
  name = "misc";
    meta.maintainers = with lib.maintainers; [ raitobezarius ];
  meta.maintainers = with lib.maintainers; [ eelco ];

  nodes.machine =
    { lib, ... }:
@@ -57,37 +40,10 @@ let
      boot.kernel.sysctl."vm.swappiness" = 1;
      boot.kernelParams = [ "vsyscall=emulate" ];
      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("nixos-version"):
          machine.succeed("[ `nixos-version | wc -w` = 2 ]")

@@ -171,9 +127,6 @@ let
      with subtest("shell-vars"):
          machine.succeed('[ -n "$NIX_PATH" ]')

        with subtest("nix-db"):
            machine.succeed("nix-store -qR /run/current-system | grep nixos-")

      with subtest("Test sysctl"):
          machine.wait_for_unit("systemd-sysctl.service")
          assert "1" == machine.succeed("sysctl -ne vm.swappiness").strip()
@@ -183,6 +136,4 @@ let
      with subtest("Test boot parameters"):
          assert "vsyscall=emulate" in machine.succeed("cat /proc/cmdline")
    '';
  });
  in
  tests
})
+64 −0
Original line number Diff line number Diff line
# 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
+1 −1
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ let
    passthru = {
      inherit aws-sdk-cpp boehmgc;
      tests = {
        misc = nixosTests.misc.lix.passthru.override { nixPackage = self; };
        misc = nixosTests.nix-misc.lix.passthru.override { nixPackage = self; };
      };
    };

Loading