testJSONPathSortOutput test cases related to map, the results may print in random order
(tests []jsonpathTest, t *testing.T)
| 64 | |
| 65 | // testJSONPathSortOutput test cases related to map, the results may print in random order |
| 66 | func 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 | |
| 90 | func testFailJSONPath(tests []jsonpathTest, t *testing.T) { |
| 91 | for _, test := range tests { |