Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 55 additions & 5 deletions hack/bats/tests/shell-sync.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ teardown() {
fi
}

file_uid() {
local path="$1"
if [[ "$OSTYPE" == darwin* ]]; then
stat -f '%u' "$path"
else
stat -c '%u' "$path"
fi
}

file_perm_octal() {
local path="$1"
if [[ "$OSTYPE" == darwin* ]]; then
stat -f '%A' "$path"
else
stat -c '%a' "$path"
fi
}

@test 'shell --sync preserves working directory path from host to guest' {
cd "$TEST_SYNC_DIR"

Expand Down Expand Up @@ -122,11 +140,7 @@ EOF
run -0 bash -c "limactl shell --sync . --yes '$INSTANCE' ./modify.sh"

# Verify file is still executable on host
if [[ "$OSTYPE" == darwin* ]]; then
run stat -f '%A' "$TEST_SYNC_DIR/executable.sh"
else
run stat -c '%a' "$TEST_SYNC_DIR/executable.sh"
fi
run file_perm_octal "$TEST_SYNC_DIR/executable.sh"
assert_output "755"

# Verify files were modified
Expand All @@ -136,6 +150,42 @@ EOF
assert_output "modified bar"
}

@test 'shell --sync reflects chmod metadata changes from guest to host' {
cd "$TEST_SYNC_DIR"

touch "$TEST_SYNC_DIR/metadata-perms.sh"
chmod 644 "$TEST_SYNC_DIR/metadata-perms.sh"

run -0 bash -c "limactl shell --sync . --yes '$INSTANCE' sh -ceu 'chmod 744 metadata-perms.sh'"

run file_perm_octal "$TEST_SYNC_DIR/metadata-perms.sh"
assert_output "744"
}

@test 'shell --sync reflects symlink target updates from guest to host' {
cd "$TEST_SYNC_DIR"

echo "a" > "$TEST_SYNC_DIR/target_a.txt"
echo "b" > "$TEST_SYNC_DIR/target_b.txt"
ln -s target_a.txt "$TEST_SYNC_DIR/current_link.txt"

run -0 bash -c "limactl shell --sync . --yes '$INSTANCE' ln -snf target_b.txt current_link.txt"

assert_symlink_to "$TEST_SYNC_DIR/target_b.txt" "$TEST_SYNC_DIR/current_link.txt"
}

@test 'shell --sync preserves host ownership after guest modification' {
cd "$TEST_SYNC_DIR"

touch "$TEST_SYNC_DIR/ownership-test.txt"
orig_uid=$(file_uid "$TEST_SYNC_DIR/ownership-test.txt")

run -0 bash -c "limactl shell --sync . --yes '$INSTANCE' sh -ceu 'sudo chown root ownership-test.txt'"

new_uid=$(file_uid "$TEST_SYNC_DIR/ownership-test.txt")
assert_equal "$orig_uid" "$new_uid"
}

@test 'shell --sync works without existing ControlMaster socket' {
cd "$TEST_SYNC_DIR"

Expand Down
Loading