Merge pull request #98057 from zerodayz/wrong-output-with-jsonpath

[jsonpath] fix wrong output when using jsonpath
This commit is contained in:
Kubernetes Prow Robot 2021-05-07 20:29:30 -07:00 committed by GitHub
commit 586ea8a482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -132,6 +132,9 @@ func (j *JSONPath) FindResults(data interface{}) ([][]reflect.Value, error) {
}
continue
}
if len(results) == 0 {
break
}
fullResult = append(fullResult, results)
}
return fullResult, nil

View File

@ -760,6 +760,64 @@ func TestNegativeIndex(t *testing.T) {
)
}
func TestRunningPodsJSONPathOutput(t *testing.T) {
var input = []byte(`{
"kind": "List",
"items": [
{
"kind": "Pod",
"metadata": {
"name": "pod1"
},
"status": {
"phase": "Running"
}
},
{
"kind": "Pod",
"metadata": {
"name": "pod2"
},
"status": {
"phase": "Running"
}
},
{
"kind": "Pod",
"metadata": {
"name": "pod3"
},
"status": {
"phase": "Running"
}
},
{
"resourceVersion": "",
"selfLink": ""
}
]
}`)
var data interface{}
err := json.Unmarshal(input, &data)
if err != nil {
t.Fatal(err)
}
testJSONPath(
[]jsonpathTest{
{
"when range is used in a certain way in script, additional line is printed",
`{range .items[?(.status.phase=="Running")]}{.metadata.name}{" is Running\n"}`,
data,
"pod1 is Running\npod2 is Running\npod3 is Running\n",
false, // expect no error
},
},
true, // allow missing keys
t,
)
}
func TestStep(t *testing.T) {
var input = []byte(
`{