From 0d7d875b9f0d370d0ca428cb08e2ac24dd685086 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Mon, 22 Aug 2011 23:22:46 +0100 Subject: [PATCH] Add Send method for mockNetConn, and make Read/Write return errors when closed. --- client/mocknetconn_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/mocknetconn_test.go b/client/mocknetconn_test.go index 89fce62..afd57bc 100644 --- a/client/mocknetconn_test.go +++ b/client/mocknetconn_test.go @@ -45,7 +45,11 @@ func MockNetConn(t *testing.T) (*mockNetConn) { return m } -// Test helper +// Test helpers +func (m *mockNetConn) Send(s string) { + m.In <- s + "\r\n" +} + func (m *mockNetConn) Expect(e string) { s := <-m.Out if e + "\r\n" != s { @@ -56,12 +60,18 @@ func (m *mockNetConn) Expect(e string) { // Implement net.Conn interface func (m *mockNetConn) Read(b []byte) (int, os.Error) { + if m.closed { + return 0, os.NewError("EOF") + } s := <-m.in copy(b, s) return len(s), nil } func (m *mockNetConn) Write(s []byte) (int, os.Error) { + if m.closed { + return 0, os.NewError("Can't write to closed socket.") + } b := make([]byte, len(s)) copy(b, s) m.out <- b