UnmarshalAndMarshalJsonString is used to normalize expected json type value to compare the actual value. JSON type value is in string format, and since Postrges JSON type preserves the input string if valid, it cannot be compared to the returned map as json.Marshal method space padded key value pair
(val string)
| 642 | // To allow result matching, we unmarshal and marshal the expected string. This causes missing check |
| 643 | // for the identical format as the input of the json string. |
| 644 | func UnmarshalAndMarshalJsonString(val string) string { |
| 645 | var decoded any |
| 646 | err := json.Unmarshal([]byte(val), &decoded) |
| 647 | if err != nil { |
| 648 | panic(err) |
| 649 | } |
| 650 | ret, err := json.Marshal(decoded) |
| 651 | if err != nil { |
| 652 | panic(err) |
| 653 | } |
| 654 | return string(ret) |
| 655 | } |
| 656 | |
| 657 | // NormalizeValToString normalizes values into types that can be compared. |
| 658 | // JSON types, any pg types and time and decimal type values are converted into string value. |
no test coverage detected