Skip to content

[Devfile #1718] Dynamic paths for devfile tests #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions tests/check_non_terminating.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
set -o nounset
set -o errexit

DEVFILES_DIR="$(pwd)/stacks"
# Source shared utilities
source "$(dirname "$0")/paths_util.sh"

# Parse all arguments
parse_arguments "$@"

# Restore positional parameters
set -- "${POSITIONAL_ARGS[@]}"

# Set defaults for stack arguments
set_stack_defaults

DEVFILES_DIR="$stacksPath"

# The stacks to test as a string separated by spaces
STACKS=$(bash "$(pwd)/tests/get_stacks.sh")
STACKS="$stackDirs"

# Path to the check_non_terminating go package
BIN_NAME=${BIN_NAME:-"flatten-parent"}
Expand Down
15 changes: 13 additions & 2 deletions tests/check_odov3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

set -x

stackDirs=$(bash "$(pwd)/tests/get_stacks.sh")
# Source shared utilities
source "$(dirname "$0")/paths_util.sh"

# Parse all arguments
parse_arguments "$@"

# Restore positional parameters
set -- "${POSITIONAL_ARGS[@]}"

# Set defaults for stack arguments
set_stack_defaults

args=""

if [ ! -z "${1}" ]; then
Expand Down Expand Up @@ -63,4 +74,4 @@ ginkgo run --mod=readonly --procs 2 \
--skip="stack: ollama" \
--slow-spec-threshold 120s \
--timeout 3h \
tests/odov3 -- -stacksPath "$(pwd)"/stacks -stackDirs "$stackDirs" ${args}
tests/odov3 -- -stacksPath "$stacksPath" -stackDirs "$stackDirs" ${args}
64 changes: 64 additions & 0 deletions tests/paths_util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

# Common variables used by all scripts
stackDirs=''
stacksPath=''
POSITIONAL_ARGS=()

# Function to parse all arguments
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--stackDirs)
if [ -z "${stackDirs}" ]; then
stackDirs=$2
else
stackDirs="${stackDirs} $2"
fi
shift # past argument
shift
;;
--stacksPath)
stacksPath=$2
shift # past argument
shift
;;
-*|--*)
# Try script-specific handler if it exists
local consumed=0
local errno=1
if declare -f handle_additional_args > /dev/null 2>&1; then
consumed=$(handle_additional_args "$@")
errno=$?
fi

if [ $errno -eq 0 ] && [ $consumed -gt 0 ]; then
# Script handler consumed some arguments
for ((i=0; i<consumed; i++)); do
shift
done
else
echo "Unknown option $1"
return $errno
fi
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

return 0
}

# Function to set default values for stack arguments
set_stack_defaults() {
if [ -z "$stackDirs" ]; then
stackDirs=$(bash "$(pwd)/tests/get_stacks.sh")
fi

if [ -z "$stacksPath" ]; then
stacksPath="$(pwd)/stacks"
fi
}
63 changes: 38 additions & 25 deletions tests/validate_devfile_schemas.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
#!/usr/bin/env bash

POSITIONAL_ARGS=()
# Source shared utilities
source "$(dirname "$0")/paths_util.sh"

SAMPLES="false"
VERBOSE="false"

while [[ $# -gt 0 ]]; do
case $1 in
-s|--samples)
SAMPLES="true"
shift # past argument
;;
-v|--verbose)
VERBOSE="true"
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
handle_additional_args() {
case $1 in
-s|--samples)
SAMPLES="true"
echo 1
return 0
;;
-v|--verbose)
VERBOSE="true"
echo 1
return 0
;;
*)
echo 0
return 1
;;
esac
}

# Parse all arguments
parse_arguments "$@"

# Restore positional parameters
set -- "${POSITIONAL_ARGS[@]}"

set -x

stacksDir=${STACKS_DIR:-stacks}
stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"}
# Set defaults for stack arguments, with backward compatibility for environment variables
if [ -z "$stacksPath" ]; then
stacksPath=${STACKS_DIR:-stacks}
fi

if [ -z "$stackDirs" ]; then
stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"}
fi

stacksDir="$stacksPath"

# Use pwd if relative path
if [[ ! ${stacksDir} = /* ]]; then
Expand Down
Loading