Complete Refactor for target/bin (#1654)

* documentation and script updates trying to fix #1647
* preparations for refactoring target/bin/
* complete refactor for target/bin/
* changing script output slightly
* outsourcing functions in `bin-helper.sh`
* re-wrote linting to allow for proper shellcheck -x execution
* show explanation for shellcheck ignore
* adding some more information
This commit is contained in:
Georg Lauterbach 2020-10-21 18:16:32 +02:00 committed by GitHub
parent 0ada57d87c
commit da8171388f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 579 additions and 504 deletions

View file

@ -2,7 +2,7 @@ load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
# load the helper function into current context
. ./target/helper_functions.sh
. ./target/helper-functions.sh
@test "check helper function: _sanitize_ipv4_to_subnet_cidr" {
output=$(_sanitize_ipv4_to_subnet_cidr 255.255.255.255/0)
@ -11,4 +11,4 @@ load 'test_helper/bats-assert/load'
assert_output "192.168.240.0/20"
output=$(_sanitize_ipv4_to_subnet_cidr 192.168.255.14/32)
assert_output "192.168.255.14/32"
}
}

View file

@ -81,7 +81,8 @@ function __which { command -v "${@}" &>/dev/null ; }
function _eclint
{
local LINT=(eclint -exclude "(.*\.git.*|.*\.md$|\.bats$)")
local SCRIPT='EDITORCONFIG LINTER'
local LINT=(eclint -exclude "(.*\.git.*|.*\.md$|\.bats$|\.cf$|\.conf$|\.init$)")
if ! __in_path "${LINT[0]}"
then
@ -93,7 +94,6 @@ function _eclint
'type: editorconfig' \
'(linter version:' "$(${LINT[0]} --version))"
local SCRIPT='EDITORCONFIG LINTER'
if "${LINT[@]}"
then
__log_success 'no errors detected'
@ -105,6 +105,7 @@ function _eclint
function _hadolint
{
local SCRIPT='HADOLINT'
local LINT=(hadolint -c "${CDIR}/.hadolint.yaml")
if ! __in_path "${LINT[0]}"
@ -117,7 +118,6 @@ function _hadolint
'type: Dockerfile' \
'(linter version:' "$(${LINT[0]} --version | grep -E -o "v[0-9\.]*"))"
local SCRIPT='HADOLINT'
if git ls-files --exclude='Dockerfile*' --ignored | \
xargs --max-lines=1 "${LINT[@]}"
then
@ -130,7 +130,9 @@ function _hadolint
function _shellcheck
{
local LINT=(/usr/bin/shellcheck -S style -Cauto -o all -e SC2154 -W 50)
local SCRIPT='SHELLCHECK'
local ERR=0
local LINT=(/usr/bin/shellcheck -x -S style -Cauto -o all -e SC2154 -W 50)
if ! __in_path "${LINT[0]}"
then
@ -142,17 +144,44 @@ function _shellcheck
'type: shellcheck' '(linter version:' \
"$(${LINT[0]} --version | grep -m 2 -o "[0-9.]*"))"
local FIND=(
find . -iname "*.sh"
-not -path "./test/*"
-not -path "./target/docker-configomat/*"
-exec "${LINT[@]}" {} \;)
# an overengineered solution to allow shellcheck -x to
# properly follow `source=<SOURCE FILE>` when sourcing
# files with `. <FILE>` in shell scripts.
while read -r FILE
do
if ! (
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then
return 1
fi
)
then
ERR=1
fi
done < <(find . -type f -iname "*.sh" \
-not -path "./test/bats/*" \
-not -path "./test/test_helper/*" \
-not -path "./target/docker-configomat/*")
local SCRIPT='SHELLCHECK'
if "${FIND[@]}" | grep -q .
# the same for executables in target/bin/
while read -r FILE
do
if ! (
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then
return 1
fi
)
then
ERR=1
fi
done < <(find target/bin -executable -type f)
if [[ ERR -eq 1 ]]
then
"${FIND[@]}"
__log_abort
__log_abort 'errors encountered'
return 101
else
__log_success 'no errors detected'

View file

@ -25,7 +25,7 @@ function setup_file() {
tail -f /var/log/faillog
wait_for_finished_setup_in_container mail_fail2ban
}
function teardown_file() {
@ -125,11 +125,11 @@ function teardown_file() {
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client set dovecot banip 192.0.66.5"
sleep 10
run ./setup.sh -c mail_fail2ban debug fail2ban
assert_output --regexp "^Banned in dovecot: 192.0.66.5 192.0.66.4.*"
assert_output -p "Banned in dovecot: 192.0.66.5" -p "Banned in dovecot: 192.0.66.4"
run ./setup.sh -c mail_fail2ban debug fail2ban unban 192.0.66.4
assert_output --partial "unbanned IP from dovecot: 192.0.66.4"
run ./setup.sh -c mail_fail2ban debug fail2ban
assert_output --regexp "^Banned in dovecot: 192.0.66.5.*"
assert_output --partial "Banned in dovecot: 192.0.66.5"
run ./setup.sh -c mail_fail2ban debug fail2ban unban 192.0.66.5
run ./setup.sh -c mail_fail2ban debug fail2ban unban
assert_output --partial "You need to specify an IP address. Run"
@ -146,4 +146,4 @@ function teardown_file() {
@test "last" {
skip 'this test is only there to reliably mark the end for the teardown_file'
}
}