2023-04-04 13:36:51 +00:00
|
|
|
#
|
|
|
|
# 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" {
|
2023-05-01 11:27:06 +00:00
|
|
|
run -1 "${deployer_bin}" -z test
|
|
|
|
run -1 "${deployer_bin}" --zzz test
|
2023-04-04 13:36:51 +00:00
|
|
|
run -1 "${deployer_bin}" zzz
|
|
|
|
|
|
|
|
run -1 "${deployer_bin}" --conf
|
2023-05-01 11:27:06 +00:00
|
|
|
run -1 "${deployer_bin}" --conf=/path/to/nowhere test
|
2023-04-04 13:36:51 +00:00
|
|
|
|
|
|
|
run -1 "${deployer_bin}" --errs
|
2023-05-01 11:27:06 +00:00
|
|
|
run -1 "${deployer_bin}" --errs=/path/to/nowhere test
|
2023-04-04 13:36:51 +00:00
|
|
|
|
2023-05-01 11:27:06 +00:00
|
|
|
run -1 "${deployer_bin}" --verbose --quiet test
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "run without loop" {
|
2023-05-01 11:27:06 +00:00
|
|
|
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
2023-04-04 13:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
send_request() (
|
|
|
|
request="$1"
|
|
|
|
|
|
|
|
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
2023-05-01 11:27:06 +00:00
|
|
|
--once --daemon --verbose start || return $?
|
2023-04-04 13:36:51 +00:00
|
|
|
(
|
2023-04-30 21:31:43 +00:00
|
|
|
inotifywait --timeout 1 --quiet --quiet \
|
|
|
|
--event create "${response_sock_dir}" || true
|
2023-04-04 13:36:51 +00:00
|
|
|
echo "${request}" | ncat --unixsock "${deployer_sock}"
|
|
|
|
) &
|
2023-05-01 11:27:06 +00:00
|
|
|
code="$(ncat --listen --unixsock "${response_sock}" | jq .code)"
|
|
|
|
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" stop
|
|
|
|
return "${code}"
|
2023-04-04 13:36:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@test "run with err_pkg_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_pkg_name_missing}"
|
|
|
|
[ "${status}" -eq "${err_pkg_name_missing}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run with err_pkg_name_empty" {
|
|
|
|
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}"
|
|
|
|
[ "${status}" -eq "${err_pkg_name_empty}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run with err_repo_dir_not_exist" {
|
|
|
|
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_existyy}"
|
|
|
|
[ "${status}" -eq "${err_repo_dir_not_exist}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run with err_pkg_version_missing" {
|
|
|
|
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}"
|
|
|
|
[ "${status}" -eq "${err_pkg_version_missing}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run with err_pkg_version_empty" {
|
|
|
|
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}"
|
|
|
|
[ "${status}" -eq "${err_pkg_version_empty}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "run with err_rpm_path_not_exist" {
|
|
|
|
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}"
|
|
|
|
[ "${status}" -eq "${err_rpm_path_not_exist}" ]
|
|
|
|
}
|