Skip to content

Commit 73d2e8a

Browse files
committed
Improve UT: add cross namespace helmchart test
Signed-off-by: Jane Liu L <[email protected]>
1 parent 40a4767 commit 73d2e8a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

controllers/helmchart_controller_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,60 @@ var _ = Describe("HelmChartReconciler", func() {
407407
Expect(chart.Status.Artifact.Revision).Should(Equal("0.1.1"))
408408
})
409409

410+
It("Cross namespace", func() {
411+
Expect(helmServer.PackageChart(path.Join("testdata/charts/helmchart"))).Should(Succeed())
412+
Expect(helmServer.GenerateIndex()).Should(Succeed())
413+
414+
repositoryKey := types.NamespacedName{
415+
Name: "helmrepository-sample-" + randStringRunes(5),
416+
Namespace: namespace.Name,
417+
}
418+
Expect(k8sClient.Create(context.Background(), &sourcev1.HelmRepository{
419+
ObjectMeta: metav1.ObjectMeta{
420+
Name: repositoryKey.Name,
421+
Namespace: repositoryKey.Namespace,
422+
},
423+
Spec: sourcev1.HelmRepositorySpec{
424+
URL: helmServer.URL(),
425+
Interval: metav1.Duration{Duration: indexInterval},
426+
},
427+
})).Should(Succeed())
428+
429+
key := types.NamespacedName{
430+
Name: "helmchart-sample-" + randStringRunes(5),
431+
Namespace: "default",
432+
}
433+
created := &sourcev1.HelmChart{
434+
ObjectMeta: metav1.ObjectMeta{
435+
Name: key.Name,
436+
Namespace: key.Namespace,
437+
},
438+
Spec: sourcev1.HelmChartSpec{
439+
Chart: "helmchart",
440+
Version: "",
441+
SourceRef: sourcev1.LocalHelmChartSourceReference{
442+
Kind: sourcev1.HelmRepositoryKind,
443+
Name: repositoryKey.Name,
444+
},
445+
Interval: metav1.Duration{Duration: pullInterval},
446+
},
447+
}
448+
Expect(k8sClient.Create(context.Background(), created)).Should(Succeed())
449+
450+
got := &sourcev1.HelmChart{}
451+
Eventually(func() bool {
452+
_ = k8sClient.Get(context.Background(), key, got)
453+
for _, c := range got.Status.Conditions {
454+
if strings.Contains(c.Message, "failed to retrieve source") {
455+
return true
456+
}
457+
}
458+
return false
459+
}, timeout, interval).Should(BeTrue())
460+
461+
Expect(k8sClient.Delete(context.Background(), created)).Should(Succeed())
462+
})
463+
410464
It("Authenticates when credentials are provided", func() {
411465
helmServer.Stop()
412466
var username, password = "john", "doe"

0 commit comments

Comments
 (0)