controllers: slightly restructure HelmRepository tests

This commit is contained in:
Hidde Beydals 2020-04-17 18:51:13 +02:00
parent 6083d886ce
commit d36efa70dd
1 changed files with 118 additions and 114 deletions

View File

@ -39,8 +39,10 @@ var _ = Describe("HelmRepositoryReconciler", func() {
const (
timeout = time.Second * 30
interval = time.Second * 1
indexInterval = time.Second * 2
)
Context("HelmRepository", func() {
var (
namespace *corev1.Namespace
helmServer *testserver.Helm
@ -53,19 +55,21 @@ var _ = Describe("HelmRepositoryReconciler", func() {
}
err = k8sClient.Create(context.Background(), namespace)
Expect(err).NotTo(HaveOccurred(), "failed to create test namespace")
helmServer, err = testserver.NewTempHelmServer()
Expect(err).To(Succeed())
})
AfterEach(func() {
err = k8sClient.Delete(context.Background(), namespace)
Expect(err).NotTo(HaveOccurred(), "failed to delete test namespace")
os.RemoveAll(helmServer.Root())
helmServer.Stop()
Eventually(func() error {
return k8sClient.Delete(context.Background(), namespace)
}, timeout, interval).Should(Succeed(), "failed to delete test namespace")
})
Context("HelmRepository", func() {
It("Creates artifacts for", func() {
helmServer, err = testserver.NewTempHelmServer()
Expect(err).To(Succeed())
defer os.RemoveAll(helmServer.Root())
defer helmServer.Stop()
helmServer.Start()
Expect(helmServer.PackageChart(path.Join("testdata/helmchart"))).Should(Succeed())
@ -82,7 +86,7 @@ var _ = Describe("HelmRepositoryReconciler", func() {
},
Spec: sourcev1.HelmRepositorySpec{
URL: helmServer.URL(),
Interval: metav1.Duration{Duration: interval},
Interval: metav1.Duration{Duration: indexInterval},
},
}
Expect(k8sClient.Create(context.Background(), created)).Should(Succeed())
@ -97,6 +101,8 @@ var _ = Describe("HelmRepositoryReconciler", func() {
By("Updating the chart index")
// Regenerating the index is sufficient to make the revision change
Expect(helmServer.GenerateIndex()).Should(Succeed())
By("Expecting revision change and GC")
Eventually(func() bool {
now := &sourcev1.HelmRepository{}
_ = k8sClient.Get(context.Background(), key, now)
@ -132,6 +138,8 @@ var _ = Describe("HelmRepositoryReconciler", func() {
r := &sourcev1.HelmRepository{}
return k8sClient.Get(context.Background(), key, r)
}).ShouldNot(Succeed())
By("Expecting GC after delete")
Eventually(storage.ArtifactExist(*got.Status.Artifact), timeout, interval).ShouldNot(BeTrue())
})
@ -184,7 +192,7 @@ var _ = Describe("HelmRepositoryReconciler", func() {
SecretRef: &corev1.LocalObjectReference{
Name: secretKey.Name,
},
Interval: metav1.Duration{Duration: interval},
Interval: metav1.Duration{Duration: indexInterval},
},
}
Expect(k8sClient.Create(context.Background(), created)).Should(Succeed())
@ -240,13 +248,8 @@ var _ = Describe("HelmRepositoryReconciler", func() {
}, timeout, interval).Should(BeTrue())
Expect(got.Status.Artifact).ShouldNot(BeNil())
})
})
It("Authenticates when TLS credentials are provided", func() {
helmServer, err = testserver.NewTempHelmServer()
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(helmServer.Root())
defer helmServer.Stop()
err = helmServer.StartTLS(examplePublicKey, examplePrivateKey, exampleCA)
Expect(err).NotTo(HaveOccurred())
@ -280,7 +283,7 @@ var _ = Describe("HelmRepositoryReconciler", func() {
SecretRef: &corev1.LocalObjectReference{
Name: secretKey.Name,
},
Interval: metav1.Duration{Duration: interval},
Interval: metav1.Duration{Duration: indexInterval},
},
}
Expect(k8sClient.Create(context.Background(), created)).Should(Succeed())
@ -337,4 +340,5 @@ var _ = Describe("HelmRepositoryReconciler", func() {
}, timeout, interval).Should(BeTrue())
Expect(got.Status.Artifact).ShouldNot(BeNil())
})
})
})