@@ -19,6 +19,7 @@ package controller
19
19
import (
20
20
"context"
21
21
"crypto/tls"
22
+ "encoding/json"
22
23
"errors"
23
24
"fmt"
24
25
"net/http"
@@ -417,7 +418,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
417
418
server options
418
419
url string
419
420
secret * corev1.Secret
420
- beforeFunc func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest )
421
+ beforeFunc func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest )
421
422
afterFunc func (t * WithT , obj * helmv1.HelmRepository , artifact sourcev1.Artifact , chartRepo * repository.ChartRepository )
422
423
want sreconcile.Result
423
424
wantErr bool
@@ -436,7 +437,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
436
437
"caFile" : tlsCA ,
437
438
},
438
439
},
439
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
440
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
440
441
obj .Spec .CertSecretRef = & meta.LocalObjectReference {Name : "ca-file" }
441
442
},
442
443
assertConditions : []metav1.Condition {
@@ -474,7 +475,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
474
475
"password" : []byte ("1234" ),
475
476
},
476
477
},
477
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
478
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
478
479
obj .Spec .SecretRef = & meta.LocalObjectReference {Name : "basic-auth" }
479
480
},
480
481
want : sreconcile .ResultSuccess ,
@@ -504,7 +505,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
504
505
"caFile" : []byte ("invalid" ),
505
506
},
506
507
},
507
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
508
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
508
509
obj .Spec .CertSecretRef = & meta.LocalObjectReference {Name : "invalid-ca" }
509
510
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
510
511
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
@@ -525,7 +526,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
525
526
{
526
527
name : "Invalid URL makes FetchFailed=True and returns stalling error" ,
527
528
protocol : "http" ,
528
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
529
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
529
530
obj .Spec .URL = strings .ReplaceAll (obj .Spec .URL , "http://" , "" )
530
531
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
531
532
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
@@ -547,7 +548,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
547
548
{
548
549
name : "Unsupported scheme makes FetchFailed=True and returns stalling error" ,
549
550
protocol : "http" ,
550
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
551
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
551
552
obj .Spec .URL = strings .ReplaceAll (obj .Spec .URL , "http://" , "ftp://" )
552
553
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
553
554
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
@@ -569,7 +570,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
569
570
{
570
571
name : "Missing secret returns FetchFailed=True and returns error" ,
571
572
protocol : "http" ,
572
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
573
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
573
574
obj .Spec .SecretRef = & meta.LocalObjectReference {Name : "non-existing" }
574
575
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
575
576
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
@@ -598,7 +599,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
598
599
"username" : []byte ("git" ),
599
600
},
600
601
},
601
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
602
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
602
603
obj .Spec .SecretRef = & meta.LocalObjectReference {Name : "malformed-basic-auth" }
603
604
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
604
605
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
@@ -617,12 +618,11 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
617
618
},
618
619
},
619
620
{
620
- name : "Stored index with same digest and revision" ,
621
+ name : "Stored index with same revision" ,
621
622
protocol : "http" ,
622
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
623
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
623
624
obj .Status .Artifact = & sourcev1.Artifact {
624
625
Revision : rev .String (),
625
- Digest : dig .String (),
626
626
}
627
627
628
628
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
@@ -642,41 +642,15 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
642
642
want : sreconcile .ResultSuccess ,
643
643
},
644
644
{
645
- name : "Stored index with different digest and same revision" ,
645
+ name : "Stored index with different revision" ,
646
646
protocol : "http" ,
647
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
648
- obj .Status .Artifact = & sourcev1.Artifact {
649
- Revision : rev .String (),
650
- Digest : "sha256:80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86" ,
651
- }
652
-
653
- conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
654
- conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
655
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , "foo" , "bar" )
656
- },
657
- assertConditions : []metav1.Condition {
658
- * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "foo" ),
659
- * conditions .UnknownCondition (meta .ReadyCondition , "foo" , "bar" ),
660
- },
661
- afterFunc : func (t * WithT , obj * helmv1.HelmRepository , artifact sourcev1.Artifact , chartRepo * repository.ChartRepository ) {
662
- t .Expect (chartRepo .Path ).ToNot (BeEmpty ())
663
- t .Expect (chartRepo .Index ).ToNot (BeNil ())
664
-
665
- t .Expect (artifact .Revision ).To (Equal (obj .Status .Artifact .Revision ))
666
- t .Expect (artifact .Digest ).ToNot (Equal (obj .Status .Artifact .Digest ))
667
- },
668
- want : sreconcile .ResultSuccess ,
669
- },
670
- {
671
- name : "Stored index with different revision and digest" ,
672
- protocol : "http" ,
673
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
647
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
674
648
obj .Status .Artifact = & sourcev1.Artifact {
675
649
Revision : "80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86" ,
676
- Digest : "sha256:80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86" ,
677
650
}
678
651
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
679
652
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
653
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , "foo" , "bar" )
680
654
},
681
655
assertConditions : []metav1.Condition {
682
656
* conditions .TrueCondition (sourcev1 .ArtifactOutdatedCondition , "NewRevision" , "new index revision" ),
@@ -689,14 +663,13 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
689
663
690
664
t .Expect (artifact .Path ).To (Not (BeEmpty ()))
691
665
t .Expect (artifact .Revision ).ToNot (Equal (obj .Status .Artifact .Revision ))
692
- t .Expect (artifact .Digest ).ToNot (Equal (obj .Status .Artifact .Digest ))
693
666
},
694
667
want : sreconcile .ResultSuccess ,
695
668
},
696
669
{
697
670
name : "Existing artifact makes ArtifactOutdated=True" ,
698
671
protocol : "http" ,
699
- beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
672
+ beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev digest.Digest ) {
700
673
obj .Status .Artifact = & sourcev1.Artifact {
701
674
Path : "some-path" ,
702
675
Revision : "some-rev" ,
@@ -806,14 +779,9 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
806
779
}
807
780
g .Expect (err ).ToNot (HaveOccurred ())
808
781
809
- // NOTE: digest will be empty in beforeFunc for invalid repo
810
- // configurations as the client can't get the repo.
811
- var rev , dig digest.Digest
782
+ var rev digest.Digest
812
783
if validSecret {
813
784
g .Expect (newChartRepo .CacheIndex ()).To (Succeed ())
814
- dig = newChartRepo .Digest (intdigest .Canonical )
815
-
816
- g .Expect (newChartRepo .LoadFromPath ()).To (Succeed ())
817
785
rev = newChartRepo .Digest (intdigest .Canonical )
818
786
}
819
787
@@ -825,7 +793,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
825
793
patchOptions : getPatchOptions (helmRepositoryReadyCondition .Owned , "sc" ),
826
794
}
827
795
if tt .beforeFunc != nil {
828
- tt .beforeFunc (g , obj , rev , dig )
796
+ tt .beforeFunc (g , obj , rev )
829
797
}
830
798
831
799
g .Expect (r .Client .Create (context .TODO (), obj )).ToNot (HaveOccurred ())
@@ -866,11 +834,17 @@ func TestHelmRepositoryReconciler_reconcileArtifact(t *testing.T) {
866
834
assertConditions []metav1.Condition
867
835
}{
868
836
{
869
- name : "Archiving artifact to storage makes ArtifactInStorage=True" ,
837
+ name : "Archiving artifact to storage makes ArtifactInStorage=True and artifact is stored as JSON " ,
870
838
beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , artifact sourcev1.Artifact , index * repository.ChartRepository ) {
871
839
obj .Spec .Interval = metav1.Duration {Duration : interval }
872
840
},
873
841
want : sreconcile .ResultSuccess ,
842
+ afterFunc : func (t * WithT , obj * helmv1.HelmRepository , cache * cache.Cache ) {
843
+ localPath := testStorage .LocalPath (* obj .GetArtifact ())
844
+ b , err := os .ReadFile (localPath )
845
+ t .Expect (err ).To (Not (HaveOccurred ()))
846
+ t .Expect (json .Valid (b )).To (BeTrue ())
847
+ },
874
848
assertConditions : []metav1.Condition {
875
849
* conditions .TrueCondition (sourcev1 .ArtifactInStorageCondition , meta .SucceededReason , "stored artifact: revision 'existing'" ),
876
850
},
@@ -970,17 +944,9 @@ func TestHelmRepositoryReconciler_reconcileArtifact(t *testing.T) {
970
944
},
971
945
}
972
946
973
- tmpDir := t .TempDir ()
974
-
975
- // Create an empty cache file.
976
- cachePath := filepath .Join (tmpDir , "index.yaml" )
977
- cacheFile , err := os .Create (cachePath )
978
- g .Expect (err ).ToNot (HaveOccurred ())
979
- g .Expect (cacheFile .Close ()).ToNot (HaveOccurred ())
980
-
981
947
chartRepo , err := repository .NewChartRepository (obj .Spec .URL , "" , testGetters , nil )
982
948
g .Expect (err ).ToNot (HaveOccurred ())
983
- chartRepo .Path = cachePath
949
+ chartRepo .Index = & repo. IndexFile {}
984
950
985
951
artifact := testStorage .NewArtifactFor (obj .Kind , obj , "existing" , "foo.tar.gz" )
986
952
// Digest of the index file calculated by the ChartRepository.
0 commit comments