redpanda-data / helm-charts

Redpanda Helm Chart
http://redpanda.com
Apache License 2.0
77 stars 96 forks source link

redpanda: refactor template tests to use txtars #1460

Closed chrisseto closed 3 months ago

chrisseto commented 3 months ago

Template tests / golden tests for the redpanda chart were previously a collection of files on disk in the testdata directory. This resulted in very noisey git diffs and git statuses whenever changes to the chart were made and it diverged from the patterns set forth in the console and connectors chart. Adding regression tests was a bit unpleasant as well. They would need to be added as a "no-values.yaml" file or have an elaborate go setup.

This commit refactors the template tests to follow a pattern similar to console and connectors. To make adding new regression tests less painful, a minimal dynamic assertion system has been put in place.

Values files may specify assertions in the form of: # ASSERT-<NAME> ["OPTIONAL", "PARAMS"] Which will cause various assertions to run and provides a framework for easily adding new assertions and selectively applying them.

RafalKorepta commented 3 months ago

Oh gofmt complains:

task: [ci:lint] gofumpt -w .
task: [ci:lint] git diff --exit-code
diff --git a/charts/redpanda/chart_template_test.go b/charts/redpanda/chart_template_test.go
index 89a05d8..e6d5e41 100644
--- a/charts/redpanda/chart_template_test.go
+++ b/charts/redpanda/chart_template_test.go
@@ -94,7 +94,7 @@ func TestTemplate(t *testing.T) {
                        // Trailing new lines are added by the txtar format if
                        // they're not already present. Add one here otherwise
                        // we'll see failures.
-                       goldens.AssertGolden(t, testutil.Text, fmt.Sprintf("testdata/%s.yaml.golden", t.Name()), []byte(err.Error() + "\n"))
+                       goldens.AssertGolden(t, testutil.Text, fmt.Sprintf("testdata/%s.yaml.golden", t.Name()), []byte(err.Error()+"\n"))
                    }

https://github.com/redpanda-data/helm-charts/actions/runs/10205242641/job/28235555473?pr=1460#step:5:291

chrisseto commented 3 months ago

Fixed, thanks for looking!