diff --git a/hack/run-e2e.sh b/hack/run-e2e.sh index c2cdbde165..82d94c3b8a 100755 --- a/hack/run-e2e.sh +++ b/hack/run-e2e.sh @@ -25,7 +25,7 @@ fi show_help() { cat </internal/e2e" is a "target-path", and may sit before, between or +after the go test flags. +Without one, it defaults to "./internal/e2e/suites/...". -Arguments before "-args" (excluding the target-path) are passed directly to "go test". +Other arguments before "-args" are passed directly to "go test". Arguments after "-args" are passed to the test binary. Example: @@ -71,7 +73,11 @@ See "go help testflag" for more Go test flags. EOF } -target_path="./internal/e2e/suites/..." +module_path="$(sed -n 's/^module //p' go.mod)" + +is_target_path() { + [[ "$1" == "./internal/e2e"* || "$1" == "internal/e2e"* || "$1" == "${module_path}/internal/e2e"* ]] +} if [[ "$#" -gt 0 ]]; then if [[ "$1" == "-h" || "$1" == "--help" ]]; then @@ -79,20 +85,15 @@ if [[ "$#" -gt 0 ]]; then exit 0 fi - if [[ "$1" == "./internal/e2e"* || "$1" == "internal/e2e"* ]]; then - target_path="$1" - shift - elif [[ "$1" == -* ]]; then - # It's a flag, keep default target_path, don't shift - : - else + if [[ "$1" != -* ]] && ! is_target_path "$1"; then echo "Error: Invalid target path '$1'." >&2 - echo "The first argument must be a valid E2E path starting with './internal/e2e' or a flag starting with '-'." >&2 + echo "The first argument must be a valid E2E path starting with './internal/e2e', '${module_path}/internal/e2e' or a flag starting with '-'." >&2 echo "Use '$0 -h' for help." >&2 exit 1 fi fi +target_paths=() go_test_args=() e2e_args=() found_args_sep=false @@ -112,6 +113,8 @@ for arg in "$@"; do if [[ "$found_args_sep" == "true" ]]; then e2e_args+=("$arg") + elif is_target_path "$arg"; then + target_paths+=("$arg") else # Both spellings: go's flag package accepts -flag, --flag, and either with =value. case "$arg" in @@ -123,6 +126,10 @@ for arg in "$@"; do fi done +if [[ "${#target_paths[@]}" -eq 0 ]]; then + target_paths=("./internal/e2e/suites/...") +fi + extra_e2e_args=() if [[ -n "${KUBECTL_CONTEXT:-}" ]]; then extra_e2e_args+=("--kube-context" "${KUBECTL_CONTEXT}") @@ -156,7 +163,7 @@ if [[ "${has_timeout_flag}" == "false" ]]; then fi # Assembled once so the two execution paths below cannot drift apart. -test_argv=("$target_path") +test_argv=("${target_paths[@]}") test_argv+=(${default_go_test_args[@]+"${default_go_test_args[@]}"}) test_argv+=(${go_test_args[@]+"${go_test_args[@]}"}) test_argv+=(-args --e2e)