|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euxo pipefail |
| 4 | + |
| 5 | +cleanup() { |
| 6 | + r=$? |
| 7 | + |
| 8 | + # Dump stack logs |
| 9 | + elastic-package stack dump -v --output "build/elastic-stack-dump/check-${PACKAGE_UNDER_TEST:-${PACKAGE_TEST_TYPE:-*}}" |
| 10 | + |
| 11 | + # Take down the stack |
| 12 | + elastic-package stack down -v |
| 13 | + |
| 14 | + # Clean used resources |
| 15 | + for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do |
| 16 | + ( |
| 17 | + cd $d |
| 18 | + elastic-package clean -v |
| 19 | + ) |
| 20 | + done |
| 21 | + |
| 22 | + # This is a false positive scenario and tests that the test case failure is a success scenario |
| 23 | + if [ "${PACKAGE_TEST_TYPE:-false_positives}" == "false_positives" ]; then |
| 24 | + if [ $r == 1 ]; then |
| 25 | + EXPECTED_ERRORS_FILE="test/packages/false_positives/${PACKAGE_UNDER_TEST}.expected_errors" |
| 26 | + if [ ! -f ${EXPECTED_ERRORS_FILE} ]; then |
| 27 | + echo "Error: Missing expected errors file: ${EXPECTED_ERRORS_FILE}" |
| 28 | + fi |
| 29 | + RESULTS_NO_SPACES="build/test-results-no-spaces.xml" |
| 30 | + cat build/test-results/*.xml | tr -d '\n' > ${RESULTS_NO_SPACES} |
| 31 | + |
| 32 | + # check number of expected errors |
| 33 | + number_errors=$(cat build/test-results/*.xml | grep "<failure>" | wc -l) |
| 34 | + expected_errors=$(cat ${EXPECTED_ERRORS_FILE} | wc -l) |
| 35 | + |
| 36 | + if [ ${number_errors} -ne ${expected_errors} ]; then |
| 37 | + echo "Error: There are unexpected errors in ${PACKAGE_UNDER_TEST}" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + |
| 41 | + # check whether or not the expected errors exist in the xml files |
| 42 | + while read -r line; do |
| 43 | + cat ${RESULTS_NO_SPACES} | grep -E "${line}" |
| 44 | + done < ${EXPECTED_ERRORS_FILE} |
| 45 | + rm -f build/test-results/*.xml |
| 46 | + rm -f ${RESULTS_NO_SPACES} |
| 47 | + exit 0 |
| 48 | + elif [ $r == 0 ]; then |
| 49 | + echo "Error: Expected to fail tests, but there was none failing" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + fi |
| 53 | + |
| 54 | + exit $r |
| 55 | +} |
| 56 | + |
| 57 | +trap cleanup EXIT |
| 58 | + |
| 59 | +export ELASTIC_PACKAGE_LINKS_FILE_PATH="$(pwd)/scripts/links_table.yml" |
| 60 | + |
| 61 | +OLDPWD=$PWD |
| 62 | +# Build/check packages |
| 63 | +for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do |
| 64 | + ( |
| 65 | + cd $d |
| 66 | + elastic-package check -v |
| 67 | + ) |
| 68 | +done |
| 69 | +cd - |
| 70 | + |
| 71 | +# Update the stack |
| 72 | +elastic-package stack update -v |
| 73 | + |
| 74 | +# Boot up the stack |
| 75 | +elastic-package stack up -d -v |
| 76 | + |
| 77 | +elastic-package stack status |
| 78 | + |
| 79 | +# Run package tests |
| 80 | +eval "$(elastic-package stack shellinit)" |
| 81 | + |
| 82 | +for d in test/packages/${PACKAGE_TEST_TYPE:-false_positives}/${PACKAGE_UNDER_TEST:-*}/; do |
| 83 | + ( |
| 84 | + cd $d |
| 85 | + elastic-package install -v |
| 86 | + |
| 87 | + # defer-cleanup is set to a short period to verify that the option is available |
| 88 | + elastic-package test -v --report-format xUnit --report-output file --defer-cleanup 1s --test-coverage |
| 89 | + ) |
| 90 | +cd - |
| 91 | +done |
0 commit comments