[Dev] Rewrite tests files to respect shellcheck and shfmt

This commit is contained in:
samuel 2023-05-11 00:56:10 +02:00
parent 8958bea96b
commit 08237fc626
4 changed files with 82 additions and 75 deletions

View File

@ -86,12 +86,13 @@ install: conf/*.sample systemd/*.service bin/*
.PHONY: check_format .PHONY: check_format
check_format: check_format:
shfmt --diff ./src shfmt --diff ./src ./tests
.PHONY: check_linting .PHONY: check_linting
check_linting: check_linting:
shfmt --find ./src | xargs bash -o noexec shfmt --find ./src ./tests | while read f; do bash -o noexec $$f; done
shfmt --find ./src | xargs shellcheck --external-sources shfmt --find ./src ./tests | while read f; do \
shellcheck --external-sources $$f; done
.PHONY: unit_test .PHONY: unit_test
unit_test: unit_test:

View File

@ -5,6 +5,7 @@
bats_require_minimum_version 1.5.0 bats_require_minimum_version 1.5.0
setup() { setup() {
# shellcheck source=./tests/tests.conf
source "${PWD}/tests/tests.conf" source "${PWD}/tests/tests.conf"
make build >/dev/null make build >/dev/null
DESTDIR="${temp}" make install >/dev/null DESTDIR="${temp}" make install >/dev/null
@ -13,6 +14,7 @@ setup() {
"${temp}${sysconf_dir}/${name}/${name}.conf" "${temp}${sysconf_dir}/${name}/${name}.conf"
install --directory "${temp}${var_dir}/${name}/repositories/test.git" install --directory "${temp}${var_dir}/${name}/repositories/test.git"
install --directory "${temp}${var_dir}/${name}/RPMS" install --directory "${temp}${var_dir}/${name}/RPMS"
# shellcheck source=./conf/errors.conf.sample
source "${errs_file}" source "${errs_file}"
} }
@ -21,7 +23,7 @@ teardown() {
make clean >/dev/null make clean >/dev/null
} }
@test "run with bad arguments" { run_with_bad_arguments() { #@test
run -1 "${deployer_bin}" -z test run -1 "${deployer_bin}" -z test
run -1 "${deployer_bin}" --zzz test run -1 "${deployer_bin}" --zzz test
run -1 "${deployer_bin}" zzz run -1 "${deployer_bin}" zzz
@ -35,7 +37,7 @@ teardown() {
run -1 "${deployer_bin}" --verbose --quiet test run -1 "${deployer_bin}" --verbose --quiet test
} }
@test "run without loop" { run_without_loop() { #@test
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test "${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
} }
@ -54,56 +56,56 @@ send_request() (
return "${code}" return "${code}"
) )
@test "run with err_pkg_name_missing" { run_with_err_pkg_name_missing() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s}')" '{"response_sock":$s}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_pkg_name_missing}" echo "status: got ${status:?}, expected ${err_pkg_name_missing}"
[ "${status}" -eq "${err_pkg_name_missing}" ] [ "${status}" -eq "${err_pkg_name_missing}" ]
} }
@test "run with err_pkg_name_empty" { run_with_err_pkg_name_empty() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"pkg_name":""}')" '{"response_sock":$s,"pkg_name":""}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_pkg_name_empty}" echo "status: got ${status:?}, expected ${err_pkg_name_empty}"
[ "${status}" -eq "${err_pkg_name_empty}" ] [ "${status}" -eq "${err_pkg_name_empty}" ]
} }
@test "run with err_repo_dir_not_exist" { run_with_err_repo_dir_not_exist() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"pkg_name":"not_exist"}')" '{"response_sock":$s,"pkg_name":"not_exist"}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_dir_not_exist}" echo "status: got ${status:?}, expected ${err_repo_dir_not_exist}"
[ "${status}" -eq "${err_repo_dir_not_exist}" ] [ "${status}" -eq "${err_repo_dir_not_exist}" ]
} }
@test "run with err_pkg_version_missing" { run_with_err_pkg_version_missing() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"pkg_name":"test"}')" '{"response_sock":$s,"pkg_name":"test"}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_pkg_version_missing}" echo "status: got ${status:?}, expected ${err_pkg_version_missing}"
[ "${status}" -eq "${err_pkg_version_missing}" ] [ "${status}" -eq "${err_pkg_version_missing}" ]
} }
@test "run with err_pkg_version_empty" { run_with_err_pkg_version_empty() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"pkg_name":"test","pkg_version":""}')" '{"response_sock":$s,"pkg_name":"test","pkg_version":""}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_pkg_version_empty}" echo "status: got ${status:?}, expected ${err_pkg_version_empty}"
[ "${status}" -eq "${err_pkg_version_empty}" ] [ "${status}" -eq "${err_pkg_version_empty}" ]
} }
@test "run with err_rpm_path_not_exist" { run_with_err_rpm_path_not_exist() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"pkg_name":"test","pkg_version":"0.1"}')" '{"response_sock":$s,"pkg_name":"test","pkg_version":"0.1"}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_rpm_path_not_exist}" echo "status: got ${status:?}, expected ${err_rpm_path_not_exist}"
[ "${status}" -eq "${err_rpm_path_not_exist}" ] [ "${status}" -eq "${err_rpm_path_not_exist}" ]
} }

View File

@ -5,12 +5,14 @@
bats_require_minimum_version 1.5.0 bats_require_minimum_version 1.5.0
setup() { setup() {
# shellcheck source=./tests/tests.conf
source "${PWD}/tests/tests.conf" source "${PWD}/tests/tests.conf"
make build >/dev/null make build >/dev/null
DESTDIR="${temp}" make install >/dev/null DESTDIR="${temp}" make install >/dev/null
install --no-target-directory \ install --no-target-directory \
"${PWD}/tests/tests.conf" \ "${PWD}/tests/tests.conf" \
"${temp}${sysconf_dir}/${name}/${name}.conf" "${temp}${sysconf_dir}/${name}/${name}.conf"
# shellcheck source=./conf/errors.conf.sample
source "${errs_file}" source "${errs_file}"
} }
@ -19,7 +21,7 @@ teardown() {
make clean >/dev/null make clean >/dev/null
} }
@test "run with bad arguments" { run_with_bad_arguments() { #@test
run -1 "${pipeline_bin}" run -1 "${pipeline_bin}"
run -1 "${pipeline_bin}" bad_pipeline run -1 "${pipeline_bin}" bad_pipeline
@ -39,21 +41,21 @@ teardown() {
run -1 "${pipeline_bin}" -e /path/to/nowhere -H hash -n name newcommit run -1 "${pipeline_bin}" -e /path/to/nowhere -H hash -n name newcommit
} }
@test "run without runner sock" { run_without_runner_sock() { #@test
run "${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \ run "${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
--test --hash hash --name name newcommit --test --hash hash --name name newcommit
echo "status: got ${status}, expected ${err_runner_sock_not_exist}" echo "status: got ${status:?}, expected ${err_runner_sock_not_exist}"
[ "${status}" -eq "${err_runner_sock_not_exist}" ] [ "${status}" -eq "${err_runner_sock_not_exist}" ]
} }
@test "run newcommit ok" { run_newcommit_ok() { #@test
ncat --listen --unixsock "${runner_sock}" & ncat --listen --unixsock "${runner_sock}" &
"${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \ "${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
--test --hash hash --name name newcommit --test --hash hash --name name newcommit
echo "done" | ncat --unixsock "${runner_sock}" echo "done" | ncat --unixsock "${runner_sock}"
} }
@test "run newtag ok" { run_newtag_ok() { #@test
ncat --listen --unixsock "${runner_sock}" & ncat --listen --unixsock "${runner_sock}" &
"${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \ "${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
--test --hash hash --name name --tag tag newtag --test --hash hash --name name --tag tag newtag

View File

@ -5,6 +5,7 @@
bats_require_minimum_version 1.5.0 bats_require_minimum_version 1.5.0
setup() { setup() {
# shellcheck source=./tests/tests.conf
source "${PWD}/tests/tests.conf" source "${PWD}/tests/tests.conf"
make build >/dev/null make build >/dev/null
DESTDIR="${temp}" make install >/dev/null DESTDIR="${temp}" make install >/dev/null
@ -13,6 +14,7 @@ setup() {
"${temp}${sysconf_dir}/${name}/${name}.conf" "${temp}${sysconf_dir}/${name}/${name}.conf"
install --directory "${temp}${var_dir}/${name}/repositories/test.git" install --directory "${temp}${var_dir}/${name}/repositories/test.git"
install --directory "${temp}${var_dir}/${name}/RPMS" install --directory "${temp}${var_dir}/${name}/RPMS"
# shellcheck source=./conf/errors.conf.sample
source "${errs_file}" source "${errs_file}"
} }
@ -21,7 +23,7 @@ teardown() {
make clean >/dev/null make clean >/dev/null
} }
@test "run with bad arguments" { run_with_bad_arguments() { #@test
run -1 "${runner_bin}" -z run -1 "${runner_bin}" -z
run -1 "${runner_bin}" --zzz run -1 "${runner_bin}" --zzz
run -1 "${runner_bin}" zzz run -1 "${runner_bin}" zzz
@ -35,7 +37,7 @@ teardown() {
run -1 "${runner_bin}" --verbose --quiet run -1 "${runner_bin}" --verbose --quiet
} }
@test "run without loop" { run_without_loop() { #@test
ncat --listen --unixsock "${deployer_sock}" & ncat --listen --unixsock "${deployer_sock}" &
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test "${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
echo "done" | ncat --unixsock "${deployer_sock}" echo "done" | ncat --unixsock "${deployer_sock}"
@ -64,56 +66,56 @@ send_request() (
return "${code}" return "${code}"
) )
@test "run with err_repo_name_missing" { run_with_err_repo_name_missing() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s}')" '{"response_sock":$s}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_name_missing}" echo "status: got ${status:?}, expected ${err_repo_name_missing}"
[ "${status}" -eq "${err_repo_name_missing}" ] [ "${status}" -eq "${err_repo_name_missing}" ]
} }
@test "run with err_repo_name_empty" { run_with_err_repo_name_empty() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"repo_name":""}')" '{"response_sock":$s,"repo_name":""}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_name_empty}" echo "status: got ${status:?}, expected ${err_repo_name_empty}"
[ "${status}" -eq "${err_repo_name_empty}" ] [ "${status}" -eq "${err_repo_name_empty}" ]
} }
@test "run with err_repo_dir_not_exist" { run_with_err_repo_dir_not_exist() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"repo_name":"not_exist"}')" '{"response_sock":$s,"repo_name":"not_exist"}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_dir_not_exist}" echo "status: got ${status:?}, expected ${err_repo_dir_not_exist}"
[ "${status}" -eq "${err_repo_dir_not_exist}" ] [ "${status}" -eq "${err_repo_dir_not_exist}" ]
} }
@test "run with err_repo_hash_missing" { run_with_err_repo_hash_missing() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"repo_name":"test"}')" '{"response_sock":$s,"repo_name":"test"}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_hash_missing}" echo "status: got ${status:?}, expected ${err_repo_hash_missing}"
[ "${status}" -eq "${err_repo_hash_missing}" ] [ "${status}" -eq "${err_repo_hash_missing}" ]
} }
@test "run with err_repo_hash_empty" { run_with_err_repo_hash_empty() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"repo_name":"test","repo_hash":""}')" '{"response_sock":$s,"repo_name":"test","repo_hash":""}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_hash_empty}" echo "status: got ${status:?}, expected ${err_repo_hash_empty}"
[ "${status}" -eq "${err_repo_hash_empty}" ] [ "${status}" -eq "${err_repo_hash_empty}" ]
} }
@test "run with err_repo_tag_empty" { run_with_err_repo_tag_empty() { #@test
request="$(jq --null-input --compact-output \ request="$(jq --null-input --compact-output \
--arg s "${response_sock}" \ --arg s "${response_sock}" \
'{"response_sock":$s,"repo_name":"test","repo_hash":"hash","repo_tag":""}')" '{"response_sock":$s,"repo_name":"test","repo_hash":"hash","repo_tag":""}')"
run send_request "${request}" run send_request "${request}"
echo "status: got ${status}, expected ${err_repo_tag_empty}" echo "status: got ${status:?}, expected ${err_repo_tag_empty}"
[ "${status}" -eq "${err_repo_tag_empty}" ] [ "${status}" -eq "${err_repo_tag_empty}" ]
} }