MCPcopy
hub / github.com/go-sql-driver/mysql / TestReadPacketFail

Function TestReadPacketFail

packets_test.go:273–314  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestReadPacketFail(t *testing.T) {
274 conn := new(mockConn)
275 mc := &mysqlConn{
276 netConn: conn,
277 buf: newBuffer(),
278 closech: make(chan struct{}),
279 cfg: NewConfig(),
280 }
281
282 // illegal empty (stand-alone) packet
283 conn.data = []byte{0x00, 0x00, 0x00, 0x00}
284 conn.maxReads = 1
285 _, err := mc.readPacket()
286 if err != ErrInvalidConn {
287 t.Errorf("expected ErrInvalidConn, got %v", err)
288 }
289
290 // reset
291 conn.reads = 0
292 mc.sequence = 0
293 mc.buf = newBuffer()
294
295 // fail to read header
296 conn.closed = true
297 _, err = mc.readPacket()
298 if err != ErrInvalidConn {
299 t.Errorf("expected ErrInvalidConn, got %v", err)
300 }
301
302 // reset
303 conn.closed = false
304 conn.reads = 0
305 mc.sequence = 0
306 mc.buf = newBuffer()
307
308 // fail to read body
309 conn.maxReads = 1
310 _, err = mc.readPacket()
311 if err != ErrInvalidConn {
312 t.Errorf("expected ErrInvalidConn, got %v", err)
313 }
314}
315
316// https://github.com/go-sql-driver/mysql/pull/801
317// not-NUL terminated plugin_name in init packet

Callers

nothing calls this directly

Calls 3

readPacketMethod · 0.95
newBufferFunction · 0.85
NewConfigFunction · 0.85

Tested by

no test coverage detected