Compare commits
No commits in common. "master" and "0.9" have entirely different histories.
7
Makefile
7
Makefile
|
@ -86,13 +86,12 @@ install: conf/*.sample systemd/*.service bin/*
|
|||
|
||||
.PHONY: check_format
|
||||
check_format:
|
||||
shfmt --diff ./src ./tests
|
||||
shfmt --diff ./src
|
||||
|
||||
.PHONY: check_linting
|
||||
check_linting:
|
||||
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
|
||||
shfmt --find ./src | xargs bash -o noexec
|
||||
shfmt --find ./src | xargs shellcheck --external-sources
|
||||
|
||||
.PHONY: unit_test
|
||||
unit_test:
|
||||
|
|
|
@ -10,7 +10,7 @@ Source0: %{name}-%{version}.tar.gz
|
|||
|
||||
BuildArch: x86_64
|
||||
BuildRequires: make
|
||||
Requires: bash,go-toolset,inotify-tools,jq,nmap-ncat,rpm-build,rpmdevtools,ShellCheck,shfmt
|
||||
Requires: bash,inotify-tools,jq,nmap-ncat,rpm-build,rpmdevtools,ShellCheck,shfmt
|
||||
|
||||
%description
|
||||
Netoik Continuous Deployment tool
|
||||
|
|
|
@ -198,9 +198,9 @@ process_request() (
|
|||
fi
|
||||
log_debug "RPM path found at '${rpm_path}'."
|
||||
|
||||
# Upgrade package if already installed.
|
||||
log_debug "Check if pkg '${pkg_name}' is already installed."
|
||||
if rpm --query "${pkg_name}" 1>/dev/null 2>/dev/null; then
|
||||
# Upgrade package if already installed.
|
||||
log_debug "Package '${pkg_name}' already installed, so upgrade to v
|
||||
${pkg_version}"
|
||||
if ! output="$(sudo rpm --upgrade \
|
||||
|
@ -210,15 +210,15 @@ process_request() (
|
|||
return
|
||||
fi
|
||||
log_debug "RPM package '${pkg_name}' upgraded to v${pkg_version}."
|
||||
else
|
||||
# Install package if not already installed.
|
||||
log_debug "Package '${pkg_name}' is not already installed, so install
|
||||
v${pkg_version}."
|
||||
if ! output="$(sudo rpm --install --verbose --hash "${rpm_path}")"; then
|
||||
reply "${err_rpm_install}" \
|
||||
"Cannot install package '${pkg_name}' v${pkg_version}: ${output}."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install package if not already installed.
|
||||
log_debug "Package '${pkg_name}' is not already installed, so install
|
||||
v${pkg_version}."
|
||||
if ! output="$(sudo rpm --install --verbose --hash "${rpm_path}")"; then
|
||||
reply "${err_rpm_install}" \
|
||||
"Cannot install package '${pkg_name}' v${pkg_version}: ${output}."
|
||||
return
|
||||
fi
|
||||
|
||||
# Package deployed.
|
||||
|
@ -246,7 +246,7 @@ process_loop() (
|
|||
|
||||
main() (
|
||||
# Parse arguments.
|
||||
daemonize="false"
|
||||
daemon="false"
|
||||
keep_open="true"
|
||||
config_file="${DEFAULT_CONFIG_FILE}"
|
||||
errors_file="${DEFAULT_ERRORS_FILE}"
|
||||
|
@ -268,7 +268,7 @@ main() (
|
|||
shift 2
|
||||
;;
|
||||
-d | --daemon)
|
||||
daemonize="true"
|
||||
daemon="true"
|
||||
shift
|
||||
;;
|
||||
-e | --errs)
|
||||
|
@ -378,7 +378,7 @@ main() (
|
|||
fail "Variable runner_deployer_username is empty." \
|
||||
"${err_runner_deployer_groupname_empty}"
|
||||
fi
|
||||
if ! getent group "${runner_deployer_groupname}" >/dev/null; then
|
||||
if ! getent group "${runner_deployer_groupname}"; then
|
||||
fail "Runner-deployer group '${runner_deployer_groupname}' does not exist." \
|
||||
"${err_runner_deployer_group_not_exist}"
|
||||
fi
|
||||
|
@ -415,7 +415,7 @@ main() (
|
|||
) &
|
||||
|
||||
# Run process loop in background or foreground.
|
||||
if "${daemonize}"; then
|
||||
if "${daemon}"; then
|
||||
log_info "Run process loop in background."
|
||||
process_loop &
|
||||
echo "$!" >"${deployer_pid}"
|
||||
|
@ -436,20 +436,14 @@ main() (
|
|||
fi
|
||||
pid="$(cat "${deployer_pid}")"
|
||||
rm --force "${deployer_pid}"
|
||||
|
||||
# Kill deployer process.
|
||||
log_info "Kill deployer process with pid '${pid}'."
|
||||
if ! ps -p "${pid}" >/dev/null; then
|
||||
if ! ps -p "${pid}"; then
|
||||
fail "Deployer process with pid='${pid}' is not running." \
|
||||
"${err_deployer_process_not_running}"
|
||||
fi
|
||||
if ! output="$(kill "${pid}" 2>&1 || kill -KILL "${pid}" 2>&1)"; then
|
||||
fail "Cannot kill deployer process: ${output}." \
|
||||
if ! kill "${pid}" || kill -KILL "${pid}"; then
|
||||
fail "Cannot kill deployer process." \
|
||||
"${err_deployer_process_not_killed}"
|
||||
fi
|
||||
|
||||
# Remove deployer sock file.
|
||||
log_info "Remove deployer sock at '${deployer_sock}'."
|
||||
rm --force "${deployer_sock}"
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -259,25 +259,21 @@ main() (
|
|||
echo "${runner_request}" | ncat --unixsock "${runner_sock}"
|
||||
) &
|
||||
|
||||
# Start CI runner.
|
||||
echo -e "Starting CI runner..."
|
||||
# Wait for runner response.
|
||||
cd "${rd_pipeline_sock_dir}"
|
||||
ncat_cmd="ncat --listen --unixsock --keep-open pipeline.sock"
|
||||
if [ "${runner_timeout}" -gt 0 ]; then
|
||||
ncat_cmd="timeout ${runner_timeout} ${ncat_cmd}"
|
||||
response="$(timeout "${runner_timeout}" ncat --listen \
|
||||
--unixsock pipeline.sock)"
|
||||
else
|
||||
response="$(ncat --listen --unixsock pipeline.sock)"
|
||||
fi
|
||||
while read -r response; do
|
||||
echo -e "$(echo "${response}" | jq --raw-output .msg)"
|
||||
code="$(echo "${response}" | jq .code)"
|
||||
[ "${code}" = "null" ] || break
|
||||
done < <($ncat_cmd)
|
||||
pkill --full --exact --parent "$$" "${ncat_cmd}" || true
|
||||
|
||||
# Remove random directory.
|
||||
rm --recursive "${rd_pipeline_sock_dir}"
|
||||
|
||||
# Display response.
|
||||
exit "${code}"
|
||||
echo -e "Response from RUNNER:\n$(echo "${response}" | jq --raw-output .msg)"
|
||||
exit "$(echo "${response}" | jq .code)"
|
||||
)
|
||||
|
||||
main "$@"
|
||||
|
|
142
src/runner.sh
142
src/runner.sh
|
@ -95,29 +95,21 @@ Positional argument ACTION
|
|||
)
|
||||
|
||||
reply() (
|
||||
msg="$1"
|
||||
code="$2"
|
||||
code="$1"
|
||||
msg="$2"
|
||||
|
||||
if [ -z "${code}" ]; then
|
||||
log_info "${msg}"
|
||||
json="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg m "${msg}" \
|
||||
'{"msg":$m}')"
|
||||
if [ "${code}" -gt 0 ]; then
|
||||
log_error "${msg}"
|
||||
else
|
||||
if [ "${code}" -eq 0 ]; then
|
||||
log_info "${msg}"
|
||||
else
|
||||
log_error "${msg}"
|
||||
fi
|
||||
json="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg m "${msg}" \
|
||||
--arg c "${code}" \
|
||||
'{"msg":$m,"code":$c|tonumber}')"
|
||||
log_info "${msg}"
|
||||
fi
|
||||
|
||||
if ! output="$(echo "${json}" | ncat --unixsock "${response_sock}" 2>&1)"; then
|
||||
if ! output="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg c "${code}" \
|
||||
--arg m "${msg}" \
|
||||
'{"code":$c|tonumber,"msg":$m}' |
|
||||
ncat --unixsock "${response_sock}" 2>&1)"; then
|
||||
log_error "Cannot write to sock '${response_sock}': ${output}."
|
||||
fi
|
||||
)
|
||||
|
@ -157,18 +149,17 @@ process_request() (
|
|||
log_debug "Get repo_name from json."
|
||||
if ! repo_name="$(echo "${request}" |
|
||||
jq --raw-output ".repo_name" 2>&1)"; then
|
||||
reply "Cannot parse json '${request}': ${repo_name}." \
|
||||
"${err_json_bad_format}"
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_name}."
|
||||
return
|
||||
fi
|
||||
if [ "${repo_name}" = "null" ]; then
|
||||
reply "Missing key repo_name in '${request}'." \
|
||||
"${err_repo_name_missing}"
|
||||
reply "${err_repo_name_missing}" "Missing key repo_name in '${request}'."
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_name}" ]; then
|
||||
reply "Empty value for key repo_name in '${request}'." \
|
||||
"${err_repo_name_empty}"
|
||||
reply "${err_repo_name_empty}" \
|
||||
"Empty value for key repo_name in '${request}'."
|
||||
return
|
||||
fi
|
||||
log_debug "Got pkg name: '${repo_name}'."
|
||||
|
@ -176,8 +167,7 @@ process_request() (
|
|||
# Get repository folder.
|
||||
repo_dir="${repos_dir}/${repo_name}.git"
|
||||
if [ ! -d "${repo_dir}" ]; then
|
||||
reply "Repository '${repo_dir}' does not exist." \
|
||||
"${err_repo_dir_not_exist}"
|
||||
reply "${err_repo_dir_not_exist}" "Repository '${repo_dir}' does not exist."
|
||||
return
|
||||
fi
|
||||
log_debug "Repository is present at '${repo_dir}'."
|
||||
|
@ -185,31 +175,30 @@ process_request() (
|
|||
# Get repo_hash from json.
|
||||
log_debug "Get repo_hash from json."
|
||||
if ! repo_hash=$(echo "${request}" | jq --raw-output ".repo_hash" 2>&1); then
|
||||
reply "Cannot parse json '${request}': ${repo_hash}." \
|
||||
"${err_json_bad_format}"
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_hash}."
|
||||
return
|
||||
fi
|
||||
if [ "${repo_hash}" = "null" ]; then
|
||||
reply "Missing key repo_hash in '${request}'." \
|
||||
"${err_repo_hash_missing}"
|
||||
reply "${err_repo_hash_missing}" "Missing key repo_hash in '${request}'."
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_hash}" ]; then
|
||||
reply "Empty value for key repo_hash in '${request}'." \
|
||||
"${err_repo_hash_empty}"
|
||||
reply "${err_repo_hash_empty}" \
|
||||
"Empty value for key repo_hash in '${request}'." 1>&2
|
||||
return
|
||||
fi
|
||||
|
||||
# Get repo_tag from json.
|
||||
log_debug "Get repo_tag from json."
|
||||
if ! repo_tag=$(echo "${request}" | jq --raw-output ".repo_tag"); then
|
||||
reply "Cannot parse json '${request}': ${repo_tag}." \
|
||||
"${err_json_bad_format}"
|
||||
reply "${err_json_bad_format}" \
|
||||
"Cannot parse json '${request}': ${repo_tag}."
|
||||
return
|
||||
fi
|
||||
if [ -z "${repo_tag}" ]; then
|
||||
reply "Empty value for key repo_tag in '${request}'." \
|
||||
"${err_repo_tag_empty}"
|
||||
reply "${err_repo_tag_empty}" \
|
||||
"Empty value for key repo_tag in '${request}'."
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -218,72 +207,66 @@ process_request() (
|
|||
[ "${repo_tag}" != "null" ] && repo_id="${repo_tag}"
|
||||
rand="$(echo "${RANDOM}" | md5sum | head --bytes 7)"
|
||||
repo_clone="${runner_cloning_dir}/${repo_name}-${repo_id}-${rand}"
|
||||
reply "Cloning repo '${repo_name}'..."
|
||||
if ! output="$(git clone "${repo_dir}" "${repo_clone}" 2>&1)"; then
|
||||
reply "Cannot clone repo '${repo_name}': ${output}." \
|
||||
"${err_clone_repo}"
|
||||
log_info "Clone '$repo_name'."
|
||||
if ! output="$(git clone "$repo_dir" "$repo_clone" 2>&1)"; then
|
||||
reply "${err_clone_repo}" "Cannot clone repo '${repo_name}': ${output}."
|
||||
return
|
||||
fi
|
||||
cd "$repo_clone"
|
||||
|
||||
# Checkout git hash.
|
||||
reply "Checkouting hash '${repo_hash}..."
|
||||
log_info "Checkout hash $repo_hash."
|
||||
if ! output="$(git checkout "$repo_hash" 2>&1)"; then
|
||||
reply "Cannot checkout hash '${repo_hash}': ${output}." \
|
||||
"${err_checkout_hash}"
|
||||
reply "${err_checkout_hash}" \
|
||||
"Cannot checkout hash '${repo_hash}': ${output}."
|
||||
return
|
||||
fi
|
||||
|
||||
# Check code validity.
|
||||
reply "Checking code format..."
|
||||
log_info "Check code validity."
|
||||
if ! output="$(make check_format 2>&1)"; then
|
||||
reply "Check format error: ${output}." "${err_check_format}"
|
||||
reply "${err_check_format}" "Check format error: ${output}."
|
||||
return
|
||||
fi
|
||||
reply "Checking code linting..."
|
||||
if ! output="$(make check_linting 2>&1)"; then
|
||||
reply "Check linting error: ${output}." "${err_check_linting}"
|
||||
reply "${err_check_linting}" "Check linting error: ${output}."
|
||||
return
|
||||
fi
|
||||
reply "Running unit tests..."
|
||||
if ! output="$(make unit_test 2>&1)"; then
|
||||
reply "Unit test error: ${output}." "${err_unit_test}"
|
||||
reply "${err_unit_test}" "Unit test error: ${output}."
|
||||
return
|
||||
fi
|
||||
|
||||
# Stop now if no tag specified.
|
||||
if [ "$repo_tag" = "null" ]; then
|
||||
reply "Hash '${repo_hash}' OK for repo '${repo_name}'." 0
|
||||
reply 0 "Hash '${repo_hash}' OK for repo '${repo_name}'."
|
||||
return
|
||||
fi
|
||||
|
||||
# Build rpm package.
|
||||
reply "Adding tag '${repo_tag}'..."
|
||||
echo "Build RPM package."
|
||||
if ! output="$(git tag --message="$repo_tag" "$repo_tag" 2>&1)"; then
|
||||
reply "Cannot add git tag '${repo_tag}': ${output}." "${err_add_tag}"
|
||||
reply "${err_add_tag}" "Cannot add git tag '${repo_tag}': ${output}."
|
||||
return
|
||||
fi
|
||||
reply "Making source tarball..."
|
||||
if ! output="$(make tarball 2>&1)"; then
|
||||
reply "Cannot make tarball for tag '${repo_tag}': ${output}." \
|
||||
"${err_make_tarball}"
|
||||
reply "${err_make_tarball}" \
|
||||
"Cannot make tarball for tag '${repo_tag}': ${output}."
|
||||
return
|
||||
fi
|
||||
repo_version="$(make version)"
|
||||
reply "Building RPM package '${repo_name}' v${repo_version}..."
|
||||
if ! output="$(rpmbuild -bb "$repo_name.spec" 2>&1)"; then
|
||||
reply "Cannot build rpm for tag '${repo_tag}': ${output}." \
|
||||
"${err_rpm_build}"
|
||||
reply "${err_rpm_build}" \
|
||||
"Cannot build rpm for tag '${repo_tag}': ${output}."
|
||||
return
|
||||
fi
|
||||
|
||||
# Deploy rpm package.
|
||||
reply "Deploying RPM package '${repo_name}' v${repo_version}..."
|
||||
log_info "Deploy RPM package."
|
||||
deployer_request="$(jq --null-input \
|
||||
--compact-output \
|
||||
--arg s "${repo_clone}/runner.sock" \
|
||||
--arg n "${repo_name}" \
|
||||
--arg v "${repo_version}" \
|
||||
--arg v "$(make version)" \
|
||||
'{"response_sock":$s,"pkg_name":$n,"pkg_version":$v}')"
|
||||
(
|
||||
inotifywait --timeout 1 --quiet --quiet \
|
||||
|
@ -450,6 +433,10 @@ main() (
|
|||
fail "Directory of runner_sock='${runner_sock}' is not writable." \
|
||||
"${err_runner_sock_dir_not_writable}"
|
||||
fi
|
||||
if [ -e "${runner_sock}" ]; then
|
||||
fail "Sock deployer_sock='${runner_sock}' is already in use." \
|
||||
"${err_runner_sock_already_in_use}"
|
||||
fi
|
||||
|
||||
if [ -z "${runner_cloning_dir}" ]; then
|
||||
fail "Variable runner_cloning_dir is empty." \
|
||||
|
@ -487,7 +474,7 @@ main() (
|
|||
if [ -z "${runner_deployer_groupname}" ]; then
|
||||
fail "Variable runner_deployer_groupname is empty." "${err_runner_deployer_groupname_empty}"
|
||||
fi
|
||||
if ! getent group "${runner_deployer_groupname}" >/dev/null; then
|
||||
if ! getent group "${runner_deployer_groupname}"; then
|
||||
fail "Runner-deployer group '${runner_deployer_groupname}' does not exist." \
|
||||
"${err_runner_deployer_group_not_exist}"
|
||||
fi
|
||||
|
@ -495,7 +482,7 @@ main() (
|
|||
if [ -z "${git_runner_groupname}" ]; then
|
||||
fail "Variable git_runner_groupname is empty." "${err_git_runner_groupname_empty}"
|
||||
fi
|
||||
if ! getent group "${git_runner_groupname}" >/dev/null; then
|
||||
if ! getent group "${git_runner_groupname}"; then
|
||||
fail "Git-runner group '${git_runner_groupname}' does not exist." \
|
||||
"${err_git_runner_group_not_exist}"
|
||||
fi
|
||||
|
@ -514,20 +501,11 @@ main() (
|
|||
|
||||
# Run chosen action.
|
||||
case "${action}" in
|
||||
test)
|
||||
# Stop now if we are only testing.
|
||||
log_info "Configuration OK."
|
||||
exit 0
|
||||
;;
|
||||
start)
|
||||
if [ ! -S "${deployer_sock}" ]; then
|
||||
fail "Sock deployer_sock='${deployer_sock}' does not exist." \
|
||||
"${err_deployer_sock_not_exist}"
|
||||
fi
|
||||
if [ -e "${runner_sock}" ]; then
|
||||
fail "Sock deployer_sock='${runner_sock}' is already in use." \
|
||||
"${err_runner_sock_already_in_use}"
|
||||
fi
|
||||
|
||||
# Set right access in background after nc listen.
|
||||
(
|
||||
|
@ -559,22 +537,20 @@ main() (
|
|||
fi
|
||||
pid="$(cat "${runner_pid}")"
|
||||
rm --force "${runner_pid}"
|
||||
|
||||
# Kill runner process.
|
||||
log_info "Kill runner process with pid '${pid}'."
|
||||
if ! ps -p "${pid}" >/dev/null; then
|
||||
if ! ps -p "${pid}"; then
|
||||
fail "Runner process with pid='${pid}' is not running." \
|
||||
"${err_runner_process_not_running}"
|
||||
fi
|
||||
if ! output="$(kill "${pid}" || kill -KILL "${pid}")"; then
|
||||
fail "Cannot kill runner process: ${output}." \
|
||||
"${err_runner_process_not_killed}"
|
||||
if ! kill "${pid}" || kill -KILL "${pid}"; then
|
||||
fail "Cannot kill runner process." "${err_runner_process_not_killed}"
|
||||
fi
|
||||
|
||||
# Remove runner sock file.
|
||||
log_info "Remove runner sock at '${runner_sock}'."
|
||||
rm --force "${runner_sock}"
|
||||
;;
|
||||
test)
|
||||
# Stop now if we are only testing.
|
||||
log_info "Configuration OK."
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#
|
||||
#
|
||||
# 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
|
||||
|
@ -14,7 +13,6 @@ 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}"
|
||||
}
|
||||
|
||||
|
@ -23,22 +21,22 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
run_with_bad_arguments() { #@test
|
||||
@test "run with bad arguments" {
|
||||
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
|
||||
}
|
||||
|
||||
run_without_loop() { #@test
|
||||
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
||||
@test "run without loop" {
|
||||
"${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" --verbose test
|
||||
}
|
||||
|
||||
send_request() (
|
||||
|
@ -49,63 +47,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}"
|
||||
)
|
||||
|
||||
run_with_err_pkg_name_missing() { #@test
|
||||
@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}"
|
||||
echo "status: got ${status}, expected ${err_pkg_name_missing}"
|
||||
[ "${status}" -eq "${err_pkg_name_missing}" ]
|
||||
}
|
||||
|
||||
run_with_err_pkg_name_empty() { #@test
|
||||
@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}"
|
||||
echo "status: got ${status}, expected ${err_pkg_name_empty}"
|
||||
[ "${status}" -eq "${err_pkg_name_empty}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_dir_not_exist() { #@test
|
||||
@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_exist}"
|
||||
echo "status: got ${status}, expected ${err_repo_dir_not_exist}"
|
||||
[ "${status}" -eq "${err_repo_dir_not_exist}" ]
|
||||
}
|
||||
|
||||
run_with_err_pkg_version_missing() { #@test
|
||||
@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}"
|
||||
echo "status: got ${status}, expected ${err_pkg_version_missing}"
|
||||
[ "${status}" -eq "${err_pkg_version_missing}" ]
|
||||
}
|
||||
|
||||
run_with_err_pkg_version_empty() { #@test
|
||||
@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}"
|
||||
echo "status: got ${status}, expected ${err_pkg_version_empty}"
|
||||
[ "${status}" -eq "${err_pkg_version_empty}" ]
|
||||
}
|
||||
|
||||
run_with_err_rpm_path_not_exist() { #@test
|
||||
@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}"
|
||||
echo "status: got ${status}, expected ${err_rpm_path_not_exist}"
|
||||
[ "${status}" -eq "${err_rpm_path_not_exist}" ]
|
||||
}
|
||||
|
|
|
@ -5,14 +5,12 @@
|
|||
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}"
|
||||
}
|
||||
|
||||
|
@ -21,7 +19,7 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
run_with_bad_arguments() { #@test
|
||||
@test "run with bad arguments" {
|
||||
run -1 "${pipeline_bin}"
|
||||
run -1 "${pipeline_bin}" bad_pipeline
|
||||
|
||||
|
@ -41,21 +39,21 @@ run_with_bad_arguments() { #@test
|
|||
run -1 "${pipeline_bin}" -e /path/to/nowhere -H hash -n name newcommit
|
||||
}
|
||||
|
||||
run_without_runner_sock() { #@test
|
||||
@test "run without runner sock" {
|
||||
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}" ]
|
||||
}
|
||||
|
||||
run_newcommit_ok() { #@test
|
||||
@test "run newcommit ok" {
|
||||
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}"
|
||||
}
|
||||
|
||||
run_newtag_ok() { #@test
|
||||
@test "run newtag ok" {
|
||||
ncat --listen --unixsock "${runner_sock}" &
|
||||
"${pipeline_bin}" --conf="${conf_file}" --errs="${errs_file}" \
|
||||
--test --hash hash --name name --tag tag newtag
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#
|
||||
#
|
||||
# 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
|
||||
|
@ -14,7 +13,6 @@ 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}"
|
||||
}
|
||||
|
||||
|
@ -23,99 +21,99 @@ teardown() {
|
|||
make clean >/dev/null
|
||||
}
|
||||
|
||||
run_with_bad_arguments() { #@test
|
||||
@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
|
||||
}
|
||||
|
||||
run_without_loop() { #@test
|
||||
@test "run without loop" {
|
||||
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}"
|
||||
)
|
||||
|
||||
run_with_err_repo_name_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"response_sock":$s}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_name_missing}"
|
||||
[ "${status}" -eq "${err_repo_name_missing}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_name_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"response_sock":$s,"repo_name":""}')"
|
||||
run send_request "${request}"
|
||||
echo "status: got ${status}, expected ${err_repo_name_empty}"
|
||||
[ "${status}" -eq "${err_repo_name_empty}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_dir_not_exist() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"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}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_hash_missing() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"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}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_hash_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"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}" ]
|
||||
}
|
||||
|
||||
run_with_err_repo_tag_empty() { #@test
|
||||
request="$(jq --null-input --compact-output \
|
||||
@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}" ]
|
||||
'{"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