2021-09-05 14:49:38 +02:00
|
|
|
package mocks
|
2021-06-08 23:59:30 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Conn is a mockable net.Conn.
|
|
|
|
type Conn struct {
|
|
|
|
MockRead func(b []byte) (int, error)
|
|
|
|
MockWrite func(b []byte) (int, error)
|
|
|
|
MockClose func() error
|
|
|
|
MockLocalAddr func() net.Addr
|
|
|
|
MockRemoteAddr func() net.Addr
|
|
|
|
MockSetDeadline func(t time.Time) error
|
|
|
|
MockSetReadDeadline func(t time.Time) error
|
|
|
|
MockSetWriteDeadline func(t time.Time) error
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// Read calls MockRead.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) Read(b []byte) (int, error) {
|
|
|
|
return c.MockRead(b)
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// Write calls MockWrite.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) Write(b []byte) (int, error) {
|
|
|
|
return c.MockWrite(b)
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// Close calls MockClose.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) Close() error {
|
|
|
|
return c.MockClose()
|
|
|
|
}
|
|
|
|
|
2021-07-02 10:39:14 +02:00
|
|
|
// LocalAddr calls MockLocalAddr.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) LocalAddr() net.Addr {
|
|
|
|
return c.MockLocalAddr()
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// RemoteAddr calls MockRemoteAddr.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) RemoteAddr() net.Addr {
|
|
|
|
return c.MockRemoteAddr()
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// SetDeadline calls MockSetDeadline.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) SetDeadline(t time.Time) error {
|
|
|
|
return c.MockSetDeadline(t)
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// SetReadDeadline calls MockSetReadDeadline.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) SetReadDeadline(t time.Time) error {
|
|
|
|
return c.MockSetReadDeadline(t)
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:00:44 +02:00
|
|
|
// SetWriteDeadline calls MockSetWriteDeadline.
|
2021-06-08 23:59:30 +02:00
|
|
|
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
|
|
|
return c.MockSetWriteDeadline(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ net.Conn = &Conn{}
|