From 0c7d4428a34a54d71469f8e792fbc46b006de6d6 Mon Sep 17 00:00:00 2001 From: ssube Date: Mon, 1 Jul 2019 07:50:34 -0500 Subject: [PATCH] feat(test): start adding pragma-based tests to examples --- examples/kubernetes-resources-high.yml | 3 +++ scripts/test-examples.sh | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100755 scripts/test-examples.sh diff --git a/examples/kubernetes-resources-high.yml b/examples/kubernetes-resources-high.yml index ed520f4..6addd2e 100644 --- a/examples/kubernetes-resources-high.yml +++ b/examples/kubernetes-resources-high.yml @@ -1,5 +1,8 @@ +# test exit-status 0 + metadata: name: example + labels: {} spec: template: spec: diff --git a/scripts/test-examples.sh b/scripts/test-examples.sh new file mode 100755 index 0000000..703ff96 --- /dev/null +++ b/scripts/test-examples.sh @@ -0,0 +1,24 @@ +# for each file in examples +EXAMPLES="$(find examples -name '*.yml')" + +while read -r example; +do + EXPECTED_STATUS="$(grep '# test exit-status' "${example}" | sed 's/# test exit-status \([0-9]*\)/\1/')" + + echo "Testing: ${example} (should be ${EXPECTED_STATUS})" + + node out/index.js --rules rules/kubernetes.yml --tag kubernetes --source ${example} + + ACTUAL_STATUS=$? + + if [[ ${ACTUAL_STATUS} != ${EXPECTED_STATUS} ]]; + then + echo "Status does not match!" + exit 1 + fi +done <<< "${EXAMPLES}" +# read pragmas: +# rules +# tags + +# run \ No newline at end of file