mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-11 23:50:05 +01:00
tests: add lib, autoimport tests
This commit is contained in:
parent
e4836108d5
commit
1ac0e76b15
7 changed files with 82 additions and 172 deletions
|
|
@ -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
|
makeDiskoTest {
|
||||||
makeTest' = args:
|
|
||||||
makeTest args {
|
|
||||||
inherit pkgs;
|
|
||||||
inherit (pkgs) system;
|
|
||||||
};
|
|
||||||
disko-config = import ../example/btrfs-subvolumes.nix;
|
disko-config = import ../example/btrfs-subvolumes.nix;
|
||||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
extraTestScript = ''
|
||||||
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
|
|
||||||
machine.succeed("test -e /mnt/test");
|
machine.succeed("test -e /mnt/test");
|
||||||
machine.succeed("btrfs subvolume list /mnt | grep -qs 'path test$'");
|
machine.succeed("btrfs subvolume list /mnt | grep -qs 'path test$'");
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
||||||
, pkgs ? (import <nixpkgs> {})
|
, pkgs ? (import <nixpkgs> {})
|
||||||
}@args:
|
}@args:
|
||||||
{
|
let
|
||||||
luks-lvm = import ./luks-lvm.nix args;
|
lib = pkgs.lib;
|
||||||
mdadm = import ./mdadm.nix args;
|
makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest; }).makeDiskoTest;
|
||||||
zfs = import ./zfs.nix args;
|
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
47
tests/lib.nix
Normal 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}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -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
|
makeDiskoTest {
|
||||||
makeTest' = args:
|
|
||||||
makeTest args {
|
|
||||||
inherit pkgs;
|
|
||||||
inherit (pkgs) system;
|
|
||||||
};
|
|
||||||
disko-config = import ../example/luks-lvm.nix;
|
disko-config = import ../example/luks-lvm.nix;
|
||||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
extraTestScript = ''
|
||||||
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
|
|
||||||
machine.succeed("cryptsetup isLuks /dev/vdb2");
|
machine.succeed("cryptsetup isLuks /dev/vdb2");
|
||||||
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
|
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -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
|
makeDiskoTest {
|
||||||
makeTest' = args:
|
|
||||||
makeTest args {
|
|
||||||
inherit pkgs;
|
|
||||||
inherit (pkgs) system;
|
|
||||||
};
|
|
||||||
disko-config = import ../example/lvm-raid.nix;
|
disko-config = import ../example/lvm-raid.nix;
|
||||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
extraTestScript = ''
|
||||||
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
|
|
||||||
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
|
machine.succeed("grep -qs '/mnt/home' /proc/mounts");
|
||||||
'';
|
'';
|
||||||
|
extraConfig = {
|
||||||
|
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
makeDiskoTest {
|
||||||
makeTest' = args:
|
|
||||||
makeTest args {
|
|
||||||
inherit pkgs;
|
|
||||||
inherit (pkgs) system;
|
|
||||||
};
|
|
||||||
disko-config = import ../example/mdadm.nix;
|
disko-config = import ../example/mdadm.nix;
|
||||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
extraTestScript = ''
|
||||||
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
|
|
||||||
machine.succeed("test -b /dev/md/raid1");
|
machine.succeed("test -b /dev/md/raid1");
|
||||||
machine.succeed("grep -qs '/mnt/raid' /proc/mounts");
|
machine.succeed("grep -qs '/mnt/raid' /proc/mounts");
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
|
|
@ -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
|
makeDiskoTest {
|
||||||
makeTest' = args:
|
|
||||||
makeTest args {
|
|
||||||
inherit pkgs;
|
|
||||||
inherit (pkgs) system;
|
|
||||||
};
|
|
||||||
disko-config = import ../example/zfs.nix;
|
disko-config = import ../example/zfs.nix;
|
||||||
tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config);
|
extraTestScript = ''
|
||||||
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
|
|
||||||
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");
|
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");
|
||||||
machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts");
|
machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts");
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue