git.iko.soy/typeable/nixpkgs
on master help sign in
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

commit97adb03a9e542c9966712b9d88c84b4ed6d1a6b6 authoraszlig <aszlig@nix.build> dateSun 29 Apr 2018, 15:28 (9 years ago) parent0e1147d
1 file changed+22−25
nixos/tests/predictable-interface-names.nix+22−25
nixos/tests/predictable-interface-names.nix+22−25
@@ -1,27 +1,24 @@
1−{ system ? builtins.currentSystem
2−, pkgs ? import ../.. { inherit system; }
3−}:
4−with import ../lib/testing.nix { inherit system; };
5−let boolToString = x: if x then "yes" else "no"; in
6−let testWhenSetTo = predictable: withNetworkd:
7−makeTest {
8− name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}";
9− meta = {};
1+{ system ? builtins.currentSystem }:
102
11− machine = { config, pkgs, ... }: {
12− networking.usePredictableInterfaceNames = pkgs.stdenv.lib.mkForce predictable;
13− networking.useNetworkd = withNetworkd;
14− networking.dhcpcd.enable = !withNetworkd;
15− };
3+let
4+ inherit (import ../lib/testing.nix { inherit system; }) makeTest pkgs;
5+in pkgs.lib.listToAttrs (pkgs.lib.crossLists (predictable: withNetworkd: {
6+ name = pkgs.lib.optionalString (!predictable) "un" + "predictable"
7+ + pkgs.lib.optionalString withNetworkd "Networkd";
8+ value = makeTest {
9+ name = "${if predictable then "" else "un"}predictableInterfaceNames${if withNetworkd then "-with-networkd" else ""}";
10+ meta = {};
11+
12+ machine = { config, lib, ... }: {
13+ networking.usePredictableInterfaceNames = lib.mkForce predictable;
14+ networking.useNetworkd = withNetworkd;
15+ networking.dhcpcd.enable = !withNetworkd;
16+ };
1617
17− testScript = ''
18− print $machine->succeed("ip link");
19− $machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}");
20− $machine->fail("ip link show ${if predictable then "eth0" else "ens3"}");
21− '';
22−}; in
23−with pkgs.stdenv.lib.lists;
24−with pkgs.stdenv.lib.attrsets;
25−listToAttrs (map (drv: nameValuePair drv.name drv) (
26−crossLists testWhenSetTo [[true false] [true false]]
27−))
18+ testScript = ''
19+ print $machine->succeed("ip link");
20+ $machine->succeed("ip link show ${if predictable then "ens3" else "eth0"}");
21+ $machine->fail("ip link show ${if predictable then "eth0" else "ens3"}");
22+ '';
23+ };
24+}) [[true false] [true false]])