2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014-2020 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 // Testing network connection that satisfies net.Conn interface
26 // Can send predefined messages and store all written ones
27 type TestingConn struct {
33 func NewTestingConn() *TestingConn {
34 inbound := make(chan string, 8)
35 outbound := make(chan string, 8)
36 return &TestingConn{inbound: inbound, outbound: outbound}
39 func (conn TestingConn) Error() string {
40 return "i am finished"
43 func (conn *TestingConn) Read(b []byte) (n int, err error) {
48 for n, bt := range append([]byte(msg), CRLF...) {
51 return len(msg) + 2, nil
56 func (a MyAddr) String() string {
59 func (a MyAddr) Network() string {
63 func (conn *TestingConn) Write(b []byte) (n int, err error) {
64 conn.outbound <- string(b)
68 func (conn *TestingConn) Close() error {
74 func (conn TestingConn) LocalAddr() net.Addr {
78 func (conn TestingConn) RemoteAddr() net.Addr {
82 func (conn TestingConn) SetDeadline(t time.Time) error {
86 func (conn TestingConn) SetReadDeadline(t time.Time) error {
90 func (conn TestingConn) SetWriteDeadline(t time.Time) error {