update funtion_test.sh support CLI mode

This commit is contained in:
doufenghu
2024-06-19 12:12:52 +08:00
parent 5d7cb84093
commit 3980b597c3
2 changed files with 212 additions and 84 deletions

View File

@@ -1,7 +1,11 @@
#!/bin/bash #!/bin/bash
show_help() {
echo " echo "
--folder Specify a single folder to run from a collection. Usage: $(basename "$0") [-f FOLDER_NUMBER] [-a] [-v] [-e]
Options:
-f FOLDER_NUMBER Specify a single folder to run from a collection:
1. Query 1. Query
2. Dataset 2. Dataset
3. Database 3. Database
@@ -9,46 +13,106 @@ echo "
5. Troubleshooting 5. Troubleshooting
6. HOS 6. HOS
7. Knowledge Base File 7. Knowledge Base File
-a Run all options [1-7]
-v Enable verbose reporting
-e Enable emojitrain reporting
-h, --help Show this help message and exit
" "
}
BASE_DIR="$(dirname "$(pwd)")" BASE_DIR="$(dirname "$(pwd)")"
CONFIG_PATH="$BASE_DIR/config" CONFIG_PATH="$BASE_DIR/config"
FOLDER=""
ALL=false
VERBOSE_FLAG=false
EMOJITRAIN_FLAG=false
#COLLECTION_FILE=`find $BIN_PATH -name '*'function-test-collection.json|xargs| awk -F" " '{print $1}'` # Flag to check if any valid option is provided
#ENV_FILE=environment.json VALID_OPTION_PROVIDED=false
FOLDER="--folder " # Parse command-line arguments
while [[ $# -gt 0 ]]; do
if [[ -n "$1" ]];then
case $1 in case $1 in
1) -f)
FOLDER+="Query" VALID_OPTION_PROVIDED=true
if [[ -n $2 && $2 =~ ^[1-7]$ ]]; then
case $2 in
1) FOLDER="--folder Query" ;;
2) FOLDER="--folder Dataset" ;;
3) FOLDER="--folder Database" ;;
4) FOLDER="--folder Util" ;;
5) FOLDER="--folder Troubleshooting" ;;
6) FOLDER="--folder HOS" ;;
7) FOLDER="--folder Knowledge Base File" ;;
esac
shift 2
else
echo "Error: Invalid folder number."
show_help
exit 1
fi
;; ;;
2) -a)
FOLDER+="Dataset" VALID_OPTION_PROVIDED=true
ALL=true
shift
;; ;;
3) -v)
FOLDER+="Database" VERBOSE_FLAG=true
shift
;; ;;
4) -e)
FOLDER+="Util" EMOJITRAIN_FLAG=true
shift
;; ;;
5) -h|--help)
FOLDER+="Troubleshooting" show_help
;; exit 0
6)
FOLDER+="HOS"
;;
7)
FOLDER+="Knowledge Base File"
;; ;;
*) *)
FOLDER="" echo "Error: Unknown option $1"
show_help
exit 1
;;
esac esac
else done
if ! $VALID_OPTION_PROVIDED; then
show_help
exit 1
fi
if $ALL; then
FOLDER="" FOLDER=""
fi fi
echo $FOLDER NEW_MAN_OPTS=(
"$CONFIG_PATH/tsg-olap-function-test-collection.json"
-n 1
-e "$CONFIG_PATH/environment.json"
-g "$CONFIG_PATH/globals.json"
--delay-request 200
--timeout-script 10000
--timeout-request 300000
--timeout 3600000
--insecure
)
# Add verbose reporting option if enabled
if $VERBOSE_FLAG; then
NEW_MAN_OPTS+=(--verbose)
fi
# Add folder option if set
if [[ -n $FOLDER ]]; then
NEW_MAN_OPTS+=($FOLDER)
fi
# Add emojitrain reporting option if enabled
if $EMOJITRAIN_FLAG; then
NEW_MAN_OPTS+=(-r emojitrain)
fi
# Run the newman command
newman run "${NEW_MAN_OPTS[@]}"
newman run $CONFIG_PATH/tsg-olap-function-test-collection.json -n 1 -e $CONFIG_PATH/environment.json -g $CONFIG_PATH/globals.json --verbose --delay-request 200 --timeout-script 10000 --timeout-request 300000 --timeout 3600000 --insecure \
$FOLDER

View File

@@ -1,7 +1,11 @@
#!/bin/bash #!/bin/bash
show_help() {
echo " echo "
--folder Specify a single folder to run from a collection. Usage: $(basename "$0") [-f FOLDER_NUMBER] [-a] [-v] [-e]
Options:
-f FOLDER_NUMBER Specify a single folder to run from a collection:
1. Query 1. Query
2. Dataset 2. Dataset
3. Database 3. Database
@@ -9,46 +13,106 @@ echo "
5. Troubleshooting 5. Troubleshooting
6. HOS 6. HOS
7. Knowledge Base File 7. Knowledge Base File
-a Run all options [1-7]
-v Enable verbose reporting
-e Enable emojitrain reporting
-h, --help Show this help message and exit
" "
}
BASE_DIR="$(dirname "$(pwd)")" BASE_DIR="$(dirname "$(pwd)")"
CONFIG_PATH="$BASE_DIR/config" CONFIG_PATH="$BASE_DIR/config"
FOLDER=""
ALL=false
VERBOSE_FLAG=false
EMOJITRAIN_FLAG=false
#COLLECTION_FILE=`find $BIN_PATH -name '*'function-test-collection.json|xargs| awk -F" " '{print $1}'` # Flag to check if any valid option is provided
#ENV_FILE=environment.json VALID_OPTION_PROVIDED=false
FOLDER="--folder " # Parse command-line arguments
while [[ $# -gt 0 ]]; do
if [[ -n "$1" ]];then
case $1 in case $1 in
1) -f)
FOLDER+="Query" VALID_OPTION_PROVIDED=true
if [[ -n $2 && $2 =~ ^[1-7]$ ]]; then
case $2 in
1) FOLDER="--folder Query" ;;
2) FOLDER="--folder Dataset" ;;
3) FOLDER="--folder Database" ;;
4) FOLDER="--folder Util" ;;
5) FOLDER="--folder Troubleshooting" ;;
6) FOLDER="--folder HOS" ;;
7) FOLDER="--folder Knowledge Base File" ;;
esac
shift 2
else
echo "Error: Invalid folder number."
show_help
exit 1
fi
;; ;;
2) -a)
FOLDER+="Dataset" VALID_OPTION_PROVIDED=true
ALL=true
shift
;; ;;
3) -v)
FOLDER+="Database" VERBOSE_FLAG=true
shift
;; ;;
4) -e)
FOLDER+="Util" EMOJITRAIN_FLAG=true
shift
;; ;;
5) -h|--help)
FOLDER+="Troubleshooting" show_help
;; exit 0
6)
FOLDER+="HOS"
;;
7)
FOLDER+="Knowledge Base File"
;; ;;
*) *)
FOLDER="" echo "Error: Unknown option $1"
show_help
exit 1
;;
esac esac
else done
if ! $VALID_OPTION_PROVIDED; then
show_help
exit 1
fi
if $ALL; then
FOLDER="" FOLDER=""
fi fi
echo $FOLDER NEW_MAN_OPTS=(
"$CONFIG_PATH/tsg-olap-function-test-collection.json"
-n 1
-e "$CONFIG_PATH/environment.json"
-g "$CONFIG_PATH/globals.json"
--delay-request 200
--timeout-script 10000
--timeout-request 300000
--timeout 3600000
--insecure
)
# Add verbose reporting option if enabled
if $VERBOSE_FLAG; then
NEW_MAN_OPTS+=(--verbose)
fi
# Add folder option if set
if [[ -n $FOLDER ]]; then
NEW_MAN_OPTS+=($FOLDER)
fi
# Add emojitrain reporting option if enabled
if $EMOJITRAIN_FLAG; then
NEW_MAN_OPTS+=(-r emojitrain)
fi
# Run the newman command
newman run "${NEW_MAN_OPTS[@]}"
newman run $CONFIG_PATH/tsg-olap-function-test-collection.json -n 1 -e $CONFIG_PATH/environment.json -g $CONFIG_PATH/globals.json --verbose --delay-request 200 --timeout-script 10000 --timeout-request 300000 --timeout 3600000 --insecure \
$FOLDER