Commit 2f792147 authored by Lukáš Bařinka's avatar Lukáš Bařinka
Browse files

Add ability to test locally

parent 7ee8cd4c
No related merge requests found
Pipeline #33849 passed with stage
in 30 seconds
Showing with 117 additions and 28 deletions
+117 -28
build 100644 → 100755
#!/bin/bash
docker() { podman "$@"; }
err() { printf -- '%s[error]: %s\n' "$0" "$@" >&2; exit 2; }
url="$( git remote get-url origin )"
......
run 100644 → 100755
#!/bin/bash
docker() { podman "$@"; }
files=( httpd.conf )
declare -i f=${#files[*]}
sanity_check() {
for file in "${files[@]}"; do
[ -f "$file" ] && f=f-1 || echo "File: '$file' missing" >&2
done
return "$f"
}
sanity_check || { echo "Sanity check failed! Are you in the directory with the solution?" >&2; exit 1; }
tmp=$( mktemp )
name=${tmp##*.}
......@@ -71,19 +82,33 @@ rm -rf "${PROJECT}/.results" 2>/dev/null
mkdir "${PROJECT}/.results" \
|| err "Unable to create '${PROJECT}/.results' directory"
docker run -dit --name "${name}" "${image}" /bin/bash
docker cp ~/.ssh/id_rsa "${name}":/root/.ssh/
docker cp ~/.ACADEMY_GITLAB_ACCESS_TOKEN "${name}":/root/
docker cp "${DIR}/run-local-academy" "${name}":/
docker cp "${PROJECT}/." "${name}":/project
[[ -n "${ACADEMY}" ]] \
&& docker cp "${ACADEMY}/." "${name}":/academy
docker exec -it "${name}" /run-local-academy "${command}"
docker cp "${name}":/project/.results/. "${PROJECT}/.results/"
docker run -dit \
--name "${name}" \
-v "$PWD:/mnt" \
-v "$DIR/test:/root/.bashrc" \
-v "$PWD/httpd.conf:/usr/local/apache2/conf/httpd.conf" \
-v "$PWD/htaccess:/var/www/main/users/alice/data/.htaccess" \
--add-host 'www.mycorp.net:127.0.0.2' \
--add-host 'mycorp.net:127.0.0.2' \
--add-host 'www.nocorp.net:127.0.0.3' \
--add-host 'nocorp.net:127.0.0.3' \
--add-host 'www.othercorp1.net:127.0.0.4' \
--add-host 'www.othercorp2.net:127.0.0.4' \
--add-host 'www.othercorp3.net:127.0.0.4' \
"${image}" \
bash
#docker cp ~/.ssh/id_rsa "${name}":/root/.ssh/
#docker cp ~/.ACADEMY_GITLAB_ACCESS_TOKEN "${name}":/root/
#docker cp "${DIR}/run-local-academy" "${name}":/
#docker cp "${PROJECT}/." "${name}":/project
#[[ -n "${ACADEMY}" ]] \
#&& docker cp "${ACADEMY}/." "${name}":/academy
#docker exec -it "${name}" /run-local-academy "${command}"
#docker cp "${name}":/project/.results/. "${PROJECT}/.results/"
#echo "${name}"
#exit
#docker attach "$name"
docker attach "$name"
docker kill "${name}" &>/dev/null
rm "${tmp}"
#!/bin/bash
export ACADEMY
export ACADEMY_DIR='/academy'
export ACADEMY_LANG="gallery"
export ACADEMY_EDITABLE="@([01][0-9]-*|showreel)/@(render[123].jpg|video.mp4)"
export CI_SERVER_HOST="gitlab.wr.cz"
ACADEMY_BRANCH='lb'
ACADEMY="${ACADEMY_DIR}/local-academy-shell"
gitlab='gitlab.wr.cz'
ACADEMY_REPO='https://github.com/InternetGuru/academy'
ssh-keygen -F "${gitlab}" 2>/dev/null || ssh-keyscan "${gitlab}" >> ~/.ssh/known_hosts 2>/dev/null
[[ -f "${ACADEMY_DIR}/academy" ]] \
|| git clone --single-branch --branch "${ACADEMY_BRANCH}" "${ACADEMY_REPO}" "${ACADEMY_DIR}"
"${ACADEMY}" "${1}"
test 0 → 100755
cd /mnt
################################################
badge_generate() { printf -v x '%60s'; printf '%s\n' "${x// /-}" "$*"; }
badge_init() { :; }
################################################
export LANG=C LC_ALL=C
shopt -s nullglob
HOST='http://localhost'
badge_init 'Tests'
info() {
printf '%s[info]: %s\n' "${0##*/}" "$*" >&2
}
err() {
printf '%s[error]: %s\n' "${0##*/}" "$*" >&2
exit 2
}
test_results() {
printf '%s[test]: %-30s\t[ %s ]\n' "${0##*/}" "${task} ${test_id}: ${1}" "${2}" >&2
}
url() {
case "${1}" in
/*) url="${HOST}${1// /}";;
*) url="${1// /}"
esac
}
equal() {
local test_name="${1}"
local expected="${2}"
local tested="${3}"
(( total++ ))
if [[ "${expected}" == "${tested}" ]]; then
test_results "${test_name}" "OK"
(( passed++ ))
else
test_results "${test_name}" "FAILED"
diff -s <( printf -- '%s\n' "${expected}" ) <( printf -- '%s\n' "${tested}" )
fi
}
test_status() {
equal 'Status' \
"$( sed -n '1p' "${test%_*}_s" )" \
"$( sed -n '1p' <<< "${output}" )"
}
test_headers() {
equal 'Headers' \
"$( sort "${test%_*}_h" )" \
"$( sed -n '2,/^$/p' <<< "${output}" | grep -f <( sed 's,^\([^:]*: \).*,^\1,' "${test%_*}_h" ) | sort )"
}
test_content() {
equal 'Content' \
"$( < "${test%_*}_c" )" \
"$( sed '1,/^$/d' <<< "${output}" )"
}
evaluate() {
local total=0
local passed=0
local output
local url
for test in .test*_url; do
[[ "${test}" =~ ([[:alnum:]:]+)_[^_]*$ ]]
test_id="${BASH_REMATCH[1]}"
url "$( < ${test} )"
output="$( curl -is "${url}" | tr -d '\r\0' )"
[[ -f "${test%_*}_s" ]] && test_status
[[ -f "${test%_*}_h" ]] && test_headers
[[ -f "${test%_*}_c" ]] && test_content
done
badge_generate "Tests" "${passed}/${total}"
}
# Start webserver
httpd && echo Webserver started || echo Webeserver error
# Run tests...
evaluate
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment