| 1 | // vtest build: started_mysqld? |
| 2 | module mysql |
| 3 | |
| 4 | import json |
| 5 | |
| 6 | struct MysqlErrorPayload { |
| 7 | data string |
| 8 | } |
| 9 | |
| 10 | fn test_clone_mysql_cstring_keeps_json_encodable_error_text() { |
| 11 | mut backing := |
| 12 | "Incorrect string value: 'undefined' for function uuid_to_bin; code: 1411".bytes() |
| 13 | backing << u8(0) |
| 14 | msg := clone_mysql_cstring(backing.data) |
| 15 | |
| 16 | backing[0] = 0xff |
| 17 | |
| 18 | assert msg == "Incorrect string value: 'undefined' for function uuid_to_bin; code: 1411" |
| 19 | assert json.encode(MysqlErrorPayload{ |
| 20 | data: msg |
| 21 | }) == '{"data":"Incorrect string value: \'undefined\' for function uuid_to_bin; code: 1411"}' |
| 22 | } |
| 23 | |