Skip to content

Commit

Permalink
Run test against unreleased version of Redpanda subcharts
Browse files Browse the repository at this point in the history
Copy the same solution as it was introduced in `TestGoHelmEquivalence` test case.

Reference
redpanda-data/helm-charts@c84b13a
  • Loading branch information
RafalKorepta committed Jan 13, 2025
1 parent 787bd25 commit 21d94b5
Show file tree
Hide file tree
Showing 3 changed files with 444 additions and 292 deletions.
38 changes: 36 additions & 2 deletions charts/redpanda/chart_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
package redpanda_test

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"strings"
"testing"
"time"

certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -79,9 +82,40 @@ func TestTemplateHelm310(t *testing.T) {

func TestTemplate(t *testing.T) {
ctx := testutil.Context(t)
client, err := helm.New(helm.Options{ConfigHome: testutil.TempDir(t)})

tmp := testutil.TempDir(t)

pwd, err := os.Getwd()
require.NoError(t, err)

err = CopyFS(tmp, os.DirFS(pwd), "charts")
require.NoError(t, err)

require.NoError(t, os.Remove(filepath.Join(tmp, "Chart.lock")))

client, err := helm.New(helm.Options{ConfigHome: tmp})
require.NoError(t, err)

ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

// As go based resource rendering is hooked with the unreleased console version
// any change to the console would end up be blocked by this test. The helm template
// would pick the latest console release, so that any change in console would not be
// available in `template` function. Just for
metadata := redpanda.Chart.Metadata()
for _, d := range metadata.Dependencies {
d.Repository = fmt.Sprintf("file://%s", filepath.Join(pwd, fmt.Sprintf("../%s", d.Name)))
}

b, err := yaml.Marshal(metadata)
require.NoError(t, err)

err = os.WriteFile(filepath.Join(tmp, "Chart.yaml"), b, os.ModePerm)
require.NoError(t, err)

require.NoError(t, client.DependencyBuild(ctx, tmp))

archive, err := txtar.ParseFile("testdata/template-cases.txtar")
require.NoError(t, err)

Expand All @@ -105,7 +139,7 @@ func TestTemplate(t *testing.T) {
var values map[string]any
require.NoError(t, yaml.Unmarshal(tc.Data, &values), "input values are invalid YAML")

out, renderErr := client.Template(ctx, ".", helm.TemplateOptions{
out, renderErr := client.Template(ctx, tmp, helm.TemplateOptions{
Name: "redpanda",
Values: values,
Set: []string{
Expand Down
Loading

0 comments on commit 21d94b5

Please sign in to comment.