Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redpanda: implement snapshot testing #1079

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/redpanda/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ README.md.gotmpl
.vscode/

*.go
testdata/
ci/
59 changes: 58 additions & 1 deletion charts/redpanda/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redpanda

import (
"os"
"os/exec"
"testing"

"github.com/redpanda-data/helm-charts/pkg/helm"
Expand All @@ -19,6 +20,11 @@ func TieredStorageStatic(t *testing.T) Values {
}

return Values{
Config: &Config{
Node: map[string]any{
"developer_mode": true,
},
},
Enterprise: &Enterprise{
License: os.Getenv("REDPANDA_LICENSE"),
},
Expand Down Expand Up @@ -55,6 +61,11 @@ func TieredStorageSecretRefs(t *testing.T, secret *corev1.Secret) Values {
}

return Values{
Config: &Config{
Node: map[string]any{
"developer_mode": true,
},
},
Enterprise: &Enterprise{
License: os.Getenv("REDPANDA_LICENSE"),
},
Expand All @@ -74,6 +85,44 @@ func TieredStorageSecretRefs(t *testing.T, secret *corev1.Secret) Values {
}
}

func TestTemplate(t *testing.T) {
ctx := testutil.Context(t)
client, err := helm.New(helm.Options{ConfigHome: testutil.TempDir(t)})
chrisseto marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

// Chart deps are kept within ./charts as a tgz archive. Helm dep build
// will ensure that ./charts is in sync with Chart.lock.
_, err = exec.CommandContext(ctx, "helm", "dep", "build").CombinedOutput()
require.NoError(t, err, "failed to refresh helm dependencies")

values, err := os.ReadDir("./ci")
require.NoError(t, err)

for _, v := range values {
v := v
t.Run(v.Name(), func(t *testing.T) {
t.Parallel()

out, err := client.Template(ctx, ".", helm.TemplateOptions{
Name: "redpanda",
ValuesFile: "./ci/" + v.Name(),
Set: []string{
// Tests utilize some non-deterministic helpers (rng). We don't
// really care about the stability of their output, so globally
// disable them.
"tests.enabled=false",
// jwtSecret defaults to a random string. Can't have that
// in snapshot testing so set it to a static value.
"console.secret.login.jwtSecret=SECRETKEY",
},
})
require.NoError(t, err)

testutil.AssertGolden(t, testutil.Text, "./testdata/"+v.Name()+".golden", out)
})
}
}

func TestChart(t *testing.T) {
if testing.Short() {
t.Skipf("Skipping log running test...")
Expand All @@ -87,7 +136,15 @@ func TestChart(t *testing.T) {
credsSecret, err := kube.Create(ctx, env.Ctl(), TieredStorageSecret(env.Namespace()))
require.NoError(t, err)

rpRelease := env.Install(".", helm.InstallOptions{})
rpRelease := env.Install(".", helm.InstallOptions{
Values: Values{
Config: &Config{
Node: map[string]any{
"developer_mode": true,
},
},
},
})

rpk := Client{Ctl: env.Ctl(), Release: &rpRelease}

Expand Down
2 changes: 1 addition & 1 deletion charts/redpanda/templates/_configmap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ rpk:
{{- define "rpk-config-external" -}}
{{- $brokers := list -}}
{{- $admin := list -}}
{{- $profile := keys .Values.listeners.kafka.external | first -}}
{{- $profile := keys .Values.listeners.kafka.external | sortAlpha | first -}}
{{- $kafkaListener := get .Values.listeners.kafka.external $profile -}}
{{- $adminListener := dict -}}
{{- if .Values.listeners.admin.external -}}
Expand Down
2 changes: 2 additions & 0 deletions charts/redpanda/templates/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- /* Generated from "values.go" */ -}}

Loading
Loading