Skip to content

Commit

Permalink
fixed UT flakiness
Browse files Browse the repository at this point in the history
- using Bash::handlePipelineFailure
- removed usage of Embeded binaries in dbScriptAllDatabases and dbQueryAllDatabases
  • Loading branch information
fchastanet committed Jan 15, 2024
1 parent 031841c commit 0bb6e57
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ cliCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/dbImport
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ dbImportCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/dbImportProfile
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ dbImportProfileCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/dbImportStream
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ dbImportStreamCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
97 changes: 94 additions & 3 deletions bin/dbQueryAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,96 @@ Version::checkMinimal() {

}

bashToolsDefaultConfigTemplate="${bashToolsDefaultConfigTemplate:-$(
cat <<'EOF'
# shellcheck disable=SC2034
# Default settings
# you can override these settings by creating ${HOME}/.bash-tools/.env file
###
### LOG Level
### minimum level of the messages that will be logged into LOG_FILE
###
### 0: NO LOG
### 1: ERROR
### 2: WARNING
### 3: INFO
### 4: DEBUG
###
BASH_FRAMEWORK_LOG_LEVEL=${BASH_FRAMEWORK_LOG_LEVEL:-0}
###
### DISPLAY Level
### minimum level of the messages that will be displayed on screen
###
### 0: NO LOG
### 1: ERROR
### 2: WARNING
### 3: INFO
### 4: DEBUG
###
BASH_FRAMEWORK_DISPLAY_LEVEL=${BASH_FRAMEWORK_DISPLAY_LEVEL:-3}
###
### Log to file
###
### all log messages will be redirected to log file specified
### this same path will be used inside and outside of the container
###
BASH_FRAMEWORK_LOG_FILE=${BASH_FRAMEWORK_LOG_FILE:-${FRAMEWORK_ROOT_DIR}/logs/bash.log}
# absolute directory containing db import sql dumps
DB_IMPORT_DUMP_DIR=${DB_IMPORT_DUMP_DIR:-${HOME}/.bash-tools/dbImportDumps}
# garbage collect all files for which modification is greater than eg: 30 days (+30)
# each time an existing file is used by dbImport/dbImportTable
# the file modification time is set to now
DB_IMPORT_GARBAGE_COLLECT_DAYS=${DB_IMPORT_GARBAGE_COLLECT_DAYS:-+30}
# absolute directory containing dbScripts used by dbScriptAllDatabases
SCRIPTS_FOLDER=${SCRIPTS_FOLDER:-${HOME}/.bash-tools/conf/dbScripts}
# -----------------------------------------------------
# AWS Parameters
# -----------------------------------------------------
S3_BASE_URL=${S3_BASE_URL:-}
# -----------------------------------------------------
# Postman Parameters
# -----------------------------------------------------
POSTMAN_API_KEY=
EOF
)}"

# @description loads ~/.bash-tools/.env if available
# if not creates it from a default template
# else check if new options need to be added
BashTools::Conf::requireLoad() {
local envFile="${HOME}/.bash-tools/.env"
if [[ ! -f "${envFile}" ]]; then
mkdir -p "${HOME}/.bash-tools"
(
echo "#!/usr/bin/env bash"
echo "${bashToolsDefaultConfigTemplate}"
) >"${envFile}"
Log::displayInfo "Configuration file '${envFile}' created"
else
if ! grep -q '^POSTMAN_API_KEY=' "${envFile}"; then
(
echo '# -----------------------------------------------------'
echo '# Postman Parameters'
echo '# -----------------------------------------------------'
echo 'POSTMAN_API_KEY='
) >>"${envFile}"
fi
fi
# shellcheck source=/conf/.env
source "${envFile}" || {
Log::displayError "impossible to load '${envFile}'"
exit 1
}
}

# @description ensure COMMAND_BIN_DIR env var is set
# and PATH correctly prepared
# @noargs
Expand Down Expand Up @@ -1152,6 +1242,7 @@ Env::requireLoad
UI::requireTheme
Linux::requireRealpathCommand
Log::requireLoad
BashTools::Conf::requireLoad
Compiler::Facade::requireCommandBinDir

# @require Compiler::Facade::requireCommandBinDir
Expand Down Expand Up @@ -1836,7 +1927,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(specify\ the\ number\ of\ db\ to\ query\ in\ parallel)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 1"
echo ' Default value: 1'
echo -e " ${__HELP_OPTION_COLOR}--bar${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-b${__HELP_NORMAL} {single}"
local -a helpArray
# shellcheck disable=SC2054
Expand All @@ -1847,7 +1938,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(character\ to\ use\ to\ separate\ mysql\ column)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: |"
echo ' Default value: |'
echo
echo -e "${__HELP_TITLE_COLOR}QUERY OPTIONS:${__RESET_COLOR}"
echo -e " ${__HELP_OPTION_COLOR}--from-dsn${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-f <String>${__HELP_NORMAL} {single}"
Expand Down Expand Up @@ -1897,7 +1988,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
97 changes: 94 additions & 3 deletions bin/dbScriptAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,96 @@ UI::theme() {
fi
}

bashToolsDefaultConfigTemplate="${bashToolsDefaultConfigTemplate:-$(
cat <<'EOF'
# shellcheck disable=SC2034
# Default settings
# you can override these settings by creating ${HOME}/.bash-tools/.env file
###
### LOG Level
### minimum level of the messages that will be logged into LOG_FILE
###
### 0: NO LOG
### 1: ERROR
### 2: WARNING
### 3: INFO
### 4: DEBUG
###
BASH_FRAMEWORK_LOG_LEVEL=${BASH_FRAMEWORK_LOG_LEVEL:-0}
###
### DISPLAY Level
### minimum level of the messages that will be displayed on screen
###
### 0: NO LOG
### 1: ERROR
### 2: WARNING
### 3: INFO
### 4: DEBUG
###
BASH_FRAMEWORK_DISPLAY_LEVEL=${BASH_FRAMEWORK_DISPLAY_LEVEL:-3}
###
### Log to file
###
### all log messages will be redirected to log file specified
### this same path will be used inside and outside of the container
###
BASH_FRAMEWORK_LOG_FILE=${BASH_FRAMEWORK_LOG_FILE:-${FRAMEWORK_ROOT_DIR}/logs/bash.log}
# absolute directory containing db import sql dumps
DB_IMPORT_DUMP_DIR=${DB_IMPORT_DUMP_DIR:-${HOME}/.bash-tools/dbImportDumps}
# garbage collect all files for which modification is greater than eg: 30 days (+30)
# each time an existing file is used by dbImport/dbImportTable
# the file modification time is set to now
DB_IMPORT_GARBAGE_COLLECT_DAYS=${DB_IMPORT_GARBAGE_COLLECT_DAYS:-+30}
# absolute directory containing dbScripts used by dbScriptAllDatabases
SCRIPTS_FOLDER=${SCRIPTS_FOLDER:-${HOME}/.bash-tools/conf/dbScripts}
# -----------------------------------------------------
# AWS Parameters
# -----------------------------------------------------
S3_BASE_URL=${S3_BASE_URL:-}
# -----------------------------------------------------
# Postman Parameters
# -----------------------------------------------------
POSTMAN_API_KEY=
EOF
)}"

# @description loads ~/.bash-tools/.env if available
# if not creates it from a default template
# else check if new options need to be added
BashTools::Conf::requireLoad() {
local envFile="${HOME}/.bash-tools/.env"
if [[ ! -f "${envFile}" ]]; then
mkdir -p "${HOME}/.bash-tools"
(
echo "#!/usr/bin/env bash"
echo "${bashToolsDefaultConfigTemplate}"
) >"${envFile}"
Log::displayInfo "Configuration file '${envFile}' created"
else
if ! grep -q '^POSTMAN_API_KEY=' "${envFile}"; then
(
echo '# -----------------------------------------------------'
echo '# Postman Parameters'
echo '# -----------------------------------------------------'
echo 'POSTMAN_API_KEY='
) >>"${envFile}"
fi
fi
# shellcheck source=/conf/.env
source "${envFile}" || {
Log::displayError "impossible to load '${envFile}'"
exit 1
}
}

# @description ensure COMMAND_BIN_DIR env var is set
# and PATH correctly prepared
# @noargs
Expand Down Expand Up @@ -999,6 +1089,7 @@ Env::requireLoad
UI::requireTheme
Linux::requireRealpathCommand
Log::requireLoad
BashTools::Conf::requireLoad
Compiler::Facade::requireCommandBinDir
Linux::requireExecutedAsUser

Expand Down Expand Up @@ -1723,7 +1814,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(specify\ the\ number\ of\ db\ to\ query\ in\ parallel)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 1"
echo ' Default value: 1'
echo -e " ${__HELP_OPTION_COLOR}--bar${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-b${__HELP_NORMAL} {single}"
local -a helpArray
# shellcheck disable=SC2054
Expand Down Expand Up @@ -1751,7 +1842,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(if\ output\ dir\ provided\,\ will\ log\ each\ db\ result\ to\ log\ file)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: none"
echo ' Default value: none'
echo ' Possible values: none|log'
echo
echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}"
Expand Down Expand Up @@ -1795,7 +1886,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/doc
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ docCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitIsAncestorOf
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ gitIsAncestorOfCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitIsBranch
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ gitIsBranchCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitRenameBranch
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ gitRenameBranchCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/installRequirements
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ installRequirementsCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
4 changes: 2 additions & 2 deletions bin/mysql2puml
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ mysql2pumlCommand() {
# shellcheck disable=SC2054
helpArray=(header\ configuration\ of\ the\ plant\ uml\ file)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo
echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}"
echo -e " ${__HELP_OPTION_COLOR}--bash-framework-config <String>${__HELP_NORMAL} {single}"
Expand Down Expand Up @@ -1568,7 +1568,7 @@ mysql2pumlCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
Loading

0 comments on commit 0bb6e57

Please sign in to comment.