@@ -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"
@@ -633,28 +634,29 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
633
634
want : sreconcile .ResultSuccess ,
634
635
},
635
636
{
636
- name : "Stored index with different digest and same revision " ,
637
+ name : "Stored index with different revision and same digest " ,
637
638
protocol : "http" ,
638
639
beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , rev , dig digest.Digest ) {
639
640
obj .Status .Artifact = & sourcev1.Artifact {
640
- Revision : rev . String () ,
641
- Digest : "sha256:80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86" ,
641
+ Revision : "sha256:80bb3dd67c63095d985850459834ea727603727a370079de90d221191d375a86" ,
642
+ Digest : dig . String () ,
642
643
}
643
644
644
645
conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
645
646
conditions .MarkUnknown (obj , meta .ReadyCondition , "foo" , "bar" )
646
647
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , "foo" , "bar" )
647
648
},
648
649
assertConditions : []metav1.Condition {
649
- * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "foo" ),
650
- * conditions .UnknownCondition (meta .ReadyCondition , "foo" , "bar" ),
650
+ * conditions .TrueCondition (sourcev1 .ArtifactOutdatedCondition , "NewRevision" , "new index revision" ),
651
+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "building artifact: new index revision" ),
652
+ * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "building artifact: new index revision" ),
651
653
},
652
654
afterFunc : func (t * WithT , obj * helmv1.HelmRepository , artifact sourcev1.Artifact , chartRepo * repository.ChartRepository ) {
653
655
t .Expect (chartRepo .Path ).ToNot (BeEmpty ())
654
656
t .Expect (chartRepo .Index ).ToNot (BeNil ())
655
657
656
- t .Expect (artifact .Revision ).To (Equal (obj .Status .Artifact .Revision ))
657
- t .Expect (artifact .Digest ).ToNot ( Equal ( obj . Status . Artifact . Digest ))
658
+ t .Expect (artifact .Revision ).NotTo (Equal (obj .Status .Artifact .Revision ))
659
+ t .Expect (artifact .Digest ).To ( BeEmpty ( ))
658
660
},
659
661
want : sreconcile .ResultSuccess ,
660
662
},
@@ -802,10 +804,12 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
802
804
var rev , dig digest.Digest
803
805
if validSecret {
804
806
g .Expect (newChartRepo .CacheIndex ()).To (Succeed ())
805
- dig = newChartRepo .Digest (intdigest .Canonical )
807
+ rev = newChartRepo .Digest (intdigest .Canonical )
806
808
807
809
g .Expect (newChartRepo .LoadFromPath ()).To (Succeed ())
808
- rev = newChartRepo .Digest (intdigest .Canonical )
810
+ d := intdigest .Canonical .Digester ()
811
+ g .Expect (json .NewEncoder (d .Hash ()).Encode (newChartRepo .Index )).To (Succeed ())
812
+ dig = d .Digest ()
809
813
}
810
814
if tt .beforeFunc != nil {
811
815
tt .beforeFunc (g , obj , rev , dig )
@@ -857,11 +861,17 @@ func TestHelmRepositoryReconciler_reconcileArtifact(t *testing.T) {
857
861
assertConditions []metav1.Condition
858
862
}{
859
863
{
860
- name : "Archiving artifact to storage makes ArtifactInStorage=True" ,
864
+ name : "Archiving artifact to storage makes ArtifactInStorage=True and artifact is stored as JSON " ,
861
865
beforeFunc : func (t * WithT , obj * helmv1.HelmRepository , artifact sourcev1.Artifact , index * repository.ChartRepository ) {
862
866
obj .Spec .Interval = metav1.Duration {Duration : interval }
863
867
},
864
868
want : sreconcile .ResultSuccess ,
869
+ afterFunc : func (t * WithT , obj * helmv1.HelmRepository , cache * cache.Cache ) {
870
+ localPath := testStorage .LocalPath (* obj .GetArtifact ())
871
+ b , err := os .ReadFile (localPath )
872
+ t .Expect (err ).To (Not (HaveOccurred ()))
873
+ t .Expect (json .Valid (b )).To (BeTrue ())
874
+ },
865
875
assertConditions : []metav1.Condition {
866
876
* conditions .TrueCondition (sourcev1 .ArtifactInStorageCondition , meta .SucceededReason , "stored artifact: revision 'existing'" ),
867
877
},
0 commit comments