Skip to content

Commit

Permalink
fix(tests): use count flag to check example errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Nov 3, 2019
1 parent e05d429 commit d2156a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion 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:
Expand Down
6 changes: 3 additions & 3 deletions 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:
Expand All @@ -21,6 +22,7 @@ spec:

metadata:
name: example
labels: {}
spec:
template:
spec:
Expand All @@ -29,10 +31,8 @@ spec:
resources:
limits:
cpu: 200m
memory: 5Mi
requests:
cpu: 100m
memory: 2Mi

---

Expand Down
6 changes: 2 additions & 4 deletions scripts/test-examples.sh
Expand Up @@ -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}"
Expand All @@ -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
Expand Down

0 comments on commit d2156a5

Please sign in to comment.