2023-05-10 22:56:10 +00:00
|
|
|
#
|
2023-04-04 13:36:51 +00:00
|
|
|
# Deployer unit tests using BATS framework.
|
|
|
|
#
|
|
|
|
|
|
|
|
bats_require_minimum_version 1.5.0
|
|
|
|
|
|
|
|
setup() {
|
2023-05-10 22:56:10 +00:00
|
|
|
# shellcheck source=./tests/tests.conf
|
2023-04-04 13:36:51 +00:00
|
|
|
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"
|
|
|
|
install --directory "${temp}${var_dir}/${name}/repositories/test.git"
|
|
|
|
install --directory "${temp}${var_dir}/${name}/RPMS"
|
2023-05-10 22:56:10 +00:00
|
|
|
# shellcheck source=./conf/errors.conf.sample
|
2023-04-04 13:36:51 +00:00
|
|
|
source "${errs_file}"
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
rm --recursive --force "${temp}"
|
|
|
|
make clean >/dev/null
|
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_bad_arguments() { #@test
|
2023-04-04 13:36:51 +00:00
|
|
|
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
|
2023-05-10 22:56:10 +00:00
|
|
|
|
2023-04-04 13:36:51 +00:00
|
|
|
run -1 "${runner_bin}" --errs
|
|
|
|
run -1 "${runner_bin}" --errs=/path/to/nowhere
|
2023-05-10 22:56:10 +00:00
|
|
|
|
2023-04-04 13:36:51 +00:00
|
|
|
run -1 "${runner_bin}" --verbose --quiet
|
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_without_loop() { #@test
|
2023-04-04 13:36:51 +00:00
|
|
|
ncat --listen --unixsock "${deployer_sock}" &
|
2023-05-04 00:20:00 +00:00
|
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
2023-04-04 13:36:51 +00:00
|
|
|
echo "done" | ncat --unixsock "${deployer_sock}"
|
|
|
|
}
|
|
|
|
|
|
|
|
send_request() (
|
2023-05-10 22:56:10 +00:00
|
|
|
request="$1"
|
2023-04-04 13:36:51 +00:00
|
|
|
|
|
|
|
ncat --listen --unixsock "${deployer_sock}" &
|
2023-05-10 22:56:10 +00:00
|
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
|
|
|
--daemon --once --verbose start
|
2023-04-25 13:09:32 +00:00
|
|
|
code=$?
|
|
|
|
if [ "${code}" -ne 0 ]; then
|
|
|
|
echo "fail" | ncat --unixsock "${deployer_sock}"
|
2023-05-04 00:20:00 +00:00
|
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
2023-04-25 13:09:32 +00:00
|
|
|
return "${code}"
|
|
|
|
fi
|
2023-05-10 22:56:10 +00:00
|
|
|
(
|
2023-04-30 21:31:43 +00:00
|
|
|
inotifywait --timeout 1 --quiet --quiet \
|
|
|
|
--event create "${response_sock_dir}" >&3
|
2023-05-10 22:56:10 +00:00
|
|
|
echo "${request}" | ncat --unixsock "${runner_sock}"
|
|
|
|
) &
|
2023-04-04 13:36:51 +00:00
|
|
|
echo "done" | ncat --unixsock "${deployer_sock}"
|
2023-05-10 22:56:10 +00:00
|
|
|
code="$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
2023-05-04 00:20:00 +00:00
|
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
|
|
|
return "${code}"
|
2023-04-04 13:36:51 +00:00
|
|
|
)
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_name_missing() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"response_sock":$s}')"
|
|
|
|
run send_request "${request}"
|
|
|
|
echo "status: got ${status:?}, expected ${err_repo_name_missing}"
|
|
|
|
[ "${status}" -eq "${err_repo_name_missing}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_name_empty() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"response_sock":$s,"repo_name":""}')"
|
|
|
|
run send_request "${request}"
|
|
|
|
echo "status: got ${status:?}, expected ${err_repo_name_empty}"
|
|
|
|
[ "${status}" -eq "${err_repo_name_empty}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_dir_not_exist() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"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}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_hash_missing() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"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}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_hash_empty() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"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}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:56:10 +00:00
|
|
|
run_with_err_repo_tag_empty() { #@test
|
|
|
|
request="$(jq --null-input --compact-output \
|
2023-04-04 13:36:51 +00:00
|
|
|
--arg s "${response_sock}" \
|
2023-05-10 22:56:10 +00:00
|
|
|
'{"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}" ]
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|