nixos/overlayfs: add test

This commit is contained in:
Pascal Bach 2019-01-23 10:19:23 +01:00
parent dc80bf520e
commit a8307b9f39
2 changed files with 58 additions and 0 deletions

View File

@ -172,6 +172,7 @@ in
osquery = handleTest ./osquery.nix {};
osrm-backend = handleTest ./osrm-backend.nix {};
ostree = handleTest ./ostree.nix {};
overlayfs = handleTest ./overlayfs.nix {};
pam-oath-login = handleTest ./pam-oath-login.nix {};
pam-u2f = handleTest ./pam-u2f.nix {};
pantheon = handleTest ./pantheon.nix {};

57
nixos/tests/overlayfs.nix Normal file
View File

@ -0,0 +1,57 @@
import ./make-test.nix ({ pkgs, ... }: {
name = "overlayfs";
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ bachp ];
machine = { pkgs, ... }: {
virtualisation.emptyDiskImages = [ 512 ];
networking.hostId = "deadbeef";
environment.systemPackages = with pkgs; [ parted ];
};
testScript = ''
$machine->succeed("ls /dev");
$machine->succeed("mkdir -p /tmp/mnt");
# Test ext4 + overlayfs
$machine->succeed(
"mkfs.ext4 -F -L overlay-ext4 /dev/vdb",
"mount -t ext4 /dev/vdb /tmp/mnt",
"mkdir -p /tmp/mnt/upper /tmp/mnt/lower /tmp/mnt/work /tmp/mnt/merged",
# Setup some existing files
"echo 'Replace' > /tmp/mnt/lower/replace.txt",
"echo 'Append' > /tmp/mnt/lower/append.txt",
"echo 'Overwrite' > /tmp/mnt/lower/overwrite.txt",
"mount -t overlay overlay -o lowerdir=/tmp/mnt/lower,upperdir=/tmp/mnt/upper,workdir=/tmp/mnt/work /tmp/mnt/merged",
# Test new
"echo 'New' > /tmp/mnt/merged/new.txt",
"[[ \"\$(cat /tmp/mnt/merged/new.txt)\" == \"New\" ]]",
# Test replace
"[[ \"\$(cat /tmp/mnt/merged/replace.txt)\" == \"Replace\" ]]",
"echo 'Replaced' > /tmp/mnt/merged/replace-tmp.txt",
"mv /tmp/mnt/merged/replace-tmp.txt /tmp/mnt/merged/replace.txt",
"[[ \"\$(cat /tmp/mnt/merged/replace.txt)\" == \"Replaced\" ]]",
# Overwrite
"[[ \"\$(cat /tmp/mnt/merged/overwrite.txt)\" == \"Overwrite\" ]]",
"echo 'Overwritten' > /tmp/mnt/merged/overwrite.txt",
"[[ \"\$(cat /tmp/mnt/merged/overwrite.txt)\" == \"Overwritten\" ]]",
# Test append
"[[ \"\$(cat /tmp/mnt/merged/append.txt)\" == \"Append\" ]]",
"echo 'ed' >> /tmp/mnt/merged/append.txt",
#"cat /tmp/mnt/merged/append.txt && exit 1",
"[[ \"\$(cat /tmp/mnt/merged/append.txt)\" == \"Append\ned\" ]]",
"umount /tmp/mnt/merged",
"umount /tmp/mnt",
"udevadm settle"
);
'';
})