1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/consumer-test/integrationTestController.sh

100 lines
2.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2019-02-27 16:43:12 +02:00
curl -X POST \
--data "{\"state\": \"pending\", \"target_url\": \"${TRAVIS_BUILD_WEB_URL}\", \"description\": \"Integration tests pending.\", \"context\": \"integration-tests\"}" \
--user "${INTEGRATION_TEST_VOTING_USER}:${INTEGRATION_TEST_VOTING_TOKEN}" \
"https://api.github.com/repos/SAP/jenkins-library/statuses/${TRAVIS_PULL_REQUEST_SHA}"
2019-02-27 16:43:12 +02:00
WORKSPACES_ROOT=workspaces
[ -e "${WORKSPACES_ROOT}" ] && rm -rf ${WORKSPACES_ROOT}
TEST_CASES=$(find testCases -name '*.yml')
2019-02-26 17:10:13 +02:00
while true; do sleep 10; echo "[INFO] Integration tests still running."; done &
notificationThreadPid=$!
2019-02-26 17:10:13 +02:00
i=0
for f in ${TEST_CASES}
do
2019-02-26 17:51:47 +02:00
testCase=$(basename "${f%.*}")
area=$(dirname "${f#*/}")
2019-02-26 17:47:31 +02:00
echo "[INFO] Running test case \"${testCase}\" in area \"${area}\"."
TEST_CASE_ROOT="${WORKSPACES_ROOT}/${area}/${testCase}"
[ -e "${TEST_CASE_ROOT}" ] && rm -rf "${TEST_CASE_ROOT}"
mkdir -p "${TEST_CASE_ROOT}"
2019-02-26 17:51:47 +02:00
source ./runTest.sh "${testCase}" "${TEST_CASE_ROOT}" &> "${TEST_CASE_ROOT}/log.txt" &
2019-02-26 17:47:31 +02:00
pid=$!
processes[$i]="${testCase}:${pid}"
echo "[INFO] Test case \"${testCase}\" in area \"${area}\" launched. (PID: \"${pid}\")."
let i=i+1
2019-02-26 17:10:13 +02:00
done
[ "${i}" == 0 ] && { echo "No tests has been executed."; exit 1; }
2019-02-26 17:10:13 +02:00
#
# wait for the test cases and cat the log
for p in "${processes[@]}"
do
2019-02-26 17:47:31 +02:00
testCase=${p%:*}
processId=${p#*:}
echo "[INFO] Waiting for test case \"${testCase}\" (PID: \"${processId}\")."
2019-02-26 17:51:47 +02:00
wait "${processId}"
2019-02-26 17:47:31 +02:00
echo "[INFO] Test case \"${testCase}\" finished (PID: \"${processId}\")."
2019-02-26 17:10:13 +02:00
done
kill -PIPE "${notificationThreadPid}" &>/dev/null
#
# provide the logs
for p in "${processes[@]}"
do
testCase=${p%:*}
processId=${p#*:}
echo "[INFO] === START === Logs for test case \"${testCase}\" ===."
cat "${TEST_CASE_ROOT}/log.txt"
echo "[INFO] === END === Logs for test case \"${testCase}\" ===."
done
2019-02-26 17:10:13 +02:00
#
# list test case status
echo "[INFO] Build status:"
failure="false"
for p in "${processes[@]}"
do
2019-02-26 17:47:31 +02:00
status="UNDEFINED"
testCase=${p%:*}
if [ -f "${TEST_CASE_ROOT}/SUCCESS" ]
then
status="SUCCESS"
else
status="FAILURE"
failure="true"
fi
printf "[INFO] %-30s: %s\n" "${testCase}" ${status}
done
2019-02-26 17:10:13 +02:00
2019-02-27 16:43:12 +02:00
STATUS_DESCRIPTION="The integration tests failed."
STATUS_STATE="failure"
2019-02-26 17:10:13 +02:00
if [ "${failure}" == "true" ]
then
2019-02-26 17:47:31 +02:00
echo "[WARNING] There are test failures. Check earlier log for details."
2019-02-27 16:43:12 +02:00
else
STATUS_DESCRIPTION="The integration tests succeeded."
STATUS_STATE="success"
2019-02-26 17:10:13 +02:00
fi
echo "[INFO] Integration tests succeeded."
2019-02-27 16:43:12 +02:00
curl -X POST \
--data "{\"state\": \"${STATUS_STATE}\", \"target_url\": \"${TRAVIS_BUILD_WEB_URL}\", \"description\": \"${STATUS_DESCRIPTION}\", \"context\": \"integration-tests\"}" \
--user "${INTEGRATION_TEST_VOTING_USER}:${INTEGRATION_TEST_VOTING_TOKEN}" \
"https://api.github.com/repos/SAP/jenkins-library/statuses/${TRAVIS_PULL_REQUEST_SHA}"
2019-02-27 16:43:12 +02:00
if [ "${failure}" == "true" ]
then
exit 1
fi
2019-02-26 17:10:13 +02:00
exit 0