Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Mar 11, 2024
1 parent 13dcda3 commit 7196aa8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions pkg/image/validation/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,22 @@ func validateHelm(k8s *image.Kubernetes, imageConfigDir string) []FailedValidati

if len(k8s.Helm.Repositories) == 0 {
failures = append(failures, FailedValidation{
UserMessage: "Helm charts defined with no Helm Repository defined.",
UserMessage: "Helm charts defined with no Helm repositories defined.",
})

return failures
}

seenHelmCharts := make(map[string]bool)
if failure := validateHelmChartDuplicates(k8s.Helm.Charts); failure != "" {
failures = append(failures, FailedValidation{
UserMessage: failure,
})
}

seenHelmRepos := make(map[string]bool)
for _, chart := range k8s.Helm.Charts {
c := chart
failures = append(failures, validateChart(&c, seenHelmCharts, imageConfigDir)...)
failures = append(failures, validateChart(&c, imageConfigDir)...)

seenHelmRepos[chart.RepositoryName] = true
}
Expand All @@ -174,7 +179,7 @@ func validateHelm(k8s *image.Kubernetes, imageConfigDir string) []FailedValidati
return failures
}

func validateChart(chart *image.HelmChart, seenHelmCharts map[string]bool, imageConfigDir string) []FailedValidation {
func validateChart(chart *image.HelmChart, imageConfigDir string) []FailedValidation {
var failures []FailedValidation

if chart.Name == "" {
Expand Down Expand Up @@ -207,14 +212,6 @@ func validateChart(chart *image.HelmChart, seenHelmCharts map[string]bool, image
})
}

if _, exists := seenHelmCharts[chart.Name]; exists {
msg := fmt.Sprintf("The 'helmCharts' field contains duplicate entries: %s", chart.Name)
failures = append(failures, FailedValidation{
UserMessage: msg,
})
}
seenHelmCharts[chart.Name] = true

return failures
}

Expand Down Expand Up @@ -261,7 +258,21 @@ func validateHelmChartValues(chartName, valuesFile string, imageConfigDir string
}

zap.S().Errorf("values file '%s' could not be read: %s", valuesFile, err)
return fmt.Sprintf("Helm chart values File '%s' could not be read.", valuesFile)
return fmt.Sprintf("Helm chart values file '%s' could not be read.", valuesFile)
}

return ""
}

func validateHelmChartDuplicates(charts []image.HelmChart) string {
seenHelmCharts := make(map[string]bool)

for _, chart := range charts {
if _, exists := seenHelmCharts[chart.Name]; exists {
return fmt.Sprintf("The 'helmCharts' field contains duplicate entries: %s", chart.Name)
}

seenHelmCharts[chart.Name] = true
}

return ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/validation/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func TestValidateHelmCharts(t *testing.T) {
},
},
ExpectedFailedMessages: []string{
"Helm charts defined with no Helm Repository defined.",
"Helm charts defined with no Helm repositories defined.",
},
},
`helm chart no name`: {
Expand Down

0 comments on commit 7196aa8

Please sign in to comment.