Skip to content

Commit ef02c2a

Browse files
committed
Helm test fix
- rethinkdb operator moved to an oci chart, but the tests don't support it. - moved the testing to use the cert-manager chart TODO will come back and get the helm tooling to handle oci charts in the future Signed-off-by: James Nesbitt <[email protected]>
1 parent 908393a commit ef02c2a

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

pkg/helm/helm_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@ package helm
33
import (
44
"testing"
55

6-
"github.com/Mirantis/launchpad/pkg/constant"
76
"github.com/hashicorp/go-version"
87
"github.com/stretchr/testify/assert"
98
"github.com/stretchr/testify/require"
109
)
1110

1211
func TestChartNeedsUpgrade(t *testing.T) {
1312
h := NewHelmTestClient(t)
14-
rd, _ := InstallRethinkDBOperatorChart(t, h)
13+
rd, _ := InstallCertManagerChart(t, h)
1514

16-
rdbOperatorVersion := rd.Version
15+
rdChartVersion := rd.Version
1716

1817
testCases := []string{
1918
// ChartNeedsUpgrade returns true if the version is DIFFERENT from
20-
// the installed one, so anything but rdbOperatorVersion should return
19+
// the installed one, so anything but Version should return
2120
// true. It's written this way to support downgrades.
22-
rdbOperatorVersion,
21+
rdChartVersion,
2322
"1.0.0",
2423
"1.0.1",
2524
"1.0.100",
@@ -36,12 +35,12 @@ func TestChartNeedsUpgrade(t *testing.T) {
3635
vers, err := version.NewVersion(tc)
3736
require.NoError(t, err)
3837

39-
actual, err := h.ChartNeedsUpgrade(constant.RethinkDBOperator, vers)
38+
actual, err := h.ChartNeedsUpgrade(rd.ReleaseName, vers)
4039
if assert.NoError(t, err) {
41-
if tc == rdbOperatorVersion {
42-
assert.False(t, actual, "version: %s does match current version: %s", tc, rdbOperatorVersion)
40+
if tc == rdChartVersion {
41+
assert.False(t, actual, "version: %s does match current version: %s", tc, rdChartVersion)
4342
} else {
44-
assert.True(t, actual, "version: %s does not match current version: %s", tc, rdbOperatorVersion)
43+
assert.True(t, actual, "version: %s does not match current version: %s", tc, rdChartVersion)
4544
}
4645
}
4746
}

pkg/helm/testutil.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,49 @@ func NewHelmTestClient(t *testing.T, options ...HelmTestClientOption) *Helm {
7777
}
7878
}
7979

80+
81+
82+
// InstallCertManagerChart installs cert-manager
83+
// to use as a chart to query for testing purposes and returns the
84+
// ReleaseDetails for the chart as well as a function to uninstall the chart.
85+
func InstallCertManagerChart(t *testing.T, h *Helm) (ReleaseDetails, func()) {
86+
t.Helper()
87+
88+
rd := ReleaseDetails{
89+
ChartName: "cert-manager",
90+
ReleaseName: "cert-manager",
91+
RepoURL: "https://charts.jetstack.io",
92+
Version: "1.10.0",
93+
}
94+
95+
_, err := h.Upgrade(context.Background(), &Options{
96+
ReleaseDetails: rd, Timeout: ptr.To(DefaultTimeout),
97+
})
98+
require.NoError(t, err)
99+
100+
uninstallFunc := func() {
101+
err := h.Uninstall(&Options{
102+
ReleaseDetails: rd, Timeout: ptr.To(DefaultTimeout),
103+
})
104+
require.NoError(t, err)
105+
}
106+
107+
rd.Installed = true
108+
109+
return rd, uninstallFunc
110+
}
111+
80112
// InstallRethinkDBOperatorChart installs rethinkdb-operator
81113
// to use as a chart to query for testing purposes and returns the
82114
// ReleaseDetails for the chart as well as a function to uninstall the chart.
115+
// @NOTE not currently tested
83116
func InstallRethinkDBOperatorChart(t *testing.T, h *Helm) (ReleaseDetails, func()) {
84117
t.Helper()
85118

86119
rd := ReleaseDetails{
87-
ChartName: constant.RethinkDBOperator,
120+
ChartName: "oci://registry.mirantis.com/rethinkdb/helm/rethindb-operator",
88121
ReleaseName: constant.RethinkDBOperator,
89-
RepoURL: "https://registry.mirantis.com/charts/rethinkdb/rethinkdb-operator",
122+
RepoURL: "",
90123
Version: "1.0.0",
91124
}
92125

pkg/helm/uninstall_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestUninstall(t *testing.T) {
1111
h := NewHelmTestClient(t)
12-
rd, _ := InstallRethinkDBOperatorChart(t, h)
12+
rd, _ := InstallCertManagerChart(t, h)
1313

1414
err := h.Uninstall(&Options{
1515
ReleaseDetails: rd,

pkg/helm/upgrade_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestUpgrade(t *testing.T) {
1212
h := NewHelmTestClient(t)
1313

1414
t.Run("Upgrade success", func(t *testing.T) {
15-
rd, uninstallFunc := InstallRethinkDBOperatorChart(t, h)
15+
rd, uninstallFunc := InstallCertManagerChart(t, h)
1616
t.Cleanup(uninstallFunc)
1717
rd.Values = map[string]interface{}{
1818
"controllerManager": map[string]interface{}{
@@ -33,12 +33,12 @@ func TestUpgrade(t *testing.T) {
3333
})
3434

3535
t.Run("Upgrade, reuse values", func(t *testing.T) {
36-
rd, uninstallFunc := InstallRethinkDBOperatorChart(t, h)
36+
rd, uninstallFunc := InstallCertManagerChart(t, h)
3737
t.Cleanup(uninstallFunc)
3838

3939
rd.Values = map[string]interface{}{
40-
"rethinkdb": map[string]interface{}{
41-
"name": "cooler-rethinkdb",
40+
"image": map[string]interface{}{
41+
"tag": "1.2.3",
4242
},
4343
}
4444

@@ -51,7 +51,7 @@ func TestUpgrade(t *testing.T) {
5151
assert.Equal(t, rd.ChartName, rel.Chart.Metadata.Name)
5252
// ReuseValues should not change the values, but reuse the previous
5353
// ones.
54-
assert.NotEqual(t, "cooler-rethinkdb", rel.Chart.Values["rethinkdb"].(map[string]interface{})["name"])
54+
assert.NotEqual(t, "1.2.3", rel.Chart.Values["image"].(map[string]interface{})["tag"])
5555
assert.ObjectsAreEqualValues(rd.Values, rel.Chart.Values)
5656
}
5757
})

0 commit comments

Comments
 (0)