@@ -37,9 +37,10 @@ import (
3737var _ = Describe ("HelmRepositoryReconciler" , func () {
3838
3939 const (
40- timeout = time .Second * 30
41- interval = time .Second * 1
42- indexInterval = time .Second * 2
40+ timeout = time .Second * 30
41+ interval = time .Second * 1
42+ indexInterval = time .Second * 2
43+ repositoryTimeout = time .Second * 5
4344 )
4445
4546 Context ("HelmRepository" , func () {
@@ -87,6 +88,7 @@ var _ = Describe("HelmRepositoryReconciler", func() {
8788 Spec : sourcev1.HelmRepositorySpec {
8889 URL : helmServer .URL (),
8990 Interval : metav1.Duration {Duration : indexInterval },
91+ Timeout : & metav1.Duration {Duration : repositoryTimeout },
9092 },
9193 }
9294 Expect (k8sClient .Create (context .Background (), created )).Should (Succeed ())
@@ -150,6 +152,57 @@ var _ = Describe("HelmRepositoryReconciler", func() {
150152 Eventually (exists (got .Status .Artifact .Path ), timeout , interval ).ShouldNot (BeTrue ())
151153 })
152154
155+ It ("Handles timeout" , func () {
156+ helmServer .Start ()
157+
158+ Expect (helmServer .PackageChart (path .Join ("testdata/helmchart" ))).Should (Succeed ())
159+ Expect (helmServer .GenerateIndex ()).Should (Succeed ())
160+
161+ key := types.NamespacedName {
162+ Name : "helmrepository-sample-" + randStringRunes (5 ),
163+ Namespace : namespace .Name ,
164+ }
165+ created := & sourcev1.HelmRepository {
166+ ObjectMeta : metav1.ObjectMeta {
167+ Name : key .Name ,
168+ Namespace : key .Namespace ,
169+ },
170+ Spec : sourcev1.HelmRepositorySpec {
171+ URL : helmServer .URL (),
172+ Interval : metav1.Duration {Duration : indexInterval },
173+ },
174+ }
175+ Expect (k8sClient .Create (context .Background (), created )).Should (Succeed ())
176+
177+ By ("Expecting index download to succeed" )
178+ Eventually (func () bool {
179+ got := & sourcev1.HelmRepository {}
180+ _ = k8sClient .Get (context .Background (), key , got )
181+ for _ , condition := range got .Status .Conditions {
182+ if condition .Reason == sourcev1 .IndexationSucceededReason {
183+ return true
184+ }
185+ }
186+ return false
187+ }, timeout , interval ).Should (BeTrue ())
188+
189+ By ("Expecting index download to timeout" )
190+ updated := & sourcev1.HelmRepository {}
191+ Expect (k8sClient .Get (context .Background (), key , updated )).Should (Succeed ())
192+ updated .Spec .Timeout = & metav1.Duration {Duration : time .Microsecond }
193+ Expect (k8sClient .Update (context .Background (), updated )).Should (Succeed ())
194+ Eventually (func () string {
195+ got := & sourcev1.HelmRepository {}
196+ _ = k8sClient .Get (context .Background (), key , got )
197+ for _ , condition := range got .Status .Conditions {
198+ if condition .Reason == sourcev1 .IndexationFailedReason {
199+ return condition .Message
200+ }
201+ }
202+ return ""
203+ }, timeout , interval ).Should (MatchRegexp ("(?i)timeout" ))
204+ })
205+
153206 It ("Authenticates when basic auth credentials are provided" , func () {
154207 helmServer , err = testserver .NewTempHelmServer ()
155208 Expect (err ).NotTo (HaveOccurred ())
0 commit comments