Skip to content

Commit

Permalink
path
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Sep 17, 2024
1 parent 2cc0104 commit c167017
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pkg/engine/assert/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
)

func Parse(ctx context.Context, assertion any) (Assertion, error) {
func Parse(ctx context.Context, path *field.Path, assertion any) (Assertion, error) {

Check warning on line 18 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L18

Added line #L18 was not covered by tests
switch reflectutils.GetKind(assertion) {
case reflect.Slice:
node := sliceNode{}
valueOf := reflect.ValueOf(assertion)
for i := 0; i < valueOf.Len(); i++ {
sub, err := Parse(ctx, valueOf.Index(i).Interface())
sub, err := Parse(ctx, path.Index(i), valueOf.Index(i).Interface())
if err != nil {
return nil, err
}
Expand All @@ -32,16 +32,16 @@ func Parse(ctx context.Context, assertion any) (Assertion, error) {
node := mapNode{}
iter := reflect.ValueOf(assertion).MapRange()
for iter.Next() {
sub, err := Parse(ctx, iter.Value().Interface())
// TODO: key in path
sub, err := Parse(ctx, path, iter.Value().Interface())
if err != nil {
return nil, err
}
node[iter.Key().Interface()] = sub

Check warning on line 40 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L35-L40

Added lines #L35 - L40 were not covered by tests
}
return node, nil

Check warning on line 42 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L42

Added line #L42 was not covered by tests
default:
// TODO: propagate path
return newScalarNode(ctx, nil, assertion)
return newScalarNode(ctx, path, assertion)

Check warning on line 44 in pkg/engine/assert/parse.go

View check run for this annotation

Codecov / codecov/patch

pkg/engine/assert/parse.go#L44

Added line #L44 was not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/matching/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert,
var fails []Result
path := path.Child("any")
for i, assertion := range match.Any {
parsed, err := assert.Parse(ctx, assertion.Check.Value)
parsed, err := assert.Parse(ctx, path.Index(i).Child("check"), assertion.Check.Value)
if err != nil {
return fails, err
}

Check warning on line 54 in pkg/matching/match.go

View check run for this annotation

Codecov / codecov/patch

pkg/matching/match.go#L53-L54

Added lines #L53 - L54 were not covered by tests
Expand Down Expand Up @@ -76,7 +76,7 @@ func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert,
var fails []Result
path := path.Child("all")
for i, assertion := range match.All {
parsed, err := assert.Parse(ctx, assertion.Check.Value)
parsed, err := assert.Parse(ctx, path.Index(i).Child("check"), assertion.Check.Value)
if err != nil {
return fails, err
}

Check warning on line 82 in pkg/matching/match.go

View check run for this annotation

Codecov / codecov/patch

pkg/matching/match.go#L81-L82

Added lines #L81 - L82 were not covered by tests
Expand Down Expand Up @@ -126,7 +126,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 any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) {
var errs field.ErrorList
for i, assertion := range assertions {
parsed, err := assert.Parse(ctx, assertion.Value)
parsed, err := assert.Parse(ctx, path.Index(i), assertion.Value)
if err != nil {
return errs, err
}

Check warning on line 132 in pkg/matching/match.go

View check run for this annotation

Codecov / codecov/patch

pkg/matching/match.go#L131-L132

Added lines #L131 - L132 were not covered by tests
Expand All @@ -145,7 +145,7 @@ func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any,
func MatchAll(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) {
var errs field.ErrorList
for i, assertion := range assertions {
parsed, err := assert.Parse(ctx, assertion.Value)
parsed, err := assert.Parse(ctx, path.Index(i), assertion.Value)
if err != nil {
return errs, err
}

Check warning on line 151 in pkg/matching/match.go

View check run for this annotation

Codecov / codecov/patch

pkg/matching/match.go#L150-L151

Added lines #L150 - L151 were not covered by tests
Expand Down

0 comments on commit c167017

Please sign in to comment.