Merge pull request #892 from rul/fix-e2e-sc2086

test_e2e.sh: quote variables to prevent globbing and word splitting
This commit is contained in:
Kubernetes Prow Robot 2024-06-19 11:54:42 -07:00 committed by GitHub
commit faba6051f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 99 additions and 99 deletions

View File

@ -72,7 +72,7 @@ function assert_link_basename_eq() {
if [[ $(basename $(readlink "$1")) == "$2" ]]; then if [[ $(basename $(readlink "$1")) == "$2" ]]; then
return return
fi fi
fail "$1 does not point to $2: $(readlink $1)" fail "$1 does not point to $2: $(readlink "$1")"
} }
function assert_file_exists() { function assert_file_exists() {
@ -91,14 +91,14 @@ function assert_file_eq() {
if [[ $(cat "$1") == "$2" ]]; then if [[ $(cat "$1") == "$2" ]]; then
return return
fi fi
fail "$1 does not contain '$2': $(cat $1)" fail "$1 does not contain '$2': $(cat "$1")"
} }
function assert_file_contains() { function assert_file_contains() {
if grep -q "$2" "$1"; then if grep -q "$2" "$1"; then
return return
fi fi
fail "$1 does not contain '$2': $(cat $1)" fail "$1 does not contain '$2': $(cat "$1")"
} }
function assert_file_lines_eq() { function assert_file_lines_eq() {
@ -761,9 +761,9 @@ function e2e::stale_worktree_timeout() {
# wait for first sync # wait for first sync
wait_for_sync "${MAXWAIT}" wait_for_sync "${MAXWAIT}"
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
# wait 2 seconds and make another commit # wait 2 seconds and make another commit
sleep 2 sleep 2
@ -776,11 +776,11 @@ function e2e::stale_worktree_timeout() {
wait_for_sync "${MAXWAIT}" wait_for_sync "${MAXWAIT}"
# at this point both WT1 and WT2 should exist, with # at this point both WT1 and WT2 should exist, with
# link pointing to the new WT2 # link pointing to the new WT2
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/.worktrees/$WT1/file assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
# wait 2 seconds and make a third commit # wait 2 seconds and make a third commit
sleep 2 sleep 2
@ -793,57 +793,57 @@ function e2e::stale_worktree_timeout() {
# at this point WT1, WT2, WT3 should exist, with # at this point WT1, WT2, WT3 should exist, with
# link pointing to WT3 # link pointing to WT3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_exists "$ROOT"/.worktrees/$WT1/file assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT"/.worktrees/$WT2/file assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT"/.worktrees/$WT2/file2 assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
# wait for WT1 to go stale # wait for WT1 to go stale
sleep 4 sleep 4
# now WT1 should be stale and deleted, # now WT1 should be stale and deleted,
# WT2 and WT3 should still exist # WT2 and WT3 should still exist
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT"/.worktrees/$WT1/file assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT"/.worktrees/$WT2/file assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT"/.worktrees/$WT2/file2 assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
# wait for WT2 to go stale # wait for WT2 to go stale
sleep 2 sleep 2
# now both WT1 and WT2 are stale, WT3 should be the only # now both WT1 and WT2 are stale, WT3 should be the only
# worktree left # worktree left
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT"/.worktrees/$WT1/file assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_absent "$ROOT"/.worktrees/$WT2/file assert_file_absent "$ROOT/.worktrees/$WT2/file"
assert_file_absent "$ROOT"/.worktrees/$WT2/file2 assert_file_absent "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
} }
############################################## ##############################################
@ -859,9 +859,9 @@ function e2e::stale_worktree_timeout_restart() {
--link="link" \ --link="link" \
--one-time --one-time
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
# wait 2 seconds and make another commit # wait 2 seconds and make another commit
sleep 2 sleep 2
@ -880,11 +880,11 @@ function e2e::stale_worktree_timeout_restart() {
# at this point both WT1 and WT2 should exist, with # at this point both WT1 and WT2 should exist, with
# link pointing to the new WT2 # link pointing to the new WT2
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/.worktrees/$WT1/file assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
# wait 2 seconds and make a third commit # wait 2 seconds and make a third commit
sleep 4 sleep 4
@ -903,19 +903,19 @@ function e2e::stale_worktree_timeout_restart() {
# at this point WT1, WT2, WT3 should exist, with # at this point WT1, WT2, WT3 should exist, with
# link pointing to WT3 # link pointing to WT3
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_exists "$ROOT"/.worktrees/$WT1/file assert_file_exists "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT"/.worktrees/$WT2/file assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT"/.worktrees/$WT2/file2 assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
# wait for WT1 to go stale and restart git-sync # wait for WT1 to go stale and restart git-sync
sleep 8 sleep 8
@ -928,19 +928,19 @@ function e2e::stale_worktree_timeout_restart() {
# now WT1 should be stale and deleted, # now WT1 should be stale and deleted,
# WT2 and WT3 should still exist # WT2 and WT3 should still exist
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT"/.worktrees/$WT1/file assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_exists "$ROOT"/.worktrees/$WT2/file assert_file_exists "$ROOT/.worktrees/$WT2/file"
assert_file_exists "$ROOT"/.worktrees/$WT2/file2 assert_file_exists "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
# wait for WT2 to go stale and restart git-sync # wait for WT2 to go stale and restart git-sync
sleep 4 sleep 4
@ -953,19 +953,19 @@ function e2e::stale_worktree_timeout_restart() {
# now both WT1 and WT2 are stale, WT3 should be the only # now both WT1 and WT2 are stale, WT3 should be the only
# worktree left # worktree left
assert_link_exists "$ROOT"/link assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT"/link/file assert_file_exists "$ROOT/link/file"
assert_file_exists "$ROOT"/link/file2 assert_file_exists "$ROOT/link/file2"
assert_file_exists "$ROOT"/link/file3 assert_file_exists "$ROOT/link/file3"
assert_file_absent "$ROOT"/.worktrees/$WT1/file assert_file_absent "$ROOT/.worktrees/$WT1/file"
assert_file_absent "$ROOT"/.worktrees/$WT1/file2 assert_file_absent "$ROOT/.worktrees/$WT1/file2"
assert_file_absent "$ROOT"/.worktrees/$WT1/file3 assert_file_absent "$ROOT/.worktrees/$WT1/file3"
assert_file_absent "$ROOT"/.worktrees/$WT2/file assert_file_absent "$ROOT/.worktrees/$WT2/file"
assert_file_absent "$ROOT"/.worktrees/$WT2/file2 assert_file_absent "$ROOT/.worktrees/$WT2/file2"
assert_file_absent "$ROOT"/.worktrees/$WT2/file3 assert_file_absent "$ROOT/.worktrees/$WT2/file3"
assert_file_exists "$ROOT"/.worktrees/$WT3/file assert_file_exists "$ROOT/.worktrees/$WT3/file"
assert_file_exists "$ROOT"/.worktrees/$WT3/file2 assert_file_exists "$ROOT/.worktrees/$WT3/file2"
assert_file_exists "$ROOT"/.worktrees/$WT3/file3 assert_file_exists "$ROOT/.worktrees/$WT3/file3"
} }
############################################## ##############################################
@ -2869,7 +2869,7 @@ function e2e::submodule_sync_relative() {
# Add submodule # Add submodule
REL="$(realpath --relative-to "$REPO" "$WORK/$SUBMODULE_REPO_NAME")" REL="$(realpath --relative-to "$REPO" "$WORK/$SUBMODULE_REPO_NAME")"
echo $REL echo "$REL"
git -C "$REPO" -c protocol.file.allow=always submodule add -q "$REL" "$SUBMODULE_REPO_NAME" git -C "$REPO" -c protocol.file.allow=always submodule add -q "$REL" "$SUBMODULE_REPO_NAME"
git -C "$REPO" commit -aqm "add submodule" git -C "$REPO" commit -aqm "add submodule"
@ -3411,7 +3411,7 @@ function list_tests() {
declare -F \ declare -F \
| cut -f3 -d' ' \ | cut -f3 -d' ' \
| grep "^e2e::" \ | grep "^e2e::" \
| while read X; do declare -F $X; done \ | while read X; do declare -F "$X"; done \
| sort -n -k2 \ | sort -n -k2 \
| cut -f1 -d' ' \ | cut -f1 -d' ' \
| sed 's/^e2e:://' | sed 's/^e2e:://'