[Dev] Rewrite tests files to respect shellcheck and shfmt
This commit is contained in:
parent
8958bea96b
commit
08237fc626
7
Makefile
7
Makefile
|
@ -86,12 +86,13 @@ install: conf/*.sample systemd/*.service bin/*
|
|||
|
||||
.PHONY: check_format
|
||||
check_format:
|
||||
shfmt --diff ./src
|
||||
shfmt --diff ./src ./tests
|
||||
|
||||
.PHONY: check_linting
|
||||
check_linting:
|
||||
shfmt --find ./src | xargs bash -o noexec
|
||||
shfmt --find ./src | xargs shellcheck --external-sources
|
||||
shfmt --find ./src ./tests | while read f; do bash -o noexec $$f; done
|
||||
shfmt --find ./src ./tests | while read f; do \
|
||||
shellcheck --external-sources $$f; done
|
||||
|
||||
.PHONY: unit_test
|
||||
unit_test:
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#
|
||||
#
|
||||
# Deployer unit tests using BATS framework.
|
||||
#
|
||||
|
||||
bats_require_minimum_version 1.5.0
|
||||
|
||||
setup() {
|
||||
# shellcheck source=./tests/tests.conf
|
||||
source "${PWD}/tests/tests.conf"
|
||||
make build >/dev/null
|
||||
DESTDIR="${temp}" make install >/dev/null
|
||||
|
@ -13,6 +14,7 @@ setup() {
|
|||
"${temp}${sysconf_dir}/${name}/${name}.conf"
|
||||
install --directory "${temp}${var_dir}/${name}/repositories/test.git"
|
||||
install --directory "${temp}${var_dir}/${name}/RPMS"
|
||||
# shellcheck source=./conf/errors.conf.sample
|
||||
source "${errs_file}"
|
||||
}
|
||||
|
||||
|
@ -21,22 +23,22 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
@test "run with bad arguments" {
|
||||
run_with_bad_arguments() { #@test
|
||||
run -1 "${deployer_bin}" -z test
|
||||
run -1 "${deployer_bin}" --zzz test
|
||||
run -1 "${deployer_bin}" zzz
|
||||
|
||||
run -1 "${deployer_bin}" --conf
|
||||
run -1 "${deployer_bin}" --conf=/path/to/nowhere test
|
||||
|
||||
|
||||
run -1 "${deployer_bin}" --errs
|
||||
run -1 "${deployer_bin}" --errs=/path/to/nowhere test
|
||||
|
||||
|
||||
run -1 "${deployer_bin}" --verbose --quiet test
|
||||
}
|
||||
|
||||
@test "run without loop" {
|
||||
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
||||
run_without_loop() { #@test
|
||||
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
||||
}
|
||||
|
||||
send_request() (
|
||||
|
@ -47,63 +49,63 @@ send_request() (
|
|||
(
|
||||
inotifywait --timeout 1 --quiet --quiet \
|
||||
--event create "${response_sock_dir}" || true
|
||||
echo "${request}" | ncat --unixsock "${deployer_sock}"
|
||||
echo "${request}" | ncat --unixsock "${deployer_sock}"
|
||||
) &
|
||||
code="$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
||||
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
||||
return "${code}"
|
||||
)
|
||||
|
||||
@test "run with err_pkg_name_missing" {
|
||||
run_with_err_pkg_name_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s}')"
|
||||
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}" ]
|
||||
}
|
||||
|
||||
@test "run with err_pkg_name_empty" {
|
||||
run_with_err_pkg_name_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"pkg_name":""}')"
|
||||
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}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_dir_not_exist" {
|
||||
run_with_err_repo_dir_not_exist() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"pkg_name":"not_exist"}')"
|
||||
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}" ]
|
||||
}
|
||||
|
||||
@test "run with err_pkg_version_missing" {
|
||||
run_with_err_pkg_version_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"pkg_name":"test"}')"
|
||||
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}" ]
|
||||
}
|
||||
|
||||
@test "run with err_pkg_version_empty" {
|
||||
run_with_err_pkg_version_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"pkg_name":"test","pkg_version":""}')"
|
||||
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}" ]
|
||||
}
|
||||
|
||||
@test "run with err_rpm_path_not_exist" {
|
||||
run_with_err_rpm_path_not_exist() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"pkg_name":"test","pkg_version":"0.1"}')"
|
||||
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}" ]
|
||||
}
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
bats_require_minimum_version 1.5.0
|
||||
|
||||
setup() {
|
||||
# shellcheck source=./tests/tests.conf
|
||||
source "${PWD}/tests/tests.conf"
|
||||
make build >/dev/null
|
||||
DESTDIR="${temp}" make install >/dev/null
|
||||
install --no-target-directory \
|
||||
"${PWD}/tests/tests.conf" \
|
||||
"${temp}${sysconf_dir}/${name}/${name}.conf"
|
||||
# shellcheck source=./conf/errors.conf.sample
|
||||
source "${errs_file}"
|
||||
}
|
||||
|
||||
|
@ -19,7 +21,7 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
@test "run with bad arguments" {
|
||||
run_with_bad_arguments() { #@test
|
||||
run -1 "${pipeline_bin}"
|
||||
run -1 "${pipeline_bin}" bad_pipeline
|
||||
|
||||
|
@ -39,21 +41,21 @@ teardown() {
|
|||
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}" \
|
||||
--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}" ]
|
||||
}
|
||||
|
||||
@test "run newcommit ok" {
|
||||
run_newcommit_ok() { #@test
|
||||
ncat --listen --unixsock "${runner_sock}" &
|
||||
"${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
||||
--test --hash hash --name name newcommit
|
||||
echo "done" | ncat --unixsock "${runner_sock}"
|
||||
}
|
||||
|
||||
@test "run newtag ok" {
|
||||
run_newtag_ok() { #@test
|
||||
ncat --listen --unixsock "${runner_sock}" &
|
||||
"${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
||||
--test --hash hash --name name --tag tag newtag
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#
|
||||
#
|
||||
# Deployer unit tests using BATS framework.
|
||||
#
|
||||
|
||||
bats_require_minimum_version 1.5.0
|
||||
|
||||
setup() {
|
||||
# shellcheck source=./tests/tests.conf
|
||||
source "${PWD}/tests/tests.conf"
|
||||
make build >/dev/null
|
||||
DESTDIR="${temp}" make install >/dev/null
|
||||
|
@ -13,6 +14,7 @@ setup() {
|
|||
"${temp}${sysconf_dir}/${name}/${name}.conf"
|
||||
install --directory "${temp}${var_dir}/${name}/repositories/test.git"
|
||||
install --directory "${temp}${var_dir}/${name}/RPMS"
|
||||
# shellcheck source=./conf/errors.conf.sample
|
||||
source "${errs_file}"
|
||||
}
|
||||
|
||||
|
@ -21,99 +23,99 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
@test "run with bad arguments" {
|
||||
run_with_bad_arguments() { #@test
|
||||
run -1 "${runner_bin}" -z
|
||||
run -1 "${runner_bin}" --zzz
|
||||
run -1 "${runner_bin}" zzz
|
||||
|
||||
run -1 "${runner_bin}" --conf
|
||||
run -1 "${runner_bin}" --conf=/path/to/nowhere
|
||||
|
||||
|
||||
run -1 "${runner_bin}" --errs
|
||||
run -1 "${runner_bin}" --errs=/path/to/nowhere
|
||||
|
||||
|
||||
run -1 "${runner_bin}" --verbose --quiet
|
||||
}
|
||||
|
||||
@test "run without loop" {
|
||||
run_without_loop() { #@test
|
||||
ncat --listen --unixsock "${deployer_sock}" &
|
||||
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
||||
echo "done" | ncat --unixsock "${deployer_sock}"
|
||||
}
|
||||
|
||||
send_request() (
|
||||
request="$1"
|
||||
request="$1"
|
||||
|
||||
ncat --listen --unixsock "${deployer_sock}" &
|
||||
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
||||
--daemon --once --verbose start
|
||||
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
||||
--daemon --once --verbose start
|
||||
code=$?
|
||||
if [ "${code}" -ne 0 ]; then
|
||||
echo "fail" | ncat --unixsock "${deployer_sock}"
|
||||
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
||||
return "${code}"
|
||||
fi
|
||||
(
|
||||
(
|
||||
inotifywait --timeout 1 --quiet --quiet \
|
||||
--event create "${response_sock_dir}" >&3
|
||||
echo "${request}" | ncat --unixsock "${runner_sock}"
|
||||
) &
|
||||
echo "${request}" | ncat --unixsock "${runner_sock}"
|
||||
) &
|
||||
echo "done" | ncat --unixsock "${deployer_sock}"
|
||||
code="$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
||||
code="$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
||||
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
||||
return "${code}"
|
||||
)
|
||||
|
||||
@test "run with err_repo_name_missing" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_name_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_name_missing}"
|
||||
[ "${status}" -eq "${err_repo_name_missing}" ]
|
||||
'{"response_sock":$s}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_name_missing}"
|
||||
[ "${status}" -eq "${err_repo_name_missing}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_name_empty" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_name_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"repo_name":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_name_empty}"
|
||||
[ "${status}" -eq "${err_repo_name_empty}" ]
|
||||
'{"response_sock":$s,"repo_name":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_name_empty}"
|
||||
[ "${status}" -eq "${err_repo_name_empty}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_dir_not_exist" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_dir_not_exist() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"repo_name":"not_exist"}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_dir_not_exist}"
|
||||
[ "${status}" -eq "${err_repo_dir_not_exist}" ]
|
||||
'{"response_sock":$s,"repo_name":"not_exist"}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_dir_not_exist}"
|
||||
[ "${status}" -eq "${err_repo_dir_not_exist}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_hash_missing" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_hash_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"repo_name":"test"}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_hash_missing}"
|
||||
[ "${status}" -eq "${err_repo_hash_missing}" ]
|
||||
'{"response_sock":$s,"repo_name":"test"}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_hash_missing}"
|
||||
[ "${status}" -eq "${err_repo_hash_missing}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_hash_empty" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_hash_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"repo_name":"test","repo_hash":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_hash_empty}"
|
||||
[ "${status}" -eq "${err_repo_hash_empty}" ]
|
||||
'{"response_sock":$s,"repo_name":"test","repo_hash":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_hash_empty}"
|
||||
[ "${status}" -eq "${err_repo_hash_empty}" ]
|
||||
}
|
||||
|
||||
@test "run with err_repo_tag_empty" {
|
||||
request="$(jq --null-input --compact-output \
|
||||
run_with_err_repo_tag_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
--arg s "${response_sock}" \
|
||||
'{"response_sock":$s,"repo_name":"test","repo_hash":"hash","repo_tag":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_tag_empty}"
|
||||
[ "${status}" -eq "${err_repo_tag_empty}" ]
|
||||
'{"response_sock":$s,"repo_name":"test","repo_hash":"hash","repo_tag":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status:?}, expected ${err_repo_tag_empty}"
|
||||
[ "${status}" -eq "${err_repo_tag_empty}" ]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue