Skip to content

Commit

Permalink
Add a test case for chart template GC
Browse files Browse the repository at this point in the history
Signed-off-by: Soule BA <[email protected]>
  • Loading branch information
souleb committed Mar 13, 2024
1 parent 07c3cc4 commit 976ee54
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/reconcile/helmchart_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,60 @@ func TestHelmChartTemplate_Reconcile(t *testing.T) {
g.Expect(err).To(HaveOccurred())
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
})

t.Run("Spec ChartRef and existing chart trigger delete", func(t *testing.T) {
g := NewWithT(t)

releaseName := "garbage-collection"
existingChart := sourcev1.HelmChart{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace.GetName(),
Name: fmt.Sprintf("%s-%s", namespace.GetName(), releaseName),
Labels: map[string]string{
v2.GroupVersion.Group + "/name": releaseName,
v2.GroupVersion.Group + "/namespace": namespace.GetName(),
},
},
Spec: sourcev1.HelmChartSpec{
Chart: "./bar",
SourceRef: sourcev1.LocalHelmChartSourceReference{
Kind: sourcev1.HelmRepositoryKind,
Name: "bar-repository",
},
},
}
g.Expect(testEnv.CreateAndWait(context.TODO(), &existingChart)).To(Succeed())
t.Cleanup(func() {
g.Expect(testEnv.Cleanup(context.Background(), &existingChart)).To(Succeed())
})

recorder := record.NewFakeRecorder(32)
r := &HelmChartTemplate{
client: testEnv,
eventRecorder: recorder,
fieldManager: testFieldManager,
}

obj := &v2.HelmRelease{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace.GetName(),
Name: releaseName,
},
Spec: v2.HelmReleaseSpec{
Interval: metav1.Duration{Duration: 1 * time.Hour},
ChartRef: &v2.CrossNamespaceSourceReference{
Kind: sourcev1.OCIRepositoryKind,
Name: "oci-repository",
},
},
Status: v2.HelmReleaseStatus{
HelmChart: fmt.Sprintf("%s/%s", existingChart.GetNamespace(), existingChart.GetName()),
},
}
err := r.Reconcile(context.TODO(), &Request{Object: obj})
g.Expect(err).To(HaveOccurred())
g.Expect(obj.Status.HelmChart).ToNot(BeEmpty())
})
}

func TestHelmChartTemplate_reconcileDelete(t *testing.T) {
Expand Down

0 comments on commit 976ee54

Please sign in to comment.