v / vlib / db / mysql / utils_test.v
22 lines · 17 sloc · 586 bytes · 07c796b670d9e498ccb25605af189617f61ec295
Raw
1// vtest build: started_mysqld?
2module mysql
3
4import json
5
6struct MysqlErrorPayload {
7 data string
8}
9
10fn 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