nixos/tests/swap-file-btrfs: init

This commit is contained in:
oxalica 2022-10-04 11:08:46 +08:00
parent 87a0c9490d
commit eecb6c2bd8
2 changed files with 47 additions and 0 deletions

View file

@ -619,6 +619,7 @@ in {
strongswan-swanctl = handleTest ./strongswan-swanctl.nix {};
stunnel = handleTest ./stunnel.nix {};
sudo = handleTest ./sudo.nix {};
swap-file-btrfs = handleTest ./swap-file-btrfs.nix {};
swap-partition = handleTest ./swap-partition.nix {};
sway = handleTest ./sway.nix {};
switchTest = handleTest ./switch-test.nix {};

View file

@ -0,0 +1,46 @@
import ./make-test-python.nix ({ lib, ... }:
{
name = "swap-file-btrfs";
meta.maintainers = with lib.maintainers; [ oxalica ];
nodes.machine =
{ pkgs, ... }:
{
virtualisation.useDefaultFilesystems = false;
virtualisation.bootDevice = "/dev/vda";
boot.initrd.postDeviceCommands = ''
${pkgs.btrfs-progs}/bin/mkfs.btrfs --label root /dev/vda
'';
virtualisation.fileSystems = {
"/" = {
device = "/dev/disk/by-label/root";
fsType = "btrfs";
};
};
swapDevices = [
{
device = "/var/swapfile";
size = 1; # 1MiB.
}
];
};
testScript = ''
machine.wait_for_unit('var-swapfile.swap')
machine.succeed("stat --file-system --format=%T /var/swapfile | grep btrfs")
# First run. Auto creation.
machine.succeed("swapon --show | grep /var/swapfile")
machine.shutdown()
machine.start()
# Second run. Use it as-is.
machine.wait_for_unit('var-swapfile.swap')
machine.succeed("swapon --show | grep /var/swapfile")
'';
})