chore: split validation logic in smaller functions (#5892)

- Move USE_FIND_ALGORITHM and VALIDATE_ALL_CODEBASE validation in a
  dedicated function (ValidateFindMode).
- Move ANSIBLE_DIRECTORY validation to a dedicated function
  (ValidateAnsibleDirectory).
- Move VALIDATE_xxxx variables validation to a dedicated function
  (ValidateValidationVariables).
- Mark ANY_SET, ANY_TRUE, ANY_FALSE as local because we don't need to
  reference them anywhere outside ValidateValidationVariables.
- Add some debug statements in validation functions.
- Merge the loops to initialize VALIDATE_xxx variables and to print
  enable/disable language debug messages.
- Add tests for these validation functions.
- Add test start message for all tests.
This commit is contained in:
Marco Ferrari 2024-07-16 10:22:45 +02:00 committed by GitHub
parent d9d19095ec
commit d2d73347d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 324 additions and 86 deletions

View file

@ -40,81 +40,15 @@ function ValidateGitHubWorkspace() {
info "Successfully validated GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
}
function GetValidationInfo() {
info "--------------------------------------------"
info "Validating the configuration"
function ValidateFindMode() {
debug "Validating find mode. USE_FIND_ALGORITHM: ${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE: ${VALIDATE_ALL_CODEBASE}"
if [[ "${USE_FIND_ALGORITHM}" == "true" ]] && [[ "${VALIDATE_ALL_CODEBASE}" == "false" ]]; then
fatal "Setting USE_FIND_ALGORITHM to true and VALIDATE_ALL_CODEBASE to false is not supported because super-linter relies on Git to validate changed files."
error "Setting USE_FIND_ALGORITHM to true and VALIDATE_ALL_CODEBASE to false is not supported because super-linter relies on Git to validate changed files."
return 1
fi
}
################################################
# Determine if any linters were explicitly set #
################################################
ANY_SET="false"
ANY_TRUE="false"
ANY_FALSE="false"
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
debug "Set VALIDATE_LANGUAGE while validating the configuration: ${VALIDATE_LANGUAGE}"
if [ -n "${!VALIDATE_LANGUAGE:-}" ]; then
# Validate if user provided a string representing a valid boolean
ValidateBooleanVariable "${VALIDATE_LANGUAGE}" "${!VALIDATE_LANGUAGE}"
# It was set, need to set flag
ANY_SET="true"
if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then
ANY_TRUE="true"
elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then
ANY_FALSE="true"
fi
else
debug "Configuration didn't provide a custom value for ${VALIDATE_LANGUAGE}"
fi
done
if [ $ANY_TRUE == "true" ] && [ $ANY_FALSE == "true" ]; then
fatal "Behavior not supported, please either only include (VALIDATE=true) or exclude (VALIDATE=false) linters, but not both"
fi
#########################################################
# Validate if we should check/omit individual languages #
#########################################################
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
if [[ ${ANY_SET} == "true" ]]; then
if [ -z "${!VALIDATE_LANGUAGE:-}" ]; then
# Flag was not set, default to:
# if ANY_TRUE then set to false
# if ANY_FALSE then set to true
eval "${VALIDATE_LANGUAGE}='$ANY_FALSE'"
fi
else
# No linter flags were set - default all to true
eval "${VALIDATE_LANGUAGE}='true'"
fi
eval "export ${VALIDATE_LANGUAGE}"
done
#######################################
# Print which linters we are enabling #
#######################################
# Loop through all languages
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
if [[ ${!VALIDATE_LANGUAGE} == "true" ]]; then
debug "- Validating [${LANGUAGE}] files in code base..."
else
debug "- Excluding [$LANGUAGE] files in code base..."
fi
done
##############################
# Validate Ansible Directory #
##############################
function ValidateAnsibleDirectory() {
if [ -z "${ANSIBLE_DIRECTORY:-}" ]; then
ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible"
debug "Set ANSIBLE_DIRECTORY to the default: ${ANSIBLE_DIRECTORY}"
@ -141,6 +75,69 @@ function GetValidationInfo() {
export ANSIBLE_DIRECTORY
}
function ValidateValidationVariables() {
################################################
# Determine if any linters were explicitly set #
################################################
local ANY_SET="false"
local ANY_TRUE="false"
local ANY_FALSE="false"
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
debug "Check if configuration provided a custom value to enable or disable ${LANGUAGE}"
local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
if [ -n "${!VALIDATE_LANGUAGE:-}" ]; then
debug "Configuration provided a custom value for ${VALIDATE_LANGUAGE}: ${!VALIDATE_LANGUAGE}"
# Validate if user provided a string representing a valid boolean
ValidateBooleanVariable "${VALIDATE_LANGUAGE}" "${!VALIDATE_LANGUAGE}"
ANY_SET="true"
if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then
ANY_TRUE="true"
# We already checked that VALIDATE_LANGUAGE is either true or false
else
ANY_FALSE="true"
fi
else
debug "Configuration didn't provide a custom value for ${VALIDATE_LANGUAGE}"
fi
done
debug "ANY_SET: ${ANY_SET}, ANY_TRUE: ${ANY_TRUE}, ANY_FALSE: ${ANY_FALSE}"
if [ $ANY_TRUE == "true" ] && [ $ANY_FALSE == "true" ]; then
error "Behavior not supported, please either only include (VALIDATE=true) or exclude (VALIDATE=false) linters, but not both"
return 1
fi
#########################################################
# Validate if we should check/omit individual languages #
#########################################################
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
local VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
if [[ ${ANY_SET} == "true" ]]; then
debug "Configuration contains at least one custom value to enable or disable linters."
if [ -z "${!VALIDATE_LANGUAGE:-}" ]; then
# Flag was not set, default to:
# if ANY_TRUE then set to false
# if ANY_FALSE then set to true
eval "${VALIDATE_LANGUAGE}='$ANY_FALSE'"
fi
else
eval "${VALIDATE_LANGUAGE}='true'"
debug "Configuration doesn't include any custom values to enable or disable linters. Setting VALIDATE variable for ${LANGUAGE} to: ${!VALIDATE_LANGUAGE}"
fi
if [[ "${!VALIDATE_LANGUAGE}" == "true" ]]; then
debug "- Validating [${LANGUAGE}] files in code base..."
else
debug "- Excluding [$LANGUAGE] files in code base..."
fi
eval "export ${VALIDATE_LANGUAGE}"
done
}
function CheckIfGitBranchExists() {
local BRANCH_NAME="${1}"
debug "Check if the ${BRANCH_NAME} branch exists in ${GITHUB_WORKSPACE}"

View file

@ -828,7 +828,17 @@ mkdir -p "${SUPER_LINTER_PRIVATE_OUTPUT_DIRECTORY_PATH}"
############################
# Validate the environment #
############################
GetValidationInfo
info "--------------------------------------------"
info "Validating the configuration"
if ! ValidateFindMode; then
fatal "Error while validating the configuration."
fi
if ! ValidateValidationVariables; then
fatal "Error while validating the configuration of enabled linters"
fi
if ! ValidateAnsibleDirectory; then
fatal "Error while validating the configuration of enabled linters"
fi
if [[ "${USE_FIND_ALGORITHM}" == "false" ]] || [[ "${IGNORE_GITIGNORED_FILES}" == "true" ]]; then
debug "Validate the local Git environment"

View file

@ -123,6 +123,9 @@ function GenerateFileDiffTwoFilesPushEventTest() {
}
function BuildFileArraysAnsibleGitHubWorkspaceTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
# shellcheck source=/dev/null
source /action/lib/functions/detectFiles.sh
@ -158,8 +161,6 @@ function BuildFileArraysAnsibleGitHubWorkspaceTest() {
fatal "${FILE_ARRAY_ANSIBLE_PATH} doesn't contain ${ANSIBLE_DIRECTORY}"
fi
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}

View file

@ -17,6 +17,9 @@ CREATE_LOG_FILE=false
source "lib/functions/detectFiles.sh"
function RecognizeNoShebangTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/noShebang_bad.sh"
debug "Confirming ${FILE} has no shebang"
@ -25,11 +28,13 @@ function RecognizeNoShebangTest() {
fatal "${FILE} is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeCommentIsNotShebangTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/comment_bad.sh"
debug "Confirming ${FILE} starting with a comment has no shebang"
@ -38,11 +43,13 @@ RecognizeCommentIsNotShebangTest() {
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeIndentedShebangAsCommentTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/indentedShebang_bad.sh"
debug "Confirming indented shebang in ${FILE} is considered a comment"
@ -51,11 +58,13 @@ RecognizeIndentedShebangAsCommentTest() {
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
RecognizeSecondLineShebangAsCommentTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/secondLineShebang_bad.sh"
debug "Confirming shebang on second line in ${FILE} is considered a comment"
@ -64,11 +73,13 @@ RecognizeSecondLineShebangAsCommentTest() {
fatal "${FILE} with a comment is mis-classified as having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function RecognizeShebangTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/shebang_bad.sh"
debug "Confirming ${FILE} has a shebang"
@ -77,11 +88,13 @@ function RecognizeShebangTest() {
fatal "${FILE} is mis-classified as not having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function RecognizeShebangWithBlankTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local FILE="test/linters/bash_exec/libraries/shebangWithBlank_bad.sh"
debug "Confirming shebang with blank in ${FILE} is recognized"
@ -90,11 +103,14 @@ function RecognizeShebangWithBlankTest() {
fatal "${FILE} is mis-classified as not having a shebang"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function IsAnsibleDirectoryTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local GITHUB_WORKSPACE
GITHUB_WORKSPACE="$(mktemp -d)"
local FILE="${GITHUB_WORKSPACE}/ansible"
@ -108,7 +124,6 @@ function IsAnsibleDirectoryTest() {
fatal "${FILE} is not considered to be an Ansible directory"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}

View file

@ -19,6 +19,10 @@ source "lib/functions/validation.sh"
source "lib/functions/githubEvent.sh"
function GetGithubPushEventCommitCountTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local GITHUB_EVENT_COMMIT_COUNT
GITHUB_EVENT_COMMIT_COUNT=$(GetGithubPushEventCommitCount "test/data/github-event/github-event-push.json")
@ -28,13 +32,16 @@ function GetGithubPushEventCommitCountTest() {
fatal "GITHUB_EVENT_COMMIT_COUNT is not equal to 1: ${GITHUB_EVENT_COMMIT_COUNT}"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
GetGithubPushEventCommitCountTest
function GetGithubRepositoryDefaultBranchTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local GITHUB_REPOSITORY_DEFAULT_BRANCH
GITHUB_REPOSITORY_DEFAULT_BRANCH=$(GetGithubRepositoryDefaultBranch "test/data/github-event/github-event-push.json")
@ -47,7 +54,6 @@ function GetGithubRepositoryDefaultBranchTest() {
fatal "GITHUB_REPOSITORY_DEFAULT_BRANCH (${GITHUB_REPOSITORY_DEFAULT_BRANCH}) is not equal to: ${EXPECTED_GITHUB_REPOSITORY_DEFAULT_BRANCH}"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}

View file

@ -21,6 +21,10 @@ GITHUB_META_URL="https://api.${GITHUB_DOMAIN}/meta"
source "lib/functions/setupSSH.sh"
function GetGitHubSshRsaKeyFingerprintTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
local SSH_RSA_KEY_FINGERPRINT
SSH_RSA_KEY_FINGERPRINT=$(GetGitHubSshRsaKeyFingerprint)
@ -33,14 +37,16 @@ function GetGitHubSshRsaKeyFingerprintTest() {
fatal "SSH_RSA_KEY_FINGERPRINT is not equal to ${EXPECTED_GITHUB_RSA_KEY_FINGERPRINT}: ${SSH_RSA_KEY_FINGERPRINT}"
fi
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}
function SetupGithubComSshKeysTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
SSH_KEY="test_ssh_key" SSH_INSECURE_NO_VERIFY_GITHUB_KEY="false" SetupGithubComSshKeys
FUNCTION_NAME="${FUNCNAME[0]}"
notice "${FUNCTION_NAME} PASS"
}

View file

@ -17,7 +17,9 @@ source "lib/functions/log.sh"
source "lib/functions/validation.sh"
function IsUnsignedIntegerSuccessTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
if ! IsUnsignedInteger 1; then
fatal "${FUNCTION_NAME} failed"
@ -27,7 +29,9 @@ function IsUnsignedIntegerSuccessTest() {
}
function IsUnsignedIntegerFailureTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
if IsUnsignedInteger "test"; then
fatal "${FUNCTION_NAME} failed"
@ -38,7 +42,9 @@ function IsUnsignedIntegerFailureTest() {
# In the current implementation, there is no return value to assert
function ValidateDeprecatedVariablesTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
ERROR_ON_MISSING_EXEC_BIT="true" \
ValidateDeprecatedVariables
@ -57,7 +63,9 @@ function ValidateDeprecatedVariablesTest() {
}
function ValidateGitHubUrlsTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
# shellcheck disable=SC2034
DEFAULT_GITHUB_DOMAIN="github.com"
@ -149,7 +157,9 @@ function ValidateGitHubUrlsTest() {
}
function ValidateGitHubActionsStepSummaryTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY="false"
if ! ValidateGitHubActionsStepSummary; then
@ -199,8 +209,201 @@ function ValidateGitHubActionsStepSummaryTest() {
notice "${FUNCTION_NAME} PASS"
}
function ValidateFindModeTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
USE_FIND_ALGORITHM="true"
VALIDATE_ALL_CODEBASE="false"
if ValidateFindMode; then
fatal "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} should have failed validation"
else
info "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} failed validation as expected"
fi
unset USE_FIND_ALGORITHM
unset VALIDATE_ALL_CODEBASE
USE_FIND_ALGORITHM="false"
VALIDATE_ALL_CODEBASE="false"
if ValidateFindMode; then
info "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} passed validation as expected"
else
fatal "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} should have passed validation"
fi
unset USE_FIND_ALGORITHM
unset VALIDATE_ALL_CODEBASE
USE_FIND_ALGORITHM="false"
VALIDATE_ALL_CODEBASE="true"
if ValidateFindMode; then
info "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} passed validation as expected"
else
fatal "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} should have passed validation"
fi
unset USE_FIND_ALGORITHM
unset VALIDATE_ALL_CODEBASE
USE_FIND_ALGORITHM="true"
VALIDATE_ALL_CODEBASE="true"
if ValidateFindMode; then
info "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} passed validation as expected"
else
fatal "USE_FIND_ALGORITHM=${USE_FIND_ALGORITHM}, VALIDATE_ALL_CODEBASE=${VALIDATE_ALL_CODEBASE} should have passed validation"
fi
unset USE_FIND_ALGORITHM
unset VALIDATE_ALL_CODEBASE
notice "${FUNCTION_NAME} PASS"
}
function ValidateAnsibleDirectoryTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
# shellcheck disable=SC2034
GITHUB_WORKSPACE="/test-github-workspace"
ValidateAnsibleDirectory
EXPECTED_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/ansible"
if [[ "${ANSIBLE_DIRECTORY:-}" != "${EXPECTED_ANSIBLE_DIRECTORY}" ]]; then
fatal "ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) is not equal to the expected value: ${EXPECTED_ANSIBLE_DIRECTORY}"
fi
ANSIBLE_DIRECTORY="."
ValidateAnsibleDirectory
EXPECTED_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}"
if [[ "${ANSIBLE_DIRECTORY:-}" != "${EXPECTED_ANSIBLE_DIRECTORY}" ]]; then
fatal "ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) is not equal to the expected value: ${EXPECTED_ANSIBLE_DIRECTORY}"
fi
INPUT_ANSIBLE_DIRECTORY="/custom-ansible-directory"
ANSIBLE_DIRECTORY="${INPUT_ANSIBLE_DIRECTORY}"
ValidateAnsibleDirectory
EXPECTED_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}${INPUT_ANSIBLE_DIRECTORY}"
if [[ "${ANSIBLE_DIRECTORY:-}" != "${EXPECTED_ANSIBLE_DIRECTORY}" ]]; then
fatal "ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) is not equal to the expected value: ${EXPECTED_ANSIBLE_DIRECTORY}"
fi
INPUT_ANSIBLE_DIRECTORY="custom-ansible-directory"
ANSIBLE_DIRECTORY="${INPUT_ANSIBLE_DIRECTORY}"
ValidateAnsibleDirectory
EXPECTED_ANSIBLE_DIRECTORY="${GITHUB_WORKSPACE}/${INPUT_ANSIBLE_DIRECTORY}"
if [[ "${ANSIBLE_DIRECTORY:-}" != "${EXPECTED_ANSIBLE_DIRECTORY}" ]]; then
fatal "ANSIBLE_DIRECTORY (${ANSIBLE_DIRECTORY}) is not equal to the expected value: ${EXPECTED_ANSIBLE_DIRECTORY}"
fi
unset GITHUB_WORKSPACE
notice "${FUNCTION_NAME} PASS"
}
function ValidateValidationVariablesTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
# shellcheck disable=SC2034
LANGUAGE_ARRAY=('A' 'B')
if ValidateValidationVariables; then
info "Providing no VALIDATE_xxx variables passed validation as expected"
else
fatal "Providing no VALIDATE_xxx variables should have passed validation"
fi
VALIDATE_A="true"
if ValidateValidationVariables; then
info "VALIDATE_A=${VALIDATE_A} passed validation as expected"
else
fatal "VALIDATE_A=${VALIDATE_A} should have passed validation"
fi
unset VALIDATE_A
# TODO: Refactor the ValidateBooleanVariable function to throw an error instead of a fatal
# VALIDATE_A="blah"
# if ! ValidateValidationVariables; then
# info "VALIDATE_A=${VALIDATE_A} failed validation as expected"
# else
# fatal "VALIDATE_A=${VALIDATE_A} should have failed validation"
# fi
# unset VALIDATE_A
VALIDATE_A="true"
VALIDATE_B="true"
if ValidateValidationVariables; then
info "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} passed validation as expected"
else
fatal "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} should have passed validation"
fi
unset VALIDATE_A
unset VALIDATE_B
VALIDATE_A="false"
VALIDATE_B="false"
if ValidateValidationVariables; then
info "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} passed validation as expected"
else
fatal "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} should have passed validation"
fi
unset VALIDATE_A
unset VALIDATE_B
VALIDATE_A="true"
VALIDATE_B="false"
if ! ValidateValidationVariables; then
info "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} failed validation as expected"
else
fatal "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} should have failed validation"
fi
unset VALIDATE_A
unset VALIDATE_B
VALIDATE_A="false"
VALIDATE_B="true"
if ! ValidateValidationVariables; then
info "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} failed validation as expected"
else
fatal "VALIDATE_A=${VALIDATE_A}, VALIDATE_B=${VALIDATE_B} should have failed validation"
fi
unset VALIDATE_A
unset VALIDATE_B
notice "${FUNCTION_NAME} PASS"
}
function ValidationVariablesExportTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
# shellcheck disable=SC2034
LANGUAGE_ARRAY=('A' 'B')
ValidateValidationVariables
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
local -n VALIDATE_LANGUAGE
VALIDATE_LANGUAGE="VALIDATE_${LANGUAGE}"
debug "VALIDATE_LANGUAGE (${LANGUAGE}) variable attributes: ${VALIDATE_LANGUAGE@a}"
if [[ "${VALIDATE_LANGUAGE@a}" == *x* ]]; then
info "VALIDATE_LANGUAGE for ${LANGUAGE} is exported as expected"
else
fatal "VALIDATE_LANGUAGE for ${LANGUAGE} should have been exported"
fi
unset -n VALIDATE_LANGUAGE
done
notice "${FUNCTION_NAME} PASS"
}
IsUnsignedIntegerSuccessTest
IsUnsignedIntegerFailureTest
ValidateDeprecatedVariablesTest
ValidateGitHubUrlsTest
ValidateGitHubActionsStepSummaryTest
ValidateFindModeTest
ValidateAnsibleDirectoryTest
ValidateValidationVariablesTest
ValidationVariablesExportTest