Skip to content

Commit 01de50f

Browse files
committed
Group tests by chart for clarity, rename outputs for when searching templates
1 parent c106b23 commit 01de50f

26 files changed

+93
-51
lines changed

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ show: ## show the starting template without installing it
2929

3030
CHARTS=$(shell find . -type f -iname 'Chart.yaml' -exec dirname "{}" \; | sed -e 's/.\///')
3131
test: ## run helm tests
32-
# Test that all values used by the chart are in values.yaml with the same defaults as the pattern
33-
@for t in $(CHARTS); do common/scripts/test.sh $$t naked ""; if [ $$? != 0 ]; then exit 1; fi; done
34-
# Test the charts as the pattern would drive them
35-
@for t in $(CHARTS); do common/scripts/test.sh $$t normal "$(TEST_OPTS) $(PATTERN_OPTS)"; if [ $$? != 0 ]; then exit 1; fi; done
32+
@for t in $(CHARTS); do common/scripts/test.sh $$t all "$(TEST_OPTS) $(PATTERN_OPTS)"; if [ $$? != 0 ]; then exit 1; fi; done
3633

3734
helmlint: ## run helm lint
3835
@for t in $(CHARTS); do helm lint $(TEST_OPTS) $(PATTERN_OPTS) $$t; if [ $$? != 0 ]; then exit 1; fi; done

scripts/test.sh

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,93 @@ unset KUBECONFIG
77

88
target=$1
99
name=$(echo $1 | sed -e s@/@-@g -e s@charts-@@)
10-
TEST_VARIANT="$2"
11-
CHART_OPTS="$3"
12-
13-
TESTDIR=tests
14-
REFERENCE=${TESTDIR}/${name}-${TEST_VARIANT}.expected.yaml
15-
OUTPUT=${TESTDIR}/.${name}-${TEST_VARIANT}.expected.yaml
16-
#REFERENCE=${TESTDIR}/${name}.expected.yaml
17-
#OUTPUT=${TESTDIR}/.${name}.expected.yaml
18-
19-
echo "Testing $1 chart (${TEST_VARIANT})" >&2
20-
helm template --kubeconfig /tmp/doesnotexistever $target --name-template $name ${CHART_OPTS} > ${OUTPUT}
21-
rc=$?
22-
if [ $rc -ne 0 ]; then
23-
echo "FAIL on helm template $target --name-template $name ${CHART_OPTS}"
24-
exit 1
25-
fi
26-
if [ ! -e ${REFERENCE} ]; then
27-
cp ${OUTPUT} ${REFERENCE}
28-
fi
29-
diff -u ${REFERENCE} ${OUTPUT}
30-
rc=$?
3110

32-
if [ $TEST_VARIANT = normal -a $rc = 0 ]; then
11+
function doTest() {
12+
TEST_VARIANT=$1
13+
CHART_OPTS="$2"
14+
TESTDIR=tests
15+
TEST=${name}-${TEST_VARIANT}
16+
FILENAME=${TEST}.expected.yml
17+
OUTPUT=${TESTDIR}/.${FILENAME}
18+
REFERENCE=${TESTDIR}/${FILENAME}
19+
20+
echo "Testing $name chart (${TEST_VARIANT})" >&2
21+
helm template --kubeconfig /tmp/doesnotexistever $target --name-template $name ${CHART_OPTS} > ${OUTPUT}
22+
rc=$?
23+
if [ $rc -ne 0 ]; then
24+
echo "FAIL on helm template $target --name-template $name ${CHART_OPTS}"
25+
exit 1
26+
fi
27+
if [ ! -e ${REFERENCE} ]; then
28+
cp ${OUTPUT} ${REFERENCE}
29+
echo -e "\n\n#### Created test output\007\n#### Now add ${REFERENCE} to Git\n\n\007"
30+
exit 2
31+
fi
32+
diff -u ${REFERENCE} ${OUTPUT}
33+
rc=$?
34+
if [ $rc = 0 ]; then
35+
rm -f ${TESTDIR}/.${name}.*
36+
echo -e "PASS on $name $TEST_VARIANT with opts [$CHART_OPTS]\n"
37+
else
38+
echo -e "FAIL on $name $TEST_VARIANT with opts [$CHART_OPTS]\n"
39+
exit $rc
40+
fi
41+
}
42+
43+
function doTestCompare() {
44+
TEST_VARIANT="differences"
45+
TESTDIR=tests
46+
TEST=${name}
47+
FILENAME=${TEST}.expected.yml
48+
OUTPUT=${TESTDIR}/.${FILENAME}
49+
REFERENCE=${TESTDIR}/${FILENAME}
50+
51+
echo "Testing $name chart (${TEST_VARIANT})" >&2
3352
# Another method of finding variables missing from values.yaml, eg.
3453
# - name: -datacenter
3554
# + name: pattern-name-datacenter
36-
diff -u ${TESTDIR}/${name}-naked.expected.yaml ${TESTDIR}/${name}-normal.expected.yaml | sed 's/20[0-9][0-9]-[09][0-9].*//' > ${OUTPUT}.variant
3755

38-
if [ ! -e ${REFERENCE}.variant ]; then
39-
cp ${OUTPUT}.variant ${REFERENCE}.variant
56+
TEST=${name}
57+
FILENAME=${TEST}.expected.diff
58+
OUTPUT=${TESTDIR}/.${FILENAME}
59+
REFERENCE=${TESTDIR}/${FILENAME}
60+
61+
# Drop the date from the diff output, it will not be stable
62+
diff -u ${TESTDIR}/${name}-naked.expected.yml ${TESTDIR}/${name}-normal.expected.yml | sed 's/\.yml.*20[0-9][0-9].*/.yml/g' > ${OUTPUT}
63+
64+
if [ ! -e ${REFERENCE} ]; then
65+
cp ${OUTPUT} ${REFERENCE}
66+
echo -e "\n\n#### Created test output\007\n#### Now add ${REFERENCE} to Git\n\n\007"
67+
exit 2
4068
fi
4169

42-
diff -u ${REFERENCE}.variant ${OUTPUT}.variant
70+
diff -u ${REFERENCE} ${OUTPUT}
4371
rc=$?
44-
fi
4572

46-
if [ $rc = 0 ]; then
47-
rm -f ${OUTPUT}
48-
rm -f ${OUTPUT}.variant
49-
echo "PASS on $target $TEST_VARIANT with opts [$CHART_OPTS]"
73+
if [ $rc = 0 ]; then
74+
rm -f ${TESTDIR}/.${name}.*
75+
echo -e "PASS on $name $TEST_VARIANT with opts [$CHART_OPTS]\n"
76+
else
77+
echo -e "FAIL on $name $TEST_VARIANT with opts [$CHART_OPTS]\n"
78+
exit $rc
79+
fi
80+
}
81+
82+
if [ $2 = "all" ]; then
83+
echo -e "\n#####################"
84+
echo -e "### ${name}"
85+
echo -e "#####################\n"
86+
87+
# Test that all values used by the chart are in values.yaml with the same defaults as the pattern
88+
doTest naked
89+
90+
# Test the charts as the pattern would drive them
91+
doTest normal "$3"
92+
93+
# Ensure the differences between the two results are also stable
94+
doTestCompare
5095
else
51-
echo "FAIL on $target $TEST_VARIANT with opts [$CHART_OPTS]"
96+
doTest $2 "$3"
5297
fi
5398

54-
exit $rc
99+
exit 0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- tests/acm-naked.expected.yaml
2-
+++ tests/acm-normal.expected.yaml 2022-10-03 11:27:20.418172850 +1100
1+
--- tests/acm-naked.expected.yml
2+
+++ tests/acm-normal.expected.yml
33
@@ -1,6 +1,386 @@
44
---
55
-# Source: acm/templates/policies/application-policies.yaml

tests/clustergroup-normal.expected.yaml.variant renamed to tests/clustergroup.expected.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- tests/clustergroup-naked.expected.yaml 2022-10-03 11:27:20.418172850 +1100
2-
+++ tests/clustergroup-normal.expected.yaml 2022-10-03 11:27:20.418172850 +1100
1+
--- tests/clustergroup-naked.expected.yml
2+
+++ tests/clustergroup-normal.expected.yml
33
@@ -1,17 +1,243 @@
44
---
55
+# Source: pattern-clustergroup/templates/core/namespaces.yaml

0 commit comments

Comments
 (0)