2024-01-30 14:24:55 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
SUPER_LINTER_TEST_CONTAINER_URL="${1}"
|
|
|
|
TEST_FUNCTION_NAME="${2}"
|
|
|
|
|
2024-02-09 13:43:58 -05:00
|
|
|
COMMAND_TO_RUN=(docker run -e DEFAULT_BRANCH=main -e ENABLE_GITHUB_ACTIONS_GROUP_TITLE=true -e JSCPD_CONFIG_FILE=".jscpd-test-linters.json" -e RENOVATE_SHAREABLE_CONFIG_PRESET_FILE_NAMES="default.json,hoge.json" -e RUN_LOCAL=true -e TEST_CASE_RUN=true -e TYPESCRIPT_STANDARD_TSCONFIG_FILE=".github/linters/tsconfig.json" -v "$(pwd):/tmp/lint")
|
2024-01-30 14:24:55 -05:00
|
|
|
|
|
|
|
run_test_cases_expect_failure() {
|
|
|
|
COMMAND_TO_RUN+=(-e ANSIBLE_DIRECTORY="/test/linters/ansible/bad" -e CHECKOV_FILE_NAME=".checkov-test-linters-failure.yaml" -e FILTER_REGEX_INCLUDE=".*bad.*")
|
|
|
|
EXPECTED_EXIT_CODE=1
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test_cases_expect_success() {
|
|
|
|
COMMAND_TO_RUN+=(-e ANSIBLE_DIRECTORY="/test/linters/ansible/good" -e CHECKOV_FILE_NAME=".checkov-test-linters-success.yaml" -e FILTER_REGEX_INCLUDE=".*good.*")
|
|
|
|
}
|
|
|
|
|
2024-02-09 13:43:58 -05:00
|
|
|
run_test_cases_log_level() {
|
|
|
|
run_test_cases_expect_success
|
|
|
|
LOG_LEVEL="NOTICE"
|
|
|
|
}
|
|
|
|
|
2024-02-10 04:16:31 -05:00
|
|
|
run_test_cases_expect_failure_notice_log() {
|
|
|
|
run_test_cases_expect_failure
|
|
|
|
LOG_LEVEL="NOTICE"
|
|
|
|
}
|
|
|
|
|
2024-02-09 17:57:01 -05:00
|
|
|
run_test_cases_non_default_home() {
|
|
|
|
run_test_cases_expect_success
|
|
|
|
COMMAND_TO_RUN+=(-e HOME=/tmp)
|
|
|
|
}
|
|
|
|
|
2024-01-30 14:24:55 -05:00
|
|
|
# Run the test setup function
|
|
|
|
${TEST_FUNCTION_NAME}
|
|
|
|
|
2024-02-09 13:43:58 -05:00
|
|
|
COMMAND_TO_RUN+=(-e LOG_LEVEL="${LOG_LEVEL:-"DEBUG"}")
|
|
|
|
|
2024-01-30 14:24:55 -05:00
|
|
|
COMMAND_TO_RUN+=("${SUPER_LINTER_TEST_CONTAINER_URL}")
|
|
|
|
|
|
|
|
declare -i EXPECTED_EXIT_CODE
|
|
|
|
EXPECTED_EXIT_CODE=${EXPECTED_EXIT_CODE:-0}
|
|
|
|
|
|
|
|
if [ ${EXPECTED_EXIT_CODE} -ne 0 ]; then
|
|
|
|
echo "Disable failures on error because the expected exit code is ${EXPECTED_EXIT_CODE}"
|
|
|
|
set +o errexit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Command to run: ${COMMAND_TO_RUN[*]}"
|
|
|
|
|
|
|
|
"${COMMAND_TO_RUN[@]}"
|
|
|
|
SUPER_LINTER_EXIT_CODE=$?
|
|
|
|
# Enable the errexit option in case we disabled it
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
echo "Super-linter exit code: ${SUPER_LINTER_EXIT_CODE}"
|
|
|
|
|
|
|
|
if [ ${SUPER_LINTER_EXIT_CODE} -ne ${EXPECTED_EXIT_CODE} ]; then
|
|
|
|
echo "Super-linter exited with an unexpected code: ${SUPER_LINTER_EXIT_CODE}"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Super-linter exited with the expected code: ${SUPER_LINTER_EXIT_CODE}"
|
|
|
|
fi
|