Skip to content

Commit

Permalink
tests: add ingress golden tests (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Feb 22, 2024
1 parent 85d6682 commit ac23c03
Show file tree
Hide file tree
Showing 5 changed files with 1,122 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
charts/kong/ci/__snapshots__/*.snap linguist-generated=true
charts/ingress/ci/__snapshots__/*.snap linguist-generated=true
2 changes: 2 additions & 0 deletions .github/workflows/release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ jobs:
- name: build helm chart dependency
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add kong https://charts.konghq.com
helm dependency build charts/kong
helm dependency build charts/ingress
- name: run golden tests
run: make test.golden
Expand Down
32 changes: 21 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ 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)
.PHONY: test.golden
test.golden:
@ $(MAKE) _chartsnap.kong && $(MAKE) _chartsnap.ingress || \
(echo "$$GOLDEN_TEST_FAILURE_MSG" && exit 1)

.PHONY: test.golden.update
test.golden.update:
@ $(MAKE) _chartsnap.kong CHARTSNAP_ARGS="-u"
@ $(MAKE) _chartsnap.ingress CHARTSNAP_ARGS="-u"

# Defining multi-line strings to echo: https://stackoverflow.com/a/649462/7958339
define GOLDEN_TEST_FAILURE_MSG
Expand All @@ -39,12 +45,16 @@ define GOLDEN_TEST_FAILURE_MSG
endef
export GOLDEN_TEST_FAILURE_MSG

.PHONY: test.golden
test.golden: chartsnap
@ $(CHARTSNAP_COMMAND) || \
(echo "$$GOLDEN_TEST_FAILURE_MSG" && \
exit 1)
.PHONY: _chartsnap.kong
_chartsnap.kong:
@ $(MAKE) _chartsnap GOLDEN_TEST_CHART=kong GOLDEN_TEST_CHART_VALUES_DIR=./charts/kong/ci/ \
CHARTSNAP_ARGS=$(CHARTSNAP_ARGS)

.PHONY: test.golden.update
test.golden.update: chartsnap
$(CHARTSNAP_COMMAND) -u
.PHONY: _chartsnap.ingress
_chartsnap.ingress:
@ $(MAKE) _chartsnap GOLDEN_TEST_CHART=ingress GOLDEN_TEST_CHART_VALUES_DIR=./charts/ingress/ci/ \
CHARTSNAP_ARGS=$(CHARTSNAP_ARGS)

.PHONY: _chartsnap
_chartsnap: chartsnap
@ helm chartsnap -c ./charts/$(GOLDEN_TEST_CHART) -f $(GOLDEN_TEST_CHART_VALUES_DIR) $(CHARTSNAP_ARGS)
38 changes: 38 additions & 0 deletions charts/ingress/ci/.chartsnap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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-controller-validation-webhook-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: v1
kind: Secret
name: chartsnap-controller-validation-webhook-ca-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: v1
kind: Secret
name: chartsnap-controller-admin-api-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: v1
kind: Secret
name: chartsnap-controller-admin-api-ca-keypair
jsonPath:
- /data/tls.crt
- /data/tls.key
- apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
name: chartsnap-controller-validations
jsonPath:
- /webhooks/0/clientConfig/caBundle
Loading

0 comments on commit ac23c03

Please sign in to comment.