Skip to content

Commit

Permalink
unexport validate functions
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Aug 8, 2024
1 parent 16dead0 commit 9d62adf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
48 changes: 24 additions & 24 deletions src/pkg/lint/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error {
}
}
for _, component := range pkg.Components {
if compErr := ValidateComponent(component); compErr != nil {
if compErr := validateComponent(component); compErr != nil {
err = errors.Join(err, compErr)
}
// ensure component name is unique
Expand All @@ -96,7 +96,7 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error {
err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartNameNotUnique, chart.Name))
}
uniqueChartNames[chart.Name] = true
if chartErr := ValidateChart(chart); chartErr != nil {
if chartErr := validateChart(chart); chartErr != nil {
err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChart, chartErr))
}
}
Expand All @@ -107,11 +107,11 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error {
err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifestNameNotUnique, manifest.Name))
}
uniqueManifestNames[manifest.Name] = true
if manifestErr := ValidateManifest(manifest); manifestErr != nil {
if manifestErr := validateManifest(manifest); manifestErr != nil {
err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifest, manifestErr))
}
}
if actionsErr := ValidateActions(component.Actions); actionsErr != nil {
if actionsErr := validateActions(component.Actions); actionsErr != nil {
err = errors.Join(err, fmt.Errorf("%q: %w", component.Name, actionsErr))
}
// ensure groups don't have multiple defaults or only one component
Expand All @@ -133,29 +133,29 @@ func ValidatePackage(pkg v1alpha1.ZarfPackage) error {
return err
}

// ValidateActions validates the actions of a component.
func ValidateActions(a v1alpha1.ZarfComponentActions) error {
// validateActions validates the actions of a component.
func validateActions(a v1alpha1.ZarfComponentActions) error {
var err error

err = errors.Join(err, ValidateActionSet(a.OnCreate))
err = errors.Join(err, validateActionSet(a.OnCreate))

if HasSetVariables(a.OnCreate) {
if hasSetVariables(a.OnCreate) {
err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions"))
}

err = errors.Join(err, ValidateActionSet(a.OnDeploy))
err = errors.Join(err, validateActionSet(a.OnDeploy))

if HasSetVariables(a.OnRemove) {
if hasSetVariables(a.OnRemove) {
err = errors.Join(err, fmt.Errorf("cannot contain setVariables outside of onDeploy in actions"))
}

err = errors.Join(err, ValidateActionSet(a.OnRemove))
err = errors.Join(err, validateActionSet(a.OnRemove))

return err
}

// ValidateComponent validates the component trying to be imported.
func ValidateComponent(c v1alpha1.ZarfComponent) error {
// validateComponent validates the component trying to be imported.
func validateComponent(c v1alpha1.ZarfComponent) error {
var err error
path := c.Import.Path
url := c.Import.URL
Expand Down Expand Up @@ -189,8 +189,8 @@ func ValidateComponent(c v1alpha1.ZarfComponent) error {
return err
}

// HasSetVariables returns true if any of the actions contain setVariables.
func HasSetVariables(as v1alpha1.ZarfComponentActionSet) bool {
// hasSetVariables returns true if any of the actions contain setVariables.
func hasSetVariables(as v1alpha1.ZarfComponentActionSet) bool {
check := func(actions []v1alpha1.ZarfComponentAction) bool {
for _, action := range actions {
if len(action.SetVariables) > 0 {
Expand All @@ -203,12 +203,12 @@ func HasSetVariables(as v1alpha1.ZarfComponentActionSet) bool {
return check(as.Before) || check(as.After) || check(as.OnSuccess) || check(as.OnFailure)
}

// ValidateActionSet runs all validation checks on component action sets.
func ValidateActionSet(as v1alpha1.ZarfComponentActionSet) error {
// validateActionSet runs all validation checks on component action sets.
func validateActionSet(as v1alpha1.ZarfComponentActionSet) error {
var err error
validate := func(actions []v1alpha1.ZarfComponentAction) {
for _, action := range actions {
if actionErr := ValidateAction(action); actionErr != nil {
if actionErr := validateAction(action); actionErr != nil {
err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrAction, actionErr))
}
}
Expand All @@ -221,8 +221,8 @@ func ValidateActionSet(as v1alpha1.ZarfComponentActionSet) error {
return err
}

// ValidateAction runs all validation checks on an action.
func ValidateAction(action v1alpha1.ZarfComponentAction) error {
// validateAction runs all validation checks on an action.
func validateAction(action v1alpha1.ZarfComponentAction) error {
var err error

if action.Wait != nil {
Expand Down Expand Up @@ -268,8 +268,8 @@ func validateReleaseName(chartName, releaseName string) (err error) {
return
}

// ValidateChart runs all validation checks on a chart.
func ValidateChart(chart v1alpha1.ZarfChart) error {
// validateChart runs all validation checks on a chart.
func validateChart(chart v1alpha1.ZarfChart) error {
var err error

if len(chart.Name) > ZarfMaxChartNameLength {
Expand Down Expand Up @@ -300,8 +300,8 @@ func ValidateChart(chart v1alpha1.ZarfChart) error {
return err
}

// ValidateManifest runs all validation checks on a manifest.
func ValidateManifest(manifest v1alpha1.ZarfManifest) error {
// validateManifest runs all validation checks on a manifest.
func validateManifest(manifest v1alpha1.ZarfManifest) error {
var err error

if len(manifest.Name) > ZarfMaxChartNameLength {
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/lint/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestValidateManifest(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := ValidateManifest(tt.manifest)
err := validateManifest(tt.manifest)
if tt.expectedErrs == nil {
require.NoError(t, err)
return
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestValidateChart(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := ValidateChart(tt.chart)
err := validateChart(tt.chart)
if tt.expectedErrs == nil {
require.NoError(t, err)
return
Expand Down Expand Up @@ -416,7 +416,7 @@ func TestValidateComponentActions(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := ValidateActions(tt.actions)
err := validateActions(tt.actions)
if tt.expectedErrs == nil {
require.NoError(t, err)
return
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestValidateComponentAction(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := ValidateAction(tt.action)
err := validateAction(tt.action)
if tt.expectedErrs == nil {
require.NoError(t, err)
return
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestValidateZarfComponent(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := ValidateComponent(tt.component)
err := validateComponent(tt.component)
if tt.expectedErrs == nil {
require.NoError(t, err)
return
Expand Down

0 comments on commit 9d62adf

Please sign in to comment.