Skip to content

Commit c89da4b

Browse files
committed
adds test and hints where code snippets are taken from fluxcd#1515
Signed-off-by: ricardo.bartels@telekom.de <ricardo.bartels@telekom.de>
1 parent 65ab271 commit c89da4b

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

internal/helm/repository/chart_repository.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,15 @@ func jsonOrYamlUnmarshal(b []byte, i interface{}) error {
515515
// In particular, charts may introduce validations that don't impact repository indexes
516516
// And repository indexes may be generated by older/non-complient software, which doesn't
517517
// conform to all validations.
518+
//
519+
// this code is taken from https://github.com/helm/helm/blob/v3.15.2/pkg/repo/index.go#L402
518520
func ignoreSkippableChartValidationError(err error) error {
519521
verr, ok := err.(chart.ValidationError)
520522
if !ok {
521523
return err
522524
}
523525

524-
// https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field)
526+
// https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field from index)
525527
if strings.HasPrefix(verr.Error(), "validation: more than one dependency with name or alias") {
526528
return nil
527529
}

internal/helm/repository/chart_repository_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,52 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
754754
g.Expect(tt.Keywords).To(ContainElements(expect.Keywords))
755755
}
756756
}
757+
758+
// This code is taken from https://github.com/helm/helm/blob/v3.15.2/pkg/repo/index_test.go#L601
759+
// and refers to: https://github.com/helm/helm/issues/12748
760+
func TestIgnoreSkippableChartValidationError(t *testing.T) {
761+
type TestCase struct {
762+
Input error
763+
ErrorSkipped bool
764+
}
765+
testCases := map[string]TestCase{
766+
"nil": {
767+
Input: nil,
768+
},
769+
"generic_error": {
770+
Input: fmt.Errorf("foo"),
771+
},
772+
"non_skipped_validation_error": {
773+
Input: chart.ValidationError("chart.metadata.type must be application or library"),
774+
},
775+
"skipped_validation_error": {
776+
Input: chart.ValidationErrorf("more than one dependency with name or alias %q", "foo"),
777+
ErrorSkipped: true,
778+
},
779+
}
780+
781+
for name, tc := range testCases {
782+
t.Run(name, func(t *testing.T) {
783+
result := ignoreSkippableChartValidationError(tc.Input)
784+
785+
if tc.Input == nil {
786+
if result != nil {
787+
t.Error("expected nil result for nil input")
788+
}
789+
return
790+
}
791+
792+
if tc.ErrorSkipped {
793+
if result != nil {
794+
t.Error("expected nil result for skipped error")
795+
}
796+
return
797+
}
798+
799+
if tc.Input != result {
800+
t.Error("expected the result equal to input")
801+
}
802+
803+
})
804+
}
805+
}

0 commit comments

Comments
 (0)