@@ -672,7 +672,7 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
672
672
g := NewWithT (t )
673
673
674
674
g .Expect (i .Entries ).ToNot (BeNil ())
675
- g .Expect (i .Entries ).To (HaveLen (3 ), "expected 3 entries in index file" )
675
+ g .Expect (i .Entries ).To (HaveLen (4 ), "expected 4 entries in index file" )
676
676
677
677
alpine , ok := i .Entries ["alpine" ]
678
678
g .Expect (ok ).To (BeTrue (), "expected 'alpine' entry to exist" )
@@ -682,6 +682,10 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
682
682
g .Expect (ok ).To (BeTrue (), "expected 'nginx' entry to exist" )
683
683
g .Expect (nginx ).To (HaveLen (2 ), "'nginx' should have 2 entries" )
684
684
685
+ broken , ok := i .Entries ["xChartWithDuplicateDependenciesAndMissingAlias" ]
686
+ g .Expect (ok ).To (BeTrue (), "expected 'xChartWithDuplicateDependenciesAndMissingAlias' entry to exist" )
687
+ g .Expect (broken ).To (HaveLen (1 ), "'xChartWithDuplicateDependenciesAndMissingAlias' should have 1 entries" )
688
+
685
689
expects := []* repo.ChartVersion {
686
690
{
687
691
Metadata : & chart.Metadata {
@@ -723,8 +727,24 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
723
727
},
724
728
Digest : "sha256:1234567890abcdef" ,
725
729
},
730
+ {
731
+ Metadata : & chart.Metadata {
732
+ Name : "xChartWithDuplicateDependenciesAndMissingAlias" ,
733
+ Description : "string" ,
734
+ Version : "1.2.3" ,
735
+ Keywords : []string {"broken" , "still accepted" },
736
+ Home : "https://example.com/something" ,
737
+ Dependencies : []* chart.Dependency {
738
+ {Name : "kube-rbac-proxy" , Version : "0.9.1" },
739
+ },
740
+ },
741
+ URLs : []string {
742
+ "https://kubernetes-charts.storage.googleapis.com/nginx-1.2.3.tgz" ,
743
+ },
744
+ Digest : "sha256:1234567890abcdef" ,
745
+ },
726
746
}
727
- tests := []* repo.ChartVersion {alpine [0 ], nginx [0 ], nginx [1 ]}
747
+ tests := []* repo.ChartVersion {alpine [0 ], nginx [0 ], nginx [1 ], broken [ 0 ] }
728
748
729
749
for i , tt := range tests {
730
750
expect := expects [i ]
@@ -735,5 +755,129 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
735
755
g .Expect (tt .Home ).To (Equal (expect .Home ))
736
756
g .Expect (tt .URLs ).To (ContainElements (expect .URLs ))
737
757
g .Expect (tt .Keywords ).To (ContainElements (expect .Keywords ))
758
+ g .Expect (tt .Dependencies ).To (ContainElements (expect .Dependencies ))
759
+ }
760
+ }
761
+
762
+ // This code is taken from https://github.com/helm/helm/blob/v3.15.2/pkg/repo/index_test.go#L601
763
+ // and refers to: https://github.com/helm/helm/issues/12748
764
+ func TestIgnoreSkippableChartValidationError (t * testing.T ) {
765
+ type TestCase struct {
766
+ Input error
767
+ ErrorSkipped bool
768
+ }
769
+ testCases := map [string ]TestCase {
770
+ "nil" : {
771
+ Input : nil ,
772
+ },
773
+ "generic_error" : {
774
+ Input : fmt .Errorf ("foo" ),
775
+ },
776
+ "non_skipped_validation_error" : {
777
+ Input : chart .ValidationError ("chart.metadata.type must be application or library" ),
778
+ },
779
+ "skipped_validation_error" : {
780
+ Input : chart .ValidationErrorf ("more than one dependency with name or alias %q" , "foo" ),
781
+ ErrorSkipped : true ,
782
+ },
783
+ }
784
+
785
+ for name , tc := range testCases {
786
+ t .Run (name , func (t * testing.T ) {
787
+ result := ignoreSkippableChartValidationError (tc .Input )
788
+
789
+ if tc .Input == nil {
790
+ if result != nil {
791
+ t .Error ("expected nil result for nil input" )
792
+ }
793
+ return
794
+ }
795
+
796
+ if tc .ErrorSkipped {
797
+ if result != nil {
798
+ t .Error ("expected nil result for skipped error" )
799
+ }
800
+ return
801
+ }
802
+
803
+ if tc .Input != result {
804
+ t .Error ("expected the result equal to input" )
805
+ }
806
+
807
+ })
808
+ }
809
+ }
810
+
811
+ var indexWithFirstVersionInvalid = `
812
+ apiVersion: v1
813
+ entries:
814
+ nginx:
815
+ - urls:
816
+ - https://charts.helm.sh/stable/alpine-1.0.0.tgz
817
+ - http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
818
+ name: nginx
819
+ version: 0..1.0
820
+ description: string
821
+ home: https://github.com/something
822
+ digest: "sha256:1234567890abcdef"
823
+ - urls:
824
+ - https://charts.helm.sh/stable/nginx-0.2.0.tgz
825
+ name: nginx
826
+ description: string
827
+ version: 0.2.0
828
+ home: https://github.com/something/else
829
+ digest: "sha256:1234567890abcdef"
830
+ `
831
+ var indexWithLastVersionInvalid = `
832
+ apiVersion: v1
833
+ entries:
834
+ nginx:
835
+ - urls:
836
+ - https://charts.helm.sh/stable/nginx-0.2.0.tgz
837
+ name: nginx
838
+ description: string
839
+ version: 0.2.0
840
+ home: https://github.com/something/else
841
+ digest: "sha256:1234567890abcdef"
842
+ - urls:
843
+ - https://charts.helm.sh/stable/alpine-1.0.0.tgz
844
+ - http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
845
+ name: nginx
846
+ version: 0..1.0
847
+ description: string
848
+ home: https://github.com/something
849
+ digest: "sha256:1234567890abcdef"
850
+ `
851
+
852
+ func TestIndexFromBytes_InvalidEntries (t * testing.T ) {
853
+ tests := []struct {
854
+ source string
855
+ data string
856
+ }{
857
+ {
858
+ source : "indexWithFirstVersionInvalid" ,
859
+ data : indexWithFirstVersionInvalid ,
860
+ },
861
+ {
862
+ source : "indexWithLastVersionInvalid" ,
863
+ data : indexWithLastVersionInvalid ,
864
+ },
865
+ }
866
+ for _ , tc := range tests {
867
+ t .Run (tc .source , func (t * testing.T ) {
868
+ idx , err := IndexFromBytes ([]byte (tc .data ))
869
+ if err != nil {
870
+ t .Fatalf ("unexpected error: %s" , err )
871
+ }
872
+ cvs := idx .Entries ["nginx" ]
873
+ if len (cvs ) == 0 {
874
+ t .Error ("expected one chart version not to be filtered out" )
875
+ }
876
+ for _ , v := range cvs {
877
+ if v .Version == "0..1.0" {
878
+ t .Error ("malformed version was not filtered out" )
879
+ }
880
+ }
881
+ })
738
882
}
739
883
}
0 commit comments