- Used %q in the error message
- Added a unit-test case Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
This commit is contained in:
parent
cac4c15ef3
commit
4e24aae89d
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue