@@ -228,3 +228,36 @@ func TestConnWriteFieldValues(t *testing.T) {
228
228
// EOF
229
229
require .Equal (t , []byte {1 , 0 , 0 , 4 , mysql .EOF_HEADER }, clientConn .WriteBuffered [43 :])
230
230
}
231
+
232
+ func TestWriteValue (t * testing.T ) {
233
+ clientConn := & mockconn.MockConn {MultiWrite : true }
234
+ conn := & Conn {Conn : packet .NewConn (clientConn )}
235
+
236
+ // simple OK
237
+ err := conn .WriteValue (mysql .NewResultReserveResultset (0 ))
238
+ require .NoError (t , err )
239
+ expected := []byte {3 , 0 , 0 , 0 , mysql .OK_HEADER , 0 , 0 }
240
+ require .Equal (t , expected , clientConn .WriteBuffered )
241
+
242
+ // reset write buffer
243
+ clientConn .WriteBuffered = []byte {}
244
+
245
+ // resultset with no rows
246
+ rs := mysql .NewResultReserveResultset (1 )
247
+ rs .Fields = []* mysql.Field {{Name : []byte ("a" )}}
248
+ err = conn .WriteValue (rs )
249
+ require .NoError (t , err )
250
+ expected = []byte {1 , 0 , 0 , 1 , mysql .MORE_DATE_HEADER }
251
+ require .Equal (t , expected , clientConn .WriteBuffered [:5 ])
252
+
253
+ // reset write buffer
254
+ clientConn .WriteBuffered = []byte {}
255
+
256
+ // resultset with rows
257
+ rs .Fields = []* mysql.Field {{Name : []byte ("a" )}}
258
+ rs .RowDatas = []mysql.RowData {[]byte {1 , 2 , 3 }}
259
+ err = conn .WriteValue (rs )
260
+ require .NoError (t , err )
261
+ expected = []byte {1 , 0 , 0 , 5 , mysql .MORE_DATE_HEADER }
262
+ require .Equal (t , expected , clientConn .WriteBuffered [:5 ])
263
+ }
0 commit comments