change -o template to -o go-template=...
This commit is contained in:
@@ -34,6 +34,26 @@ type jsonpathTest struct {
|
||||
}
|
||||
|
||||
func testJSONPath(tests []jsonpathTest, t *testing.T) {
|
||||
for _, test := range tests {
|
||||
j := New(test.name)
|
||||
err := j.Parse(test.template)
|
||||
if err != nil {
|
||||
t.Errorf("in %s, parse %s error %v", test.name, test.template, err)
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
err = j.Execute(buf, test.input)
|
||||
if err != nil {
|
||||
t.Errorf("in %s, execute error %v", test.name, err)
|
||||
}
|
||||
out := buf.String()
|
||||
if out != test.expect {
|
||||
t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// testJSONPathSortOutput test testcases related to map, the results may print in random order
|
||||
func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) {
|
||||
for _, test := range tests {
|
||||
j := New(test.name)
|
||||
err := j.Parse(test.template)
|
||||
@@ -218,8 +238,6 @@ func TestKubenates(t *testing.T) {
|
||||
`127.0.0.1 127.0.0.2 127.0.0.3`},
|
||||
{"double range", "{range .items[*]}{range .status.addresses[*]}{.address}, {end}{end}", nodesData,
|
||||
`127.0.0.1, 127.0.0.2, 127.0.0.3, `},
|
||||
// TODO: fix & uncomment the case bellow (#13024)
|
||||
// {"recursive name", "{..name}", nodesData, `127.0.0.1 127.0.0.2 myself e2e`},
|
||||
{"item name", "{.items[*].metadata.name}", nodesData, `127.0.0.1 127.0.0.2`},
|
||||
{"union nodes capacity", "{.items[*]['metadata.name', 'status.capacity']}", nodesData,
|
||||
`127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`},
|
||||
@@ -228,4 +246,9 @@ func TestKubenates(t *testing.T) {
|
||||
{"user password", `{.users[?(@.name=="e2e")].user.password}`, &nodesData, "secret"},
|
||||
}
|
||||
testJSONPath(nodesTests, t)
|
||||
|
||||
randomPrintOrderTests := []jsonpathTest{
|
||||
{"recursive name", "{..name}", nodesData, `127.0.0.1 127.0.0.2 myself e2e`},
|
||||
}
|
||||
testJSONPathSortOutput(randomPrintOrderTests, t)
|
||||
}
|
||||
|
Reference in New Issue
Block a user