CompareJSONReaderBytes compares the reader containing serialized JSON document. Deserializes the JSON documents to determine if they are equal. Return an error if the two JSON documents are not equal.
(r io.Reader, expect []byte)
| 56 | // document. Deserializes the JSON documents to determine if they are equal. |
| 57 | // Return an error if the two JSON documents are not equal. |
| 58 | func CompareJSONReaderBytes(r io.Reader, expect []byte) error { |
| 59 | if r == nil { |
| 60 | return fmt.Errorf("missing body") |
| 61 | } |
| 62 | actual, err := io.ReadAll(r) |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("unable to read, %v", err) |
| 65 | } |
| 66 | |
| 67 | if err := JSONEqual(expect, actual); err != nil { |
| 68 | return fmt.Errorf("JSON documents not equal, %v", err) |
| 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | // CompareXMLReaderBytes compares the reader with expected xml byte |
| 74 | func CompareXMLReaderBytes(r io.Reader, expect []byte) error { |