tests: add lib, autoimport tests

This commit is contained in:
lassulus 2022-08-25 23:12:49 +02:00
parent e4836108d5
commit 1ac0e76b15
7 changed files with 82 additions and 172 deletions

View File

@ -1,38 +1,9 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
{ pkgs ? (import <nixpkgs> {})
, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
makeDiskoTest {
disko-config = import ../example/btrfs-subvolumes.nix;
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = [ 512 ];
};
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
extraTestScript = ''
machine.succeed("test -e /mnt/test");
machine.succeed("btrfs subvolume list /mnt | grep -qs 'path test$'");
'';

View File

@ -1,8 +1,15 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
}@args:
{
luks-lvm = import ./luks-lvm.nix args;
mdadm = import ./mdadm.nix args;
zfs = import ./zfs.nix args;
}
let
lib = pkgs.lib;
makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest; }).makeDiskoTest;
allTestFilenames =
builtins.map (lib.removeSuffix ".nix") (
builtins.filter
(x: lib.hasSuffix ".nix" x && x != "default.nix" && x != "lib.nix")
(lib.attrNames (builtins.readDir ./.))
);
allTests = lib.genAttrs (allTestFilenames) (test: import (./. + "/${test}.nix") { inherit makeDiskoTest; });
in allTests

47
tests/lib.nix Normal file
View File

@ -0,0 +1,47 @@
{ pkgs ? (import <nixpkgs> {})
, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, ...
}:
{
makeDiskoTest = {
disko-config,
extraTestScript,
extraConfig ? {}
}:
let
lib = pkgs.lib;
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
num-disks = builtins.length (builtins.filter (x: builtins.match "vd." x == []) (lib.attrNames disko-config.content));
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = builtins.genList (_: 512) num-disks;
} // extraConfig;
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
${extraTestScript}
'';
};
}

View File

@ -1,38 +1,9 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
{ pkgs ? (import <nixpkgs> {})
, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
makeDiskoTest {
disko-config = import ../example/luks-lvm.nix;
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = [ 512 ];
};
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
extraTestScript = ''
machine.succeed("cryptsetup isLuks /dev/vdb2");
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
'';

View File

@ -1,39 +1,12 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
{ pkgs ? (import <nixpkgs> {})
, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
makeDiskoTest {
disko-config = import ../example/lvm-raid.nix;
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = [ 512 512 ];
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
};
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
extraTestScript = ''
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
'';
extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
};
}

View File

@ -1,38 +1,9 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
{ pkgs ? (import <nixpkgs> {})
, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
makeDiskoTest {
disko-config = import ../example/mdadm.nix;
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = [ 512 512 ];
};
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
extraTestScript = ''
machine.succeed("test -b /dev/md/raid1");
machine.succeed("grep -qs '/mnt/raid' /proc/mounts");
'';

View File

@ -1,40 +1,10 @@
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
, pkgs ? (import <nixpkgs> {})
{ pkgs ? (import <nixpkgs> {})
, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest
}:
let
makeTest' = args:
makeTest args {
inherit pkgs;
inherit (pkgs) system;
};
makeDiskoTest {
disko-config = import ../example/zfs.nix;
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config);
in makeTest' {
name = "disko";
nodes.machine =
{ config, pkgs, modulesPath, ... }:
{
imports = [
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/profiles/base.nix")
];
# speed-up eval
documentation.enable = false;
virtualisation.emptyDiskImages = [ 512 512 ];
};
testScript = ''
machine.succeed("echo 'secret' > /tmp/secret.key");
machine.succeed("${tsp-create}");
machine.succeed("${tsp-mount}");
machine.succeed("${tsp-mount}"); # verify that the command is idempotent
extraTestScript = ''
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");
machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts");
'';
}