116 lines
3.4 KiB
Bash
116 lines
3.4 KiB
Bash
#
|
|
# Deployer unit tests using BATS framework.
|
|
#
|
|
|
|
bats_require_minimum_version 1.5.0
|
|
|
|
setup() {
|
|
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"
|
|
source "${errs_file}"
|
|
}
|
|
|
|
teardown() {
|
|
rm --recursive --force "${temp}"
|
|
make clean >/dev/null
|
|
}
|
|
|
|
@test "run with bad arguments" {
|
|
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" {
|
|
ncat --listen --unixsock "${deployer_sock}" &
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" --test --verbose
|
|
echo "done" | ncat --unixsock "${deployer_sock}"
|
|
}
|
|
|
|
send_request() (
|
|
request="$1"
|
|
|
|
ncat --listen --unixsock "${deployer_sock}" &
|
|
"${runner_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
|
--daemon --once --verbose
|
|
code=$?
|
|
if [ "${code}" -ne 0 ]; then
|
|
echo "fail" | ncat --unixsock "${deployer_sock}"
|
|
return "${code}"
|
|
fi
|
|
(
|
|
inotifywait --quiet --quiet --event create "${response_sock_dir}"
|
|
echo "${request}" | ncat --unixsock "${runner_sock}"
|
|
) &
|
|
echo "done" | ncat --unixsock "${deployer_sock}"
|
|
return "$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
|
)
|
|
|
|
@test "run with err_repo_name_missing" {
|
|
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}" ]
|
|
}
|
|
|
|
@test "run with err_repo_name_empty" {
|
|
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}" ]
|
|
}
|
|
|
|
@test "run with err_repo_dir_not_exist" {
|
|
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}" ]
|
|
}
|
|
|
|
@test "run with err_repo_hash_missing" {
|
|
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}" ]
|
|
}
|
|
|
|
@test "run with err_repo_hash_empty" {
|
|
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}" ]
|
|
}
|
|
|
|
@test "run with err_repo_tag_empty" {
|
|
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}" ]
|
|
}
|