- 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:
Sergen Yalçın 2023-12-12 14:57:53 +03:00
parent cac4c15ef3
commit 4e24aae89d
No known key found for this signature in database
GPG Key ID: 9AE9E8BDB520B045
2 changed files with 9 additions and 1 deletions

View File

@ -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])
}

View File

@ -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 {