2 Star 2 Fork 2

tym_hmm/mysql-mydumper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mock.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
天蝎儿 提交于 2021-12-16 21:06 +08:00 . 完成底层封装
/*
* go-mysqlstack
* xelabs.org
*
* Copyright (c) XeLabs
* Copyright 2016 The Go-MySQL-Driver Authors. All rights reserved.
* GPL License
*
*/
package packet
import (
"io"
"net"
"time"
)
var _ net.Conn = &MockConn{}
// MockConn used to mock a net.Conn for testing purposes.
type MockConn struct {
laddr net.Addr
raddr net.Addr
data []byte
closed bool
read int
}
// NewMockConn creates new mock connection.
func NewMockConn() *MockConn {
return &MockConn{}
}
// Read implements the net.Conn interface.
func (m *MockConn) Read(b []byte) (n int, err error) {
// handle the EOF
if len(m.data) == 0 {
err = io.EOF
return
}
n = copy(b, m.data)
m.read += n
m.data = m.data[n:]
return
}
// Write implements the net.Conn interface.
func (m *MockConn) Write(b []byte) (n int, err error) {
m.data = append(m.data, b...)
return len(b), nil
}
// Datas implements the net.Conn interface.
func (m *MockConn) Datas() []byte {
return m.data
}
// Close implements the net.Conn interface.
func (m *MockConn) Close() error {
m.closed = true
return nil
}
// LocalAddr implements the net.Conn interface.
func (m *MockConn) LocalAddr() net.Addr {
return m.laddr
}
// RemoteAddr implements the net.Conn interface.
func (m *MockConn) RemoteAddr() net.Addr {
return m.raddr
}
// SetDeadline implements the net.Conn interface.
func (m *MockConn) SetDeadline(t time.Time) error {
return nil
}
// SetReadDeadline implements the net.Conn interface.
func (m *MockConn) SetReadDeadline(t time.Time) error {
return nil
}
// SetWriteDeadline implements the net.Conn interface.
func (m *MockConn) SetWriteDeadline(t time.Time) error {
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tym_hmm/mysql-mydumper.git
git@gitee.com:tym_hmm/mysql-mydumper.git
tym_hmm
mysql-mydumper
mysql-mydumper
v1.0.3

搜索帮助