Merge pull request #242 from flatcar-linux/t-lo/tapfile-helper-fix-test-output

ci-automation/tapfile_helper_lib.sh: read test output from file
This commit is contained in:
Thilo Fromm 2022-03-02 17:46:10 +01:00 committed by GitHub
commit c94315eeba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,13 +77,13 @@ function __db_init() {
# 3: <run> - re-run iteration
function tap_ingest_tapfile() {
local tapfile="${1}"
local vendor="${2}"
local run="${3}"
local result=""
local test_name=""
local error_message=""
local in_error_message=false
if ! [ -f "${TAPFILE_HELPER_DBNAME}" ] ; then
@ -91,8 +91,16 @@ function tap_ingest_tapfile() {
fi
# Wrap all SQL commands in a transaction to speed up INSERTs
# We will commit intermediately if there's an error message to insert so the
# error message file can be reused.
local SQL="BEGIN TRANSACTION;"
local has_error_message="false"
# run the parse loop in a subshell and clean up temporary error message file on exit
(
local error_message_file="$(mktemp)"
trap "rm -f '${error_message_file}'" EXIT
# Example TAP input:
# ok - coreos.auth.verify
# ok - coreos.locksmith.tls
@ -112,10 +120,13 @@ function tap_ingest_tapfile() {
if $in_error_message ; then
if [ "${line}" = "..." ] ; then
in_error_message=false
has_error_message="true"
else
error_message="$(echo -e "$line" \
echo -e "$line" \
| sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \
| sed -e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g')"
-e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g' \
-e 's/.\{200\}/&\n/g' \
>> "${error_message_file}"
continue
fi
else
@ -128,18 +139,30 @@ function tap_ingest_tapfile() {
fi
fi
local test_output="/dev/null"
if [ "${has_error_message}" = "true" ] ; then
test_output="${error_message_file}"
fi
SQL="${SQL}INSERT OR IGNORE INTO test_case(name) VALUES ('${test_name}');"
SQL="${SQL}INSERT OR IGNORE INTO vendor(name) VALUES ('${vendor}');"
SQL="${SQL}INSERT OR REPLACE INTO test_run(run,result,output,case_id,vendor_id)
VALUES ('${run}','${result}', '${error_message}',
VALUES ('${run}','${result}', readfile('${test_output}'),
(SELECT id FROM test_case WHERE name='${test_name}'),
(SELECT id FROM vendor WHERE name='${vendor}'));"
error_message=""
if [ "${has_error_message}" = "true" ] ; then
SQL="${SQL}COMMIT;"
__sqlite3_wrapper "${SQL}"
truncate --size 0 "${error_message_file}"
has_error_message="false"
SQL="BEGIN TRANSACTION;"
fi
done < "$tapfile"
)
local SQL="${SQL}COMMIT;"
SQL="${SQL}COMMIT;"
__sqlite3_wrapper "${SQL}"
}
# --