From 97adb03a9e542c9966712b9d88c84b4ed6d1a6b6 Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 29 Apr 2018 15:28:33 +0200 Subject: [PATCH] nixos/tests/predictable-interface-names: Refactor The Nix expression here is really hard to read with multiple (and unnecessarily) nested lets and it also generates attribute names based on the derivation generated by makeTest, which will result in these attribute names: * vm-test-run-predictableInterfaceNames * vm-test-run-predictableInterfaceNames-with-networkd * vm-test-run-unpredictableInterfaceNames * vm-test-run-unpredictableInterfaceNames-with-networkd With the refactor the attribute names are now: * predictable * predictableNetworkd * unpredictable * unpredictableNetworkd So now the code is even shorter and IMHO slightly more readable. Signed-off-by: aszlig Cc: @symphorien, @fpletz, @adisbladis --- nixos/tests/predictable-interface-names.nix | 47 ++++++++++----------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/nixos/tests/predictable-interface-names.nix b/nixos/tests/predictable-interface-names.nix index b4c2039923cf..0b431034a7a9 100644 --- a/nixos/tests/predictable-interface-names.nix +++ b/nixos/tests/predictable-interface-names.nix @@ -1,27 +1,24 @@ -{ system ? builtins.currentSystem -, pkgs ? import ../.. { inherit system; } -}: -with import ../lib/testing.nix { inherit system; }; -let boolToString = x: if x then "yes" else "no"; in -let testWhenSetTo = predictable: withNetworkd: -makeTest { - name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}"; - meta = {}; +{ system ? builtins.currentSystem }: - machine = { config, pkgs, ... }: { - networking.usePredictableInterfaceNames = pkgs.stdenv.lib.mkForce predictable; - networking.useNetworkd = withNetworkd; - networking.dhcpcd.enable = !withNetworkd; +let + inherit (import ../lib/testing.nix { inherit system; }) makeTest pkgs; +in pkgs.lib.listToAttrs (pkgs.lib.crossLists (predictable: withNetworkd: { + name = pkgs.lib.optionalString (!predictable) "un" + "predictable" + + pkgs.lib.optionalString withNetworkd "Networkd"; + value = makeTest { + name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}"; + meta = {}; + + machine = { config, lib, ... }: { + networking.usePredictableInterfaceNames = lib.mkForce predictable; + networking.useNetworkd = withNetworkd; + networking.dhcpcd.enable = !withNetworkd; + }; + + testScript = '' + print $machine->succeed("ip link"); + $machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}"); + $machine->fail("ip link show ${if predictable then "eth0" else "ens3"}"); + ''; }; - - testScript = '' - print $machine->succeed("ip link"); - $machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}"); - $machine->fail("ip link show ${if predictable then "eth0" else "ens3"}"); - ''; -}; in -with pkgs.stdenv.lib.lists; -with pkgs.stdenv.lib.attrsets; -listToAttrs (map (drv: nameValuePair drv.name drv) ( -crossLists testWhenSetTo [[true false] [true false]] -)) +}) [[true false] [true false]])