| 11 | ) |
| 12 | |
| 13 | func jsonPath(opChain *chain, value interface{}, path string) *Value { |
| 14 | if opChain.failed() { |
| 15 | return newValue(opChain, nil) |
| 16 | } |
| 17 | |
| 18 | filterFn, err := jsonpath.Prepare(path) |
| 19 | if err != nil { |
| 20 | opChain.fail(AssertionFailure{ |
| 21 | Type: AssertValid, |
| 22 | Actual: &AssertionValue{path}, |
| 23 | Errors: []error{ |
| 24 | errors.New("expected: valid json path"), |
| 25 | err, |
| 26 | }, |
| 27 | }) |
| 28 | return newValue(opChain, nil) |
| 29 | } |
| 30 | |
| 31 | result, err := filterFn(value) |
| 32 | if err != nil { |
| 33 | opChain.fail(AssertionFailure{ |
| 34 | Type: AssertMatchPath, |
| 35 | Actual: &AssertionValue{value}, |
| 36 | Expected: &AssertionValue{path}, |
| 37 | Errors: []error{ |
| 38 | errors.New("expected: value matches given json path"), |
| 39 | err, |
| 40 | }, |
| 41 | }) |
| 42 | return newValue(opChain, nil) |
| 43 | } |
| 44 | |
| 45 | return newValue(opChain, result) |
| 46 | } |
| 47 | |
| 48 | func jsonSchema(opChain *chain, value, schema interface{}) { |
| 49 | if opChain.failed() { |