Fix bug in JSON path parser where an error occurs when a range is empty

Kubernetes-commit: 10634c6093c84acc78181a26c93d8785e12802e4
This commit is contained in:
brianpursley
2020-11-01 10:41:19 -05:00
committed by Kubernetes Publisher
parent 4ef01cd5e2
commit 135cef183c
2 changed files with 28 additions and 3 deletions

View File

@@ -393,6 +393,21 @@ func TestKubernetes(t *testing.T) {
testJSONPathSortOutput(randomPrintOrderTests, t)
}
func TestEmptyRange(t *testing.T) {
var input = []byte(`{"items":[]}`)
var emptyList interface{}
err := json.Unmarshal(input, &emptyList)
if err != nil {
t.Error(err)
}
tests := []jsonpathTest{
{"empty range", `{range .items[*]}{.metadata.name}{end}`, &emptyList, "", false},
{"empty nested range", `{range .items[*]}{.metadata.name}{":"}{range @.spec.containers[*]}{.name}{","}{end}{"+"}{end}`, &emptyList, "", false},
}
testJSONPath(tests, true, t)
}
func TestNestedRanges(t *testing.T) {
var input = []byte(`{
"items": [