Skip to content

Commit

Permalink
fixed UT flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed Jan 7, 2024
1 parent f637e31 commit 989ad1a
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,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 @@ -2194,7 +2194,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 @@ -1807,7 +1807,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 @@ -2006,7 +2006,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
6 changes: 3 additions & 3 deletions bin/dbQueryAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,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 @@ -1935,7 +1935,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 @@ -1985,7 +1985,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
6 changes: 3 additions & 3 deletions bin/dbScriptAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,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 @@ -1919,7 +1919,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 @@ -1963,7 +1963,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 @@ -1650,7 +1650,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 @@ -1400,7 +1400,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 @@ -1378,7 +1378,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 @@ -1484,7 +1484,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 @@ -1445,7 +1445,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 @@ -1551,7 +1551,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 @@ -1594,7 +1594,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
36 changes: 33 additions & 3 deletions bin/postmanCli
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ Postman::api() {
--header 'Accept: application/json' \
--header "X-Api-Key: ${POSTMAN_API_KEY}" \
--data @- \
--fail --silent --show-error || status=$?
--fail --silent --show-error || Bash::handlePipelineFailure status

Postman::displayResponse "createCollectionFromFile" "${responseFile}"

Expand All @@ -1182,7 +1182,7 @@ Postman::api() {
--header 'Accept: application/json' \
--header "X-Api-Key: ${POSTMAN_API_KEY}" \
--data @- \
--fail --silent --show-error || status=$?
--fail --silent --show-error || Bash::handlePipelineFailure status

Postman::displayResponse "updateCollectionFromFile" "${responseFile}"

Expand Down Expand Up @@ -1217,6 +1217,36 @@ Postman::api() {
esac
}

# @description ignore exit code 141 from simple command pipes
# @example use with:
# local resultingStatus=0
# local -a originalPipeStatus=()
# cmd1 | cmd2 || handle_pipefails originalPipeStatus resultingStatus || true
# [[ "${resultingStatus}" = "0" ]]
# @arg $1 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
# @arg $2 resultingStatusCode:&int (passed by reference) (optional) resulting status code
# @env PIPESTATUS assuming that this function is called like in the example provided
# @see https://unix.stackexchange.com/a/709880/582856
Bash::handlePipelineFailure() {
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
local -n handlePipelineFailure_originalStatus=$1
local -n handlePipelineFailure_resultingStatusCode=$2
# shellcheck disable=SC2034
handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}")
handlePipelineFailure_resultingStatusCode=0
local statusCode
for statusCode in "${pipeStatusBackup[@]}"; do
if ((statusCode == 141)); then
return 0
elif ((statusCode > 0)); then
# shellcheck disable=SC2034
handlePipelineFailure_resultingStatusCode="${statusCode}"
break
fi
done
return "${handlePipelineFailure_resultingStatusCode}"
}

# @description log message to file
# @arg $1 message:String the message to display
Log::logSkipped() {
Expand Down Expand Up @@ -1978,7 +2008,7 @@ postmanCliCommand() {
# 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/upgradeGithubRelease
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ upgradeGithubReleaseCommand() {
# shellcheck disable=SC2054
helpArray=($'The argument that will be provided to the currently installed binary\n\n to check the version of the software. \n\n See options constraints below.')
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: --version"
echo ' Default value: --version'
echo -e " ${__HELP_OPTION_COLOR}--current-version${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-c <currentVersion>${__HELP_NORMAL} {single}"
local -a helpArray
# shellcheck disable=SC2054
Expand Down Expand Up @@ -1817,7 +1817,7 @@ upgradeGithubReleaseCommand() {
# 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/waitForIt
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ waitForItCommand() {
# shellcheck disable=SC2054
helpArray=(Timeout\ in\ seconds\,\ zero\ for\ no\ timeout.)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 15"
echo ' Default value: 15'
echo -e " ${__HELP_OPTION_COLOR}--host${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-i <hostOrIp>${__HELP_NORMAL} {single} (mandatory)"
local -a helpArray
# shellcheck disable=SC2054
Expand Down Expand Up @@ -1540,7 +1540,7 @@ waitForItCommand() {
# 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/waitForMysql
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ waitForMysqlCommand() {
# shellcheck disable=SC2054
helpArray=(Timeout\ in\ seconds\,\ zero\ for\ no\ timeout.)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 15"
echo ' Default value: 15'
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 @@ -1496,7 +1496,7 @@ waitForMysqlCommand() {
# 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 install
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ installCommand() {
# 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
15 changes: 11 additions & 4 deletions src/Postman/Model/validate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ setup() {
export BASH_FRAMEWORK_THEME="noColor"
}

teardown() {
chmod -R u+w "${BATS_TEST_TMPDIR}/pullMode" 2>/dev/null || true
}

function Postman::Model::validate::missingMode { #@test
run Postman::Model::validate \
"fileNotFound.json" "invalidMode"
Expand Down Expand Up @@ -89,17 +93,20 @@ function Postman::Model::validate::pushModeCollectionsWithErrors { #@test
}

function Postman::Model::validate::pullModeCollectionsWithErrors { #@test
cp -R "${BATS_TEST_DIRNAME}/testsData/pullMode" "${BATS_TEST_TMPDIR}"
chmod -w "${BATS_TEST_TMPDIR}/pullMode/GithubAPI/notWritableFile.json"
chmod -w "${BATS_TEST_TMPDIR}/pullMode"
Postman::Model::getRelativeConfigDirectory() {
echo "${BATS_TEST_DIRNAME}/testsData/pullMode"
echo "${BATS_TEST_TMPDIR}/pullMode"
}
local file="${BATS_TEST_DIRNAME}/testsData/pullMode/getCollectionRefs-collectionsWithErrors.json"
local file="${BATS_TEST_TMPDIR}/pullMode/getCollectionRefs-collectionsWithErrors.json"
run Postman::Model::validate \
"${file}" "pull"

assert_failure 1
assert_line --index 0 "ERROR - File '${file}' - collection 0 - missing file property"
assert_line --index 1 "ERROR - File '${file}' - collection fileNotWritable - collection file ${BATS_TEST_DIRNAME}/testsData/pullMode/GithubAPI/notWritableFile.json is not writable"
assert_line --index 2 "ERROR - File '${file}' - collection dirNotWritable - config directory ${BATS_TEST_DIRNAME}/testsData/pullMode is not writable"
assert_line --index 1 "ERROR - File '${file}' - collection fileNotWritable - collection file ${BATS_TEST_TMPDIR}/pullMode/GithubAPI/notWritableFile.json is not writable"
assert_line --index 2 "ERROR - File '${file}' - collection dirNotWritable - config directory ${BATS_TEST_TMPDIR}/pullMode is not writable"

assert_lines_count 3
}
Expand Down
2 changes: 2 additions & 0 deletions src/Postman/api.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
source "$(cd "${BATS_TEST_DIRNAME}/.." && pwd)/batsHeaders.sh"
# shellcheck source=src/Postman/api.sh
source "${rootDir}/src/Postman/api.sh"
# shellcheck source=vendor/bash-tools-framework/src/Bash/handlePipelineFailure.sh
source "${FRAMEWORK_ROOT_DIR}/src/Bash/handlePipelineFailure.sh"

setup() {
export BASH_FRAMEWORK_THEME="noColor"
Expand Down
4 changes: 2 additions & 2 deletions src/Postman/api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Postman::api() {
--header 'Accept: application/json' \
--header "X-Api-Key: ${POSTMAN_API_KEY}" \
--data @- \
--fail --silent --show-error || status=$?
--fail --silent --show-error || Bash::handlePipelineFailure status

Postman::displayResponse "createCollectionFromFile" "${responseFile}"

Expand All @@ -60,7 +60,7 @@ Postman::api() {
--header 'Accept: application/json' \
--header "X-Api-Key: ${POSTMAN_API_KEY}" \
--data @- \
--fail --silent --show-error || status=$?
--fail --silent --show-error || Bash::handlePipelineFailure status

Postman::displayResponse "updateCollectionFromFile" "${responseFile}"

Expand Down

0 comments on commit 989ad1a

Please sign in to comment.