From 8e2e4c75b44ee82e065e64265603ba1e08bb6dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 28 Nov 2023 22:11:13 +0100 Subject: [PATCH] chore: remove error prone validate func (#233) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/engine/assert/assert.go | 8 -------- pkg/engine/assert/match.go | 8 ++++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pkg/engine/assert/assert.go b/pkg/engine/assert/assert.go index cfd8ac95..a778d77d 100644 --- a/pkg/engine/assert/assert.go +++ b/pkg/engine/assert/assert.go @@ -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) } diff --git a/pkg/engine/assert/match.go b/pkg/engine/assert/match.go index 1b77d4fc..c3b8aaf3 100644 --- a/pkg/engine/assert/match.go +++ b/pkg/engine/assert/match.go @@ -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 } @@ -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 } @@ -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 } @@ -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 }