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 <aszlig@nix.build> Cc: @symphorien, @fpletz, @adisbladis
This commit is contained in:
parent
0e1147d137
commit
97adb03a9e
|
@ -1,15 +1,16 @@
|
||||||
{ system ? builtins.currentSystem
|
{ system ? builtins.currentSystem }:
|
||||||
, pkgs ? import ../.. { inherit system; }
|
|
||||||
}:
|
let
|
||||||
with import ../lib/testing.nix { inherit system; };
|
inherit (import ../lib/testing.nix { inherit system; }) makeTest pkgs;
|
||||||
let boolToString = x: if x then "yes" else "no"; in
|
in pkgs.lib.listToAttrs (pkgs.lib.crossLists (predictable: withNetworkd: {
|
||||||
let testWhenSetTo = predictable: withNetworkd:
|
name = pkgs.lib.optionalString (!predictable) "un" + "predictable"
|
||||||
makeTest {
|
+ pkgs.lib.optionalString withNetworkd "Networkd";
|
||||||
|
value = makeTest {
|
||||||
name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}";
|
name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}";
|
||||||
meta = {};
|
meta = {};
|
||||||
|
|
||||||
machine = { config, pkgs, ... }: {
|
machine = { config, lib, ... }: {
|
||||||
networking.usePredictableInterfaceNames = pkgs.stdenv.lib.mkForce predictable;
|
networking.usePredictableInterfaceNames = lib.mkForce predictable;
|
||||||
networking.useNetworkd = withNetworkd;
|
networking.useNetworkd = withNetworkd;
|
||||||
networking.dhcpcd.enable = !withNetworkd;
|
networking.dhcpcd.enable = !withNetworkd;
|
||||||
};
|
};
|
||||||
|
@ -19,9 +20,5 @@ makeTest {
|
||||||
$machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}");
|
$machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}");
|
||||||
$machine->fail("ip link show ${if predictable then "eth0" else "ens3"}");
|
$machine->fail("ip link show ${if predictable then "eth0" else "ens3"}");
|
||||||
'';
|
'';
|
||||||
}; in
|
};
|
||||||
with pkgs.stdenv.lib.lists;
|
}) [[true false] [true false]])
|
||||||
with pkgs.stdenv.lib.attrsets;
|
|
||||||
listToAttrs (map (drv: nameValuePair drv.name drv) (
|
|
||||||
crossLists testWhenSetTo [[true false] [true false]]
|
|
||||||
))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user