Skip to content

Commit b864a0e

Browse files
committed
fix: adding tests for new functionality in helm release
Testing OCI without specifying credentials Testing exclusion and inclusion of specific helm charts
1 parent 8b3378d commit b864a0e

4 files changed

Lines changed: 84 additions & 12 deletions

File tree

pkg/cmd/helm/release/release_test.go

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestStepHelmRelease(t *testing.T) {
7070
t.Logf("ran: %s\n", c.CLI())
7171
}
7272

73-
assert.Equal(t, o.ReleasedCharts, 1, "should have released 1 chart")
73+
assert.Equal(t, 2, o.ReleasedCharts, "should have released 2 charts")
7474
}
7575

7676
func TestStepHelmReleaseWithArtifactory(t *testing.T) {
@@ -112,7 +112,7 @@ func TestStepHelmReleaseWithArtifactory(t *testing.T) {
112112
},
113113
)
114114

115-
err = o.Run()
115+
err = o.Run("anotherchart")
116116
require.NoError(t, err, "failed to run the command")
117117

118118
for _, c := range runner.OrderedCommands {
@@ -160,16 +160,13 @@ func TestStepHelmReleaseWithChartPages(t *testing.T) {
160160
t.Logf("ran: %s\n", c.CLI())
161161
}
162162

163-
assert.Equal(t, o.ReleasedCharts, 1, "should have released 1 chart")
163+
assert.Equal(t, 2, o.ReleasedCharts, "should have released 2 charts")
164164

165165
runner.ExpectResults(t,
166166
fakerunner.FakeResult{
167167
// workaround for dynamically generated git clone destination folder
168168
CLI: runner.OrderedCommands[0].Name + " " + strings.Join(runner.OrderedCommands[0].Args, " "),
169169
},
170-
fakerunner.FakeResult{
171-
CLI: "helm repo add 0 file://myapp-common",
172-
},
173170
fakerunner.FakeResult{
174171
CLI: "git sparse-checkout set --no-cone jx-requirements.yml .jx/gitops/source-config.yaml",
175172
},
@@ -194,6 +191,33 @@ func TestStepHelmReleaseWithChartPages(t *testing.T) {
194191
fakerunner.FakeResult{
195192
CLI: "git status -s",
196193
},
194+
fakerunner.FakeResult{
195+
CLI: "git commit -m chore: add helm chart for anotherchart v1.2.3",
196+
},
197+
fakerunner.FakeResult{
198+
CLI: "git push --set-upstream origin gh-pages",
199+
},
200+
fakerunner.FakeResult{
201+
CLI: "helm repo add 0 file://myapp-common",
202+
},
203+
fakerunner.FakeResult{
204+
CLI: helmDependencyBuild + o.RegistryConfigFile,
205+
},
206+
fakerunner.FakeResult{
207+
CLI: helmLint,
208+
},
209+
fakerunner.FakeResult{
210+
CLI: helmPackage,
211+
},
212+
fakerunner.FakeResult{
213+
CLI: "helm repo index .",
214+
},
215+
fakerunner.FakeResult{
216+
CLI: "git add *",
217+
},
218+
fakerunner.FakeResult{
219+
CLI: "git status -s",
220+
},
197221
fakerunner.FakeResult{
198222
CLI: "git commit -m chore: add helm chart for myapp v1.2.3",
199223
},
@@ -213,7 +237,7 @@ func TestStepHelmReleaseWithOCIUsingUserName(t *testing.T) {
213237
o.RepositoryPassword = reposvearword
214238
o.Dir = "testdata"
215239

216-
err = o.Run()
240+
err = o.Run("myapp")
217241
require.NoError(t, err, "failed to run the command")
218242

219243
for _, c := range runner.OrderedCommands {
@@ -262,7 +286,7 @@ func TestStepHelmReleaseWithOCIUsingRegistryConfig(t *testing.T) {
262286
require.NoError(t, err, "failed to setup commands")
263287
o.NoOCILogin = true
264288
o.RegistryConfigFile = "testdata/helmregistry/config.json"
265-
err = o.Run()
289+
err = o.Run("anotherchart")
266290
require.NoError(t, err, "failed to run the command")
267291

268292
for _, c := range runner.OrderedCommands {
@@ -276,9 +300,6 @@ func TestStepHelmReleaseWithOCIUsingRegistryConfig(t *testing.T) {
276300
// workaround for dynamically generated git clone destination folder
277301
CLI: runner.OrderedCommands[0].Name + " " + strings.Join(runner.OrderedCommands[0].Args, " "),
278302
},
279-
fakerunner.FakeResult{
280-
CLI: "helm repo add 0 file://myapp-common",
281-
},
282303
fakerunner.FakeResult{
283304
CLI: "git sparse-checkout set --no-cone jx-requirements.yml .jx/gitops/source-config.yaml",
284305
},
@@ -296,7 +317,7 @@ func TestStepHelmReleaseWithOCIUsingRegistryConfig(t *testing.T) {
296317
},
297318

298319
fakerunner.FakeResult{
299-
CLI: "helm push myapp-" + chartVersion + ".tgz " + "oci://" + OCIRegistry + " --registry-config " + o.RegistryConfigFile,
320+
CLI: "helm push anotherchart-" + chartVersion + ".tgz " + "oci://" + OCIRegistry + " --registry-config " + o.RegistryConfigFile,
300321
},
301322
)
302323
}
@@ -306,6 +327,50 @@ func TestStepHelmReleaseWithOCINoOCILogin(t *testing.T) {
306327
runner, OCIRegistry, chartVersion, o, err := setupReleaseOCI(t)
307328
require.NoError(t, err, "failed to run the command")
308329
o.NoOCILogin = true
330+
err = o.Run("myapp")
331+
require.NoError(t, err, "failed to run the command")
332+
333+
for _, c := range runner.OrderedCommands {
334+
t.Logf("ran: %s\n", c.CLI())
335+
}
336+
337+
assert.Equal(t, o.ReleasedCharts, 1, "should have released 1 chart")
338+
339+
runner.ExpectResults(t,
340+
fakerunner.FakeResult{
341+
// workaround for dynamically generated git clone destination folder
342+
CLI: runner.OrderedCommands[0].Name + " " + strings.Join(runner.OrderedCommands[0].Args, " "),
343+
},
344+
fakerunner.FakeResult{
345+
CLI: "helm repo add 0 file://myapp-common",
346+
},
347+
fakerunner.FakeResult{
348+
CLI: "git sparse-checkout set --no-cone jx-requirements.yml .jx/gitops/source-config.yaml",
349+
},
350+
fakerunner.FakeResult{
351+
CLI: "git checkout",
352+
},
353+
fakerunner.FakeResult{
354+
CLI: helmDependencyBuild + o.RegistryConfigFile,
355+
},
356+
fakerunner.FakeResult{
357+
CLI: helmLint,
358+
},
359+
fakerunner.FakeResult{
360+
CLI: helmPackage,
361+
},
362+
363+
fakerunner.FakeResult{
364+
CLI: "helm push myapp-" + chartVersion + ".tgz " + "oci://" + OCIRegistry + " --registry-config " + o.RegistryConfigFile,
365+
})
366+
367+
}
368+
369+
//nolint:dupl
370+
func TestStepHelmReleaseWithOCINoOCILoginImplicit(t *testing.T) {
371+
runner, OCIRegistry, chartVersion, o, err := setupReleaseOCI(t)
372+
require.NoError(t, err, "failed to run the command")
373+
o.IgnoreChartNames = []string{"anotherchart", "preview"}
309374
err = o.Run()
310375
require.NoError(t, err, "failed to run the command")
311376

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
description: Another test chart
3+
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/nodejs.png
4+
name: anotherchart
5+
version: 0.1.0-SNAPSHOT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Another test chart

pkg/cmd/helm/release/testdata/charts/anotherchart/values.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)