github.com/ManabuSeki/goa-v1@v1.4.3/middleware/xray/net_conn_testing.go (about) 1 package xray 2 3 import ( 4 "net" 5 "time" 6 ) 7 8 // TestNetConn is a mock net.Conn 9 type TestNetConn struct { 10 *TestClientExpectation 11 } 12 13 // Make sure TestNetConn implements net.Conn 14 var _ (net.Conn) = (*TestNetConn)(nil) 15 16 // NewTestNetConn creates a mock net.Conn which uses expectations set by the 17 // tests to implement the behavior. 18 func NewTestNetConn() *TestNetConn { 19 return &TestNetConn{NewTestClientExpectation()} 20 } 21 22 // Read runs any preset expectation. 23 func (c *TestNetConn) Read(b []byte) (n int, err error) { 24 if e := c.Expectation("Read"); e != nil { 25 return e.(func(b []byte) (n int, err error))(b) 26 } 27 return 0, nil 28 } 29 30 // Write runs any preset expectation. 31 func (c *TestNetConn) Write(b []byte) (n int, err error) { 32 if e := c.Expectation("Write"); e != nil { 33 return e.(func(b []byte) (n int, err error))(b) 34 } 35 return 0, nil 36 } 37 38 // Close runs any preset expectation. 39 func (c *TestNetConn) Close() error { 40 if e := c.Expectation("Close"); e != nil { 41 return e.(func() error)() 42 } 43 return nil 44 } 45 46 // LocalAddr runs any preset expectation. 47 func (c *TestNetConn) LocalAddr() net.Addr { 48 if e := c.Expectation("LocalAddr"); e != nil { 49 return e.(func() net.Addr)() 50 } 51 return nil 52 } 53 54 // RemoteAddr runs any preset expectation. 55 func (c *TestNetConn) RemoteAddr() net.Addr { 56 if e := c.Expectation("RemoteAddr"); e != nil { 57 return e.(func() net.Addr)() 58 } 59 return nil 60 } 61 62 // SetDeadline runs any preset expectation. 63 func (c *TestNetConn) SetDeadline(t time.Time) error { 64 if e := c.Expectation("SetDeadline"); e != nil { 65 return e.(func(t time.Time) error)(t) 66 } 67 return nil 68 } 69 70 // SetReadDeadline runs any preset expectation. 71 func (c *TestNetConn) SetReadDeadline(t time.Time) error { 72 if e := c.Expectation("SetReadDeadline"); e != nil { 73 return e.(func(t time.Time) error)(t) 74 } 75 return nil 76 } 77 78 // SetWriteDeadline runs any preset expectation. 79 func (c *TestNetConn) SetWriteDeadline(t time.Time) error { 80 if e := c.Expectation("SetWriteDeadline"); e != nil { 81 return e.(func(t time.Time) error)(t) 82 } 83 return nil 84 }