From 4d28b4159a424346a5c5f24f90ec57e04f495280 Mon Sep 17 00:00:00 2001
From: Daniel Czerwonk <daniel@dan-nrw.de>
Date: Tue, 26 Jun 2018 17:44:08 +0200
Subject: [PATCH] added tests for conn mock

---
 testing/conn_mock.go      |  2 +-
 testing/conn_mock_test.go | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 testing/conn_mock_test.go

diff --git a/testing/conn_mock.go b/testing/conn_mock.go
index 86e8e1ae..893cd446 100644
--- a/testing/conn_mock.go
+++ b/testing/conn_mock.go
@@ -27,6 +27,6 @@ func (m *MockConn) Read(b []byte) (n int, err error) {
 		count = len(m.Bytes)
 	}
 
-	copy(m.Bytes[0:count], b)
+	copy(b, m.Bytes[0:count])
 	return count, nil
 }
diff --git a/testing/conn_mock_test.go b/testing/conn_mock_test.go
new file mode 100644
index 00000000..b77bd063
--- /dev/null
+++ b/testing/conn_mock_test.go
@@ -0,0 +1,28 @@
+package testing
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestWrite(t *testing.T) {
+	m := &MockConn{}
+
+	payload := []byte{1, 2, 3}
+	m.Write(payload)
+
+	assert.Equal(t, payload, m.Bytes)
+}
+
+func TestRead(t *testing.T) {
+	m := &MockConn{}
+
+	payload := []byte{1, 2, 3}
+	m.Bytes = payload
+
+	buffer := make([]byte, 4)
+	m.Read(buffer)
+
+	assert.Equal(t, payload, buffer[:3])
+}
-- 
GitLab