diff --git a/internal/helm/repository/chart_repository.go b/internal/helm/repository/chart_repository.go index af5672cca..9837224f4 100644 --- a/internal/helm/repository/chart_repository.go +++ b/internal/helm/repository/chart_repository.go @@ -515,13 +515,15 @@ func jsonOrYamlUnmarshal(b []byte, i interface{}) error { // In particular, charts may introduce validations that don't impact repository indexes // And repository indexes may be generated by older/non-complient software, which doesn't // conform to all validations. +// +// this code is taken from https://github.com/helm/helm/blob/v3.15.2/pkg/repo/index.go#L402 func ignoreSkippableChartValidationError(err error) error { verr, ok := err.(chart.ValidationError) if !ok { return err } - // https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field) + // https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field from index) if strings.HasPrefix(verr.Error(), "validation: more than one dependency with name or alias") { return nil } diff --git a/internal/helm/repository/chart_repository_test.go b/internal/helm/repository/chart_repository_test.go index 1b76f5126..ce16ff886 100644 --- a/internal/helm/repository/chart_repository_test.go +++ b/internal/helm/repository/chart_repository_test.go @@ -754,3 +754,52 @@ func verifyLocalIndex(t *testing.T, i *repo.IndexFile) { g.Expect(tt.Keywords).To(ContainElements(expect.Keywords)) } } + +// This code is taken from https://github.com/helm/helm/blob/v3.15.2/pkg/repo/index_test.go#L601 +// and refers to: https://github.com/helm/helm/issues/12748 +func TestIgnoreSkippableChartValidationError(t *testing.T) { + type TestCase struct { + Input error + ErrorSkipped bool + } + testCases := map[string]TestCase{ + "nil": { + Input: nil, + }, + "generic_error": { + Input: fmt.Errorf("foo"), + }, + "non_skipped_validation_error": { + Input: chart.ValidationError("chart.metadata.type must be application or library"), + }, + "skipped_validation_error": { + Input: chart.ValidationErrorf("more than one dependency with name or alias %q", "foo"), + ErrorSkipped: true, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + result := ignoreSkippableChartValidationError(tc.Input) + + if tc.Input == nil { + if result != nil { + t.Error("expected nil result for nil input") + } + return + } + + if tc.ErrorSkipped { + if result != nil { + t.Error("expected nil result for skipped error") + } + return + } + + if tc.Input != result { + t.Error("expected the result equal to input") + } + + }) + } +}