Skip to content

Commit

Permalink
tests: introduce golden tests in kong chart using chartsnap (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Jan 9, 2024
1 parent b087f02 commit d5e1c3c
Show file tree
Hide file tree
Showing 19 changed files with 13,777 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts/kong/ci/__snapshots__/*.snap linguist-generated=true
21 changes: 21 additions & 0 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ jobs:
- name: cleanup integration tests (cleanup)
run: ./scripts/test-env.sh cleanup

golden-tests:
runs-on: ubuntu-latest
name: golden-tests
steps:
- name: checkout
uses: actions/checkout@v4

- name: setup helm
uses: azure/setup-helm@v3
with:
version: v3.11.0

- name: build helm chart dependency
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm dependency build charts/kong
- name: run golden tests
run: make test.golden

# Workaround to allow checking the matrix tests as required tests without adding the individual cases
# Ref: https://github.com/orgs/community/discussions/26822#discussioncomment-3305794
passed:
Expand All @@ -168,6 +188,7 @@ jobs:
- lint-test
- integration-test
- oldversion-integration-test
- golden-tests
if: always()
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
Expand Down
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ _download_tool:
GOBIN=$(PROJECT_DIR)/bin go generate -tags=third_party ./$(TOOL).go )

.PHONY: tools
tools: kube-linter
tools: kube-linter chartsnap

KUBE_LINTER = $(PROJECT_DIR)/bin/kube-linter
.PHONY: kube-linter
kube-linter:
@$(MAKE) _download_tool TOOL=kube-linter

.PHONY: chartsnap
chartsnap:
@helm plugin list | grep chartsnap > /dev/null || \
helm plugin install https://github.com/jlandowner/helm-chartsnap

.PHONY: lint
lint: tools lint.charts.kong lint.shellcheck

Expand All @@ -22,3 +27,24 @@ lint.charts.kong:

lint.shellcheck:
shellcheck ./scripts/*

GOLDEN_TEST_CHART ?= kong
GOLDEN_TEST_CHART_VALUES_DIR ?= ./charts/kong/ci/
CHARTSNAP_COMMAND = helm chartsnap -c ./charts/$(GOLDEN_TEST_CHART) -f $(GOLDEN_TEST_CHART_VALUES_DIR)

# Defining multi-line strings to echo: https://stackoverflow.com/a/649462/7958339
define GOLDEN_TEST_FAILURE_MSG
>> Golden tests have failed.
>> Please run 'make test.golden.update' to update golden files and commit the changes if they're expected.
endef
export GOLDEN_TEST_FAILURE_MSG

.PHONY: test.golden
test.golden: chartsnap
@ $(CHARTSNAP_COMMAND) || \
(echo "$$GOLDEN_TEST_FAILURE_MSG" && \
exit 1)

.PHONY: test.golden.update
test.golden.update: chartsnap
$(CHARTSNAP_COMMAND) -u
26 changes: 26 additions & 0 deletions charts/kong/ci/.chartsnap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# It's a configuration file used by helm-chartsnap to ignore dynamically generated fields
# when comparing the chart's snapshot with the rendered chart.
# See https://github.com/jlandowner/helm-chartsnap?tab=readme-ov-file#handling-dynamic-values-.
dynamicFields:
- apiVersion: v1
kind: Secret
name: chartsnap-postgresql
jsonPath:
- /data/postgres-password
- apiVersion: v1
kind: Secret
name: chartsnap-kong-validation-webhook-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: v1
kind: Secret
name: chartsnap-kong-validation-webhook-ca-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
name: chartsnap-kong-validations
jsonPath:
- /webhooks/0/clientConfig/caBundle
Loading

0 comments on commit d5e1c3c

Please sign in to comment.