MCPcopy
hub / github.com/kubernetes/client-go / testJSONPath

Function testJSONPath

util/jsonpath/jsonpath_test.go:37–63  ·  view source on GitHub ↗
(tests []jsonpathTest, allowMissingKeys bool, t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func testJSONPath(tests []jsonpathTest, allowMissingKeys bool, t *testing.T) {
38 for _, test := range tests {
39 j := New(test.name)
40 j.AllowMissingKeys(allowMissingKeys)
41 err := j.Parse(test.template)
42 if err != nil {
43 if !test.expectError {
44 t.Errorf("in %s, parse %s error %v", test.name, test.template, err)
45 }
46 continue
47 }
48 buf := new(bytes.Buffer)
49 err = j.Execute(buf, test.input)
50 if test.expectError {
51 if err == nil {
52 t.Errorf("in %s, expected execute error", test.name)
53 }
54 continue
55 } else if err != nil {
56 t.Errorf("in %s, execute error %v", test.name, err)
57 }
58 out := buf.String()
59 if out != test.expect {
60 t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out)
61 }
62 }
63}
64
65// testJSONPathSortOutput test cases related to map, the results may print in random order
66func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) {

Callers 6

TestStructInputFunction · 0.85
TestJSONInputFunction · 0.85
TestKubernetesFunction · 0.85
TestNegativeIndexFunction · 0.85
TestStepFunction · 0.85

Calls 6

AllowMissingKeysMethod · 0.80
ExecuteMethod · 0.80
NewFunction · 0.70
ErrorfMethod · 0.65
StringMethod · 0.65
ParseMethod · 0.45

Tested by

no test coverage detected