Skip to content

Commit

Permalink
chore: remove error prone validate func (#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly authored Nov 28, 2023
1 parent 5ba1828 commit 8e2e4c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 0 additions & 8 deletions pkg/engine/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
)

func Validate(ctx context.Context, assertion interface{}, value interface{}, bindings binding.Bindings) (field.ErrorList, error) {
return validate(ctx, nil, assertion, value, bindings)
}

func Assert(ctx context.Context, assertion Assertion, value interface{}, bindings binding.Bindings) (field.ErrorList, error) {
return assert(ctx, nil, assertion, value, bindings)
}

func validate(ctx context.Context, path *field.Path, assertion interface{}, value interface{}, bindings binding.Bindings) (field.ErrorList, error) {
return assert(ctx, path, Parse(ctx, assertion), value, bindings)
}

func assert(ctx context.Context, path *field.Path, assertion Assertion, value interface{}, bindings binding.Bindings) (field.ErrorList, error) {
return assertion.assert(ctx, path, value, bindings)
}
8 changes: 4 additions & 4 deletions pkg/engine/assert/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert,
var fails []error
path := path.Child("any")
for i, assertion := range match.Any {
checkFails, err := validate(ctx, path.Index(i).Child("check"), assertion.Check.Value, actual, bindings)
checkFails, err := assert(ctx, path.Index(i).Child("check"), Parse(ctx, assertion.Check.Value), actual, bindings)
if err != nil {
return fails, err
}
Expand All @@ -46,7 +46,7 @@ func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert,
var fails []error
path := path.Child("all")
for i, assertion := range match.All {
checkFails, err := validate(ctx, path.Index(i).Child("check"), assertion.Check.Value, actual, bindings)
checkFails, err := assert(ctx, path.Index(i).Child("check"), Parse(ctx, assertion.Check.Value), actual, bindings)
if err != nil {
return fails, err
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func Match(ctx context.Context, path *field.Path, match *v1alpha1.Match, actual
func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual interface{}, bindings binding.Bindings) (field.ErrorList, error) {
var errs field.ErrorList
for i, assertion := range assertions {
_errs, err := validate(ctx, path.Index(i), assertion.Value, actual, bindings)
_errs, err := assert(ctx, path.Index(i), Parse(ctx, assertion.Value), actual, bindings)
if err != nil {
return errs, err
}
Expand All @@ -107,7 +107,7 @@ func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any,
func MatchAll(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual interface{}, bindings binding.Bindings) (field.ErrorList, error) {
var errs field.ErrorList
for i, assertion := range assertions {
_errs, err := validate(ctx, path.Index(i), assertion.Value, actual, bindings)
_errs, err := assert(ctx, path.Index(i), Parse(ctx, assertion.Value), actual, bindings)
if err != nil {
return errs, err
}
Expand Down

0 comments on commit 8e2e4c7

Please sign in to comment.