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

Function testJSONPathSortOutput

util/jsonpath/jsonpath_test.go:66–88  ·  view source on GitHub ↗

testJSONPathSortOutput test cases related to map, the results may print in random order

(tests []jsonpathTest, t *testing.T)

Source from the content-addressed store, hash-verified

64
65// testJSONPathSortOutput test cases related to map, the results may print in random order
66func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) {
67 for _, test := range tests {
68 j := New(test.name)
69 err := j.Parse(test.template)
70 if err != nil {
71 t.Errorf("in %s, parse %s error %v", test.name, test.template, err)
72 }
73 buf := new(bytes.Buffer)
74 err = j.Execute(buf, test.input)
75 if err != nil {
76 t.Errorf("in %s, execute error %v", test.name, err)
77 }
78 out := buf.String()
79 //since map is visited in random order, we need to sort the results.
80 sortedOut := strings.Fields(out)
81 sort.Strings(sortedOut)
82 sortedExpect := strings.Fields(test.expect)
83 sort.Strings(sortedExpect)
84 if !reflect.DeepEqual(sortedOut, sortedExpect) {
85 t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out)
86 }
87 }
88}
89
90func testFailJSONPath(tests []jsonpathTest, t *testing.T) {
91 for _, test := range tests {

Callers 1

TestKubernetesFunction · 0.85

Calls 5

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

Tested by

no test coverage detected