Skip to content

Commit 9d7283f

Browse files
committed
Improve test_restore.sh path handling and mocks
Refines the way restore.sh is patched for test paths by replacing entire variable assignment lines for EFI_MOUNT_POINT and BACKUP_DIR, ensuring more robust path substitution. Also updates the mount mock to a placeholder before finalizing it with the correct test path, and ensures restore.sh is executable after modifications.
1 parent 9a4bd36 commit 9d7283f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

tests/test_restore.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ EOF
5858
chmod +x "$MOCK_BIN/diskutil"
5959

6060
# Mock mount (for check)
61-
cat << EOF > "$MOCK_BIN/mount"
61+
# Will be overwritten later with correct path
62+
cat << 'EOF' > "$MOCK_BIN/mount"
6263
#!/bin/sh
63-
echo "/dev/disk0s1 on $MOCK_VOLUMES/EFI (msdos, local, nodev, nosuid, noowners)"
64+
echo "mount mock"
6465
EOF
6566
chmod +x "$MOCK_BIN/mount"
6667

@@ -82,12 +83,7 @@ chmod +x "$MOCK_BIN/shutdown"
8283

8384
echo "Running restore.sh in test environment..."
8485

85-
# We need to modify restore.sh slightly to run in our test env (paths)
86-
# or we can just symlink our mock repo to where the script expects it.
87-
# The script expects ./BOOTEFIX64/EFI relative to CWD.
88-
8986
# Copy restore.sh to test dir
90-
# We assume restore.sh is in the parent directory
9187
if [ ! -f "../restore.sh" ]; then
9288
echo "Error: ../restore.sh not found!"
9389
exit 1
@@ -115,13 +111,17 @@ RUNTIME_MOCK_VOLUMES="./Volumes"
115111

116112
# Replace /Volumes/EFI with our mock path
117113
# Use | as delimiter to avoid escaping slashes
118-
sed "s|/Volumes/EFI|$RUNTIME_MOCK_VOLUMES/EFI|g" "$TEST_DIR/restore.sh" > "$TEST_DIR/restore.sh.tmp"
114+
# We replace the whole line to be safe
115+
sed "s|EFI_MOUNT_POINT=\"/Volumes/EFI\"|EFI_MOUNT_POINT=\"$RUNTIME_MOCK_VOLUMES/EFI\"|g" "$TEST_DIR/restore.sh" > "$TEST_DIR/restore.sh.tmp"
119116
mv "$TEST_DIR/restore.sh.tmp" "$TEST_DIR/restore.sh"
120117

121118
# Replace /Volumes/EFI_BACKUP with our mock path
122-
sed "s|/Volumes/EFI_BACKUP|$RUNTIME_MOCK_VOLUMES/EFI_BACKUP|g" "$TEST_DIR/restore.sh" > "$TEST_DIR/restore.sh.tmp"
119+
# We replace the whole line prefix
120+
sed "s|BACKUP_DIR=\"/Volumes/EFI_BACKUP_|BACKUP_DIR=\"$RUNTIME_MOCK_VOLUMES/EFI_BACKUP_|g" "$TEST_DIR/restore.sh" > "$TEST_DIR/restore.sh.tmp"
123121
mv "$TEST_DIR/restore.sh.tmp" "$TEST_DIR/restore.sh"
124122

123+
chmod +x "$TEST_DIR/restore.sh"
124+
125125
# Also update the mock mount script to return the path relative to CWD or absolute
126126
# Since we are inside TEST_DIR, ./Volumes/EFI is correct.
127127
cat << EOF > "$MOCK_BIN/mount"
@@ -130,8 +130,6 @@ echo "/dev/disk0s1 on $RUNTIME_MOCK_VOLUMES/EFI (msdos, local, nodev, nosuid, no
130130
EOF
131131
chmod +x "$MOCK_BIN/mount"
132132

133-
chmod +x "$TEST_DIR/restore.sh"
134-
135133
# Run the script
136134
# We pipe "y" to confirm the prompt, and "enter" for the final prompt
137135
cd "$TEST_DIR"

0 commit comments

Comments
 (0)