(tests []jsonpathTest, allowMissingKeys bool, t *testing.T)
| 35 | } |
| 36 | |
| 37 | func 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 |
| 66 | func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) { |
no test coverage detected