From d2156a5b23379ea616ba481e87c24e4e3ebcf257 Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 1 Nov 2019 21:26:48 -0500 Subject: [PATCH] fix(tests): use count flag to check example errors --- examples/kubernetes-resources-none.yml | 3 ++- examples/kubernetes-resources-some.yml | 6 +++--- scripts/test-examples.sh | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/kubernetes-resources-none.yml b/examples/kubernetes-resources-none.yml index c5d5387..9421ea6 100644 --- a/examples/kubernetes-resources-none.yml +++ b/examples/kubernetes-resources-none.yml @@ -1,9 +1,10 @@ # test rules kubernetes # test tags kubernetes -# test exit-status 1 +# test exit-status 2 metadata: name: example + # missing labels spec: template: spec: diff --git a/examples/kubernetes-resources-some.yml b/examples/kubernetes-resources-some.yml index 97f6f40..cf6e7ee 100644 --- a/examples/kubernetes-resources-some.yml +++ b/examples/kubernetes-resources-some.yml @@ -1,9 +1,10 @@ # test rules kubernetes # test tags kubernetes -# test exit-status 1 +# test exit-status 2 metadata: name: example + labels: {} spec: template: spec: @@ -21,6 +22,7 @@ spec: metadata: name: example + labels: {} spec: template: spec: @@ -29,10 +31,8 @@ spec: resources: limits: cpu: 200m - memory: 5Mi requests: cpu: 100m - memory: 2Mi --- diff --git a/scripts/test-examples.sh b/scripts/test-examples.sh index bb2effe..165f8e5 100755 --- a/scripts/test-examples.sh +++ b/scripts/test-examples.sh @@ -12,20 +12,17 @@ do 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 "Using rules: ${USE_RULES}" echo "Using tags: ${USE_TAGS}" - echo "Expected errors: ${EXPECTED_ERRORS}" echo "Expected status: ${EXPECTED_STATUS}" node out/index.js \ --config-path ./docs \ --config-name config-stderr.yml \ + --count \ --rules "rules/${USE_RULES}.yml" \ --tag "${USE_TAGS}" \ --source "${example}" @@ -37,6 +34,7 @@ do if [ "${ACTUAL_STATUS}" != "${EXPECTED_STATUS}" ]; then echo "Exit status does not match! (expected ${EXPECTED_STATUS}, got ${ACTUAL_STATUS})" + echo "Failed in: ${example}" exit 1 fi done