Skip to content

Commit

Permalink
add nix support for test/missing_unionfs_mergerfs closes #182
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Dec 13, 2024
1 parent d8aee09 commit 4273d25
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions test/missing_unionfs_mergerfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,46 @@ cleanup() {

trap 'cleanup' EXIT

run_regular() {
new_bin_dir="$(mktemp -d)"
mkdir "$new_bin_dir/usr"
# -s makes symlinks
cp -rs /usr/bin "$new_bin_dir/usr/bin"

# Delete mergerfs and unionfs and set the new PATH to the temporary directory
rm -f "$new_bin_dir/usr/bin/mergerfs" 2>/dev/null
rm -f "$new_bin_dir/usr/bin/unionfs" 2>/dev/null

echo hi >expected
PATH="$new_bin_dir/usr/bin" "$TRY" -y "echo hi" >target 2>/dev/null || exit 1
diff -q expected target || exit 2
}

run_nix() {
cat > shell.nix <<'EOF'
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
attr
util-linux
];
}
EOF

echo hi >expected
# Run the command in a nix-shell with only the specified packages
nix-shell --pure shell.nix --run "\"$TRY\" -y \"echo hi\"" >target 2>/dev/null || exit 3
diff -q expected target || exit 4
}

# particularly important that we run in mktemp: in some test machines,
# the cwd is mounted, hence inaccessable.
try_workspace="$(mktemp -d)"
cd "$try_workspace" || exit 9

new_bin_dir="$(mktemp -d)"
mkdir "$new_bin_dir/usr"
# -s makes symlinks
cp -rs /usr/bin "$new_bin_dir/usr/bin"

# Delete mergerfs and unionfs and set the new PATH to the temporary directory
rm -f "$new_bin_dir/usr/bin/mergerfs" 2>/dev/null
rm -f "$new_bin_dir/usr/bin/unionfs" 2>/dev/null

echo hi >expected
PATH="$new_bin_dir/usr/bin" "$TRY" -y "echo hi" >target 2>/dev/null || exit 1
diff -q expected target || exit 2
if [ -e /etc/NIXOS ]
then
run_nix
else
run_regular
fi

0 comments on commit 4273d25

Please sign in to comment.