From cce86715962de4aa8d5126a77768224add7fb1dd Mon Sep 17 00:00:00 2001 From: ssube Date: Mon, 1 Jul 2019 08:02:38 -0500 Subject: [PATCH] feat(test): rules and tags pragmas --- examples/kubernetes-resources-high.yml | 2 ++ scripts/test-examples.sh | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/kubernetes-resources-high.yml b/examples/kubernetes-resources-high.yml index 6addd2e..277104e 100644 --- a/examples/kubernetes-resources-high.yml +++ b/examples/kubernetes-resources-high.yml @@ -1,3 +1,5 @@ +# test rules kubernetes +# test tags kubernetes # test exit-status 0 metadata: diff --git a/scripts/test-examples.sh b/scripts/test-examples.sh index 703ff96..fb0eb02 100755 --- a/scripts/test-examples.sh +++ b/scripts/test-examples.sh @@ -3,17 +3,32 @@ EXAMPLES="$(find examples -name '*.yml')" while read -r example; do + echo "Testing: ${example}" + + USE_RULES="$(grep '# test rules' "${example}" | sed 's/# test rules \(.*\)/\1/')" + [[ -z "${USE_RULES}" ]] && echo "Test example must have '# test rules' pragma" && exit 1 + + USE_TAGS="$(grep '# test tags' "${example}" | sed 's/# test tags \(.*\)/\1/')" + [[ -z "${USE_TAGS}" ]] && echo "Test example must have '# test tags' pragma" && exit 1 + + EXPECTED_ERRORS="$(grep '# test error-count' "${example}" | sed 's/# test error-count \([0-9]*\)/\1/')" + [[ -z "${EXPECTED_ERRORS}" ]] && EXPECTED_ERRORS=0 + EXPECTED_STATUS="$(grep '# test exit-status' "${example}" | sed 's/# test exit-status \([0-9]*\)/\1/')" + [[ -z "${EXPECTED_STATUS}" ]] && EXPECTED_STATUS=0 - echo "Testing: ${example} (should be ${EXPECTED_STATUS})" + echo "Using rules: ${USE_RULES}" + echo "Using tags: ${USE_TAGS}" + echo "Expected errors: ${EXPECTED_ERRORS}" + echo "Expected status: ${EXPECTED_STATUS}" - node out/index.js --rules rules/kubernetes.yml --tag kubernetes --source ${example} + node out/index.js --rules rules/${USE_RULES}.yml --tag ${USE_TAGS} --source ${example} ACTUAL_STATUS=$? if [[ ${ACTUAL_STATUS} != ${EXPECTED_STATUS} ]]; then - echo "Status does not match!" + echo "Exit status does not match! (expected ${EXPECTED_STATUS}, got ${ACTUAL_STATUS})" exit 1 fi done <<< "${EXAMPLES}"