Skip to content

Commit b5621ce

Browse files
authored
Merge pull request #624 from devfile/JslYoon-renovate-tests
[Devfile #1718] Dynamic paths for devfile tests
2 parents ee0685a + c65ea41 commit b5621ce

File tree

4 files changed

+129
-29
lines changed

4 files changed

+129
-29
lines changed

tests/check_non_terminating.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
set -o nounset
33
set -o errexit
44

5-
DEVFILES_DIR="$(pwd)/stacks"
5+
# Source shared utilities
6+
source "$(dirname "$0")/paths_util.sh"
7+
8+
# Parse all arguments
9+
parse_arguments "$@"
10+
11+
# Restore positional parameters
12+
set -- "${POSITIONAL_ARGS[@]}"
13+
14+
# Set defaults for stack arguments
15+
set_stack_defaults
16+
17+
DEVFILES_DIR="$stacksPath"
618

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

1022
# Path to the check_non_terminating go package
1123
BIN_NAME=${BIN_NAME:-"flatten-parent"}

tests/check_odov3.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
set -x
44

5-
stackDirs=$(bash "$(pwd)/tests/get_stacks.sh")
5+
# Source shared utilities
6+
source "$(dirname "$0")/paths_util.sh"
7+
8+
# Parse all arguments
9+
parse_arguments "$@"
10+
11+
# Restore positional parameters
12+
set -- "${POSITIONAL_ARGS[@]}"
13+
14+
# Set defaults for stack arguments
15+
set_stack_defaults
16+
617
args=""
718

819
if [ ! -z "${1}" ]; then
@@ -63,4 +74,4 @@ ginkgo run --mod=readonly --procs 2 \
6374
--skip="stack: ollama" \
6475
--slow-spec-threshold 120s \
6576
--timeout 3h \
66-
tests/odov3 -- -stacksPath "$(pwd)"/stacks -stackDirs "$stackDirs" ${args}
77+
tests/odov3 -- -stacksPath "$stacksPath" -stackDirs "$stackDirs" ${args}

tests/paths_util.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
# Common variables used by all scripts
4+
stackDirs=''
5+
stacksPath=''
6+
POSITIONAL_ARGS=()
7+
8+
# Function to parse all arguments
9+
parse_arguments() {
10+
while [[ $# -gt 0 ]]; do
11+
case $1 in
12+
--stackDirs)
13+
if [ -z "${stackDirs}" ]; then
14+
stackDirs=$2
15+
else
16+
stackDirs="${stackDirs} $2"
17+
fi
18+
shift # past argument
19+
shift
20+
;;
21+
--stacksPath)
22+
stacksPath=$2
23+
shift # past argument
24+
shift
25+
;;
26+
-*|--*)
27+
# Try script-specific handler if it exists
28+
local consumed=0
29+
local errno=1
30+
if declare -f handle_additional_args > /dev/null 2>&1; then
31+
consumed=$(handle_additional_args "$@")
32+
errno=$?
33+
fi
34+
35+
if [ $errno -eq 0 ] && [ $consumed -gt 0 ]; then
36+
# Script handler consumed some arguments
37+
for ((i=0; i<consumed; i++)); do
38+
shift
39+
done
40+
else
41+
echo "Unknown option $1"
42+
return $errno
43+
fi
44+
;;
45+
*)
46+
POSITIONAL_ARGS+=("$1") # save positional arg
47+
shift # past argument
48+
;;
49+
esac
50+
done
51+
52+
return 0
53+
}
54+
55+
# Function to set default values for stack arguments
56+
set_stack_defaults() {
57+
if [ -z "$stackDirs" ]; then
58+
stackDirs=$(bash "$(pwd)/tests/get_stacks.sh")
59+
fi
60+
61+
if [ -z "$stacksPath" ]; then
62+
stacksPath="$(pwd)/stacks"
63+
fi
64+
}

tests/validate_devfile_schemas.sh

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
11
#!/usr/bin/env bash
22

3-
POSITIONAL_ARGS=()
3+
# Source shared utilities
4+
source "$(dirname "$0")/paths_util.sh"
5+
46
SAMPLES="false"
57
VERBOSE="false"
68

7-
while [[ $# -gt 0 ]]; do
8-
case $1 in
9-
-s|--samples)
10-
SAMPLES="true"
11-
shift # past argument
12-
;;
13-
-v|--verbose)
14-
VERBOSE="true"
15-
shift # past argument
16-
;;
17-
-*|--*)
18-
echo "Unknown option $1"
19-
exit 1
20-
;;
21-
*)
22-
POSITIONAL_ARGS+=("$1") # save positional arg
23-
shift # past argument
24-
;;
25-
esac
26-
done
27-
28-
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
9+
handle_additional_args() {
10+
case $1 in
11+
-s|--samples)
12+
SAMPLES="true"
13+
echo 1
14+
return 0
15+
;;
16+
-v|--verbose)
17+
VERBOSE="true"
18+
echo 1
19+
return 0
20+
;;
21+
*)
22+
echo 0
23+
return 1
24+
;;
25+
esac
26+
}
27+
28+
# Parse all arguments
29+
parse_arguments "$@"
30+
31+
# Restore positional parameters
32+
set -- "${POSITIONAL_ARGS[@]}"
33+
2934
set -x
3035

31-
stacksDir=${STACKS_DIR:-stacks}
32-
stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"}
36+
# Set defaults for stack arguments, with backward compatibility for environment variables
37+
if [ -z "$stacksPath" ]; then
38+
stacksPath=${STACKS_DIR:-stacks}
39+
fi
40+
41+
if [ -z "$stackDirs" ]; then
42+
stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"}
43+
fi
44+
45+
stacksDir="$stacksPath"
3346

3447
# Use pwd if relative path
3548
if [[ ! ${stacksDir} = /* ]]; then

0 commit comments

Comments
 (0)