Skip to content

Commit

Permalink
- Used %q in the error message
Browse files Browse the repository at this point in the history
- Added a unit-test case

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
  • Loading branch information
sergenyalcin committed Dec 12, 2023
1 parent cac4c15 commit 4e24aae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/fieldpath/paved.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func expandWildcards(data any, segments Segments) ([]Segments, error) { //nolint
res = append(res, r...)
}
case nil:
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])}
return nil, errNotFound{errors.Errorf("wildcard field %q is not found in the path", segments[:i])}
default:
return nil, errors.Errorf("%q: unexpected wildcard usage", segments[:i])
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/fieldpath/paved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,14 @@ func TestExpandWildcards(t *testing.T) {
err: errors.Wrap(errors.New("unexpected ']' at position 5"), "cannot parse path \"spec[]\""),
},
},
"NilValue": {
reason: "Requesting a wildcard for an object that has nil value",
path: "spec.containers[*].name",
data: []byte(`{"spec":{"containers": null}}`),
want: want{
err: errors.Wrapf(errNotFound{errors.Errorf("wildcard field %q is not found in the path", "spec.containers")}, "cannot expand wildcards for segments: %q", "spec.containers[*].name"),
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit 4e24aae

Please sign in to comment.