@@ -279,7 +279,7 @@ var _ = Describe("HelmChartReconciler", func() {
279279 })
280280 helmServer .Start ()
281281
282- Expect (helmServer .PackageChart (path .Join ("testdata/helmchart" ))).Should (Succeed ())
282+ Expect (helmServer .PackageChartWithVersion (path .Join ("testdata/helmchart" ), "0.1.0" )).Should (Succeed ())
283283 Expect (helmServer .GenerateIndex ()).Should (Succeed ())
284284
285285 secretKey := types.NamespacedName {
@@ -298,6 +298,7 @@ var _ = Describe("HelmChartReconciler", func() {
298298 }
299299 Expect (k8sClient .Create (context .Background (), secret )).Should (Succeed ())
300300
301+ By ("Creating repository and waiting for artifact" )
301302 repositoryKey := types.NamespacedName {
302303 Name : "helmrepository-sample-" + randStringRunes (5 ),
303304 Namespace : namespace .Name ,
@@ -312,12 +313,21 @@ var _ = Describe("HelmChartReconciler", func() {
312313 SecretRef : & corev1.LocalObjectReference {
313314 Name : secretKey .Name ,
314315 },
315- Interval : metav1.Duration {Duration : time . Hour * 1 },
316+ Interval : metav1.Duration {Duration : pullInterval },
316317 },
317318 }
318319 Expect (k8sClient .Create (context .Background (), repository )).Should (Succeed ())
319320 defer k8sClient .Delete (context .Background (), repository )
320321
322+ Eventually (func () bool {
323+ _ = k8sClient .Get (context .Background (), repositoryKey , repository )
324+ return repository .Status .Artifact != nil
325+ }, timeout , interval ).Should (BeTrue ())
326+
327+ By ("Deleting secret before applying HelmChart" )
328+ Expect (k8sClient .Delete (context .Background (), secret )).Should (Succeed ())
329+
330+ By ("Applying HelmChart" )
321331 key := types.NamespacedName {
322332 Name : "helmchart-sample-" + randStringRunes (5 ),
323333 Namespace : namespace .Name ,
@@ -340,63 +350,68 @@ var _ = Describe("HelmChartReconciler", func() {
340350 Expect (k8sClient .Create (context .Background (), chart )).Should (Succeed ())
341351 defer k8sClient .Delete (context .Background (), chart )
342352
343- By ("Expecting artifact " )
344- Expect ( k8sClient . Update ( context . Background (), secret )). Should ( Succeed ())
353+ By ("Expecting missing secret error " )
354+ got := & sourcev1. HelmChart {}
345355 Eventually (func () bool {
346- got := & sourcev1.HelmChart {}
347356 _ = k8sClient .Get (context .Background (), key , got )
348- return got .Status .Artifact != nil &&
349- storage .ArtifactExist (* got .Status .Artifact )
357+ for _ , c := range got .Status .Conditions {
358+ if c .Reason == sourcev1 .AuthenticationFailedReason &&
359+ strings .Contains (c .Message , "auth secret error" ) {
360+ return true
361+ }
362+ }
363+ return false
350364 }, timeout , interval ).Should (BeTrue ())
351365
352- delete (secret .Data , "username" )
353- Expect (k8sClient .Update (context .Background (), secret )).Should (Succeed ())
366+ By ("Applying secret with missing keys" )
367+ secret .ResourceVersion = ""
368+ secret .Data ["username" ] = []byte {}
369+ secret .Data ["password" ] = []byte {}
370+ Expect (k8sClient .Create (context .Background (), secret )).Should (Succeed ())
354371
355- By ("Expecting missing field error" )
356- delete (secret .Data , "username" )
357- Expect (k8sClient .Update (context .Background (), secret )).Should (Succeed ())
358- got := & sourcev1.HelmChart {}
372+ By ("Expecting 401" )
359373 Eventually (func () bool {
374+ got := & sourcev1.HelmChart {}
360375 _ = k8sClient .Get (context .Background (), key , got )
361376 for _ , c := range got .Status .Conditions {
362- if c .Reason == sourcev1 .AuthenticationFailedReason {
377+ if c .Reason == sourcev1 .ChartPullFailedReason &&
378+ strings .Contains (c .Message , "401 Unauthorized" ) {
363379 return true
364380 }
365381 }
366382 return false
367383 }, timeout , interval ).Should (BeTrue ())
368- Expect (got .Status .Artifact ).ToNot (BeNil ())
369384
370- delete (secret .Data , "password" )
385+ By ("Adding username key" )
386+ secret .Data ["username" ] = []byte (username )
371387 Expect (k8sClient .Update (context .Background (), secret )).Should (Succeed ())
372388
373- By ("Expecting 401 " )
389+ By ("Expecting missing field error " )
374390 Eventually (func () bool {
375- got := & sourcev1.HelmChart {}
376391 _ = k8sClient .Get (context .Background (), key , got )
377392 for _ , c := range got .Status .Conditions {
378- if c .Reason == sourcev1 .ChartPullFailedReason &&
379- strings .Contains (c .Message , "401 Unauthorized" ) {
393+ if c .Reason == sourcev1 .AuthenticationFailedReason {
380394 return true
381395 }
382396 }
383397 return false
384398 }, timeout , interval ).Should (BeTrue ())
385399
386- By ("Expecting missing secret error" )
387- Expect (k8sClient .Delete (context .Background (), secret )).Should (Succeed ())
388- got = & sourcev1.HelmChart {}
400+ By ("Adding password key" )
401+ secret .Data ["password" ] = []byte (password )
402+ Expect (k8sClient .Update (context .Background (), secret )).Should (Succeed ())
403+
404+ By ("Expecting artifact" )
389405 Eventually (func () bool {
390406 _ = k8sClient .Get (context .Background (), key , got )
391407 for _ , c := range got .Status .Conditions {
392- if c .Reason == sourcev1 .AuthenticationFailedReason &&
393- strings .Contains (c .Message , "auth secret error" ) {
408+ if c .Type == sourcev1 .ReadyCondition && c .Status == corev1 .ConditionTrue {
394409 return true
395410 }
396411 }
397412 return false
398413 }, timeout , interval ).Should (BeTrue ())
399- Expect (got .Status .Artifact ).ShouldNot (BeNil ())
414+ Expect (got .Status .Artifact ).ToNot (BeNil ())
400415 })
401416 })
402417
0 commit comments