diff options
author | Paramtamtam <[email protected]> | 2019-12-24 10:48:49 +0500 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-24 10:48:49 +0500 |
commit | fbd2022729ab7ffe4eee8ba8b7357ba179e4d010 (patch) | |
tree | fa6b66b18259282b2efe00a41c445a3fa40aa701 /error_buffer_test.go | |
parent | 3f7d8bc007a4efdd48bb16253c2686006f0f9cda (diff) | |
parent | 75a817edcff22e721dcc3a7fa5590b866f630403 (diff) |
Merge branch 'master' into master
Diffstat (limited to 'error_buffer_test.go')
-rw-r--r-- | error_buffer_test.go | 91 |
1 files changed, 73 insertions, 18 deletions
diff --git a/error_buffer_test.go b/error_buffer_test.go index 81107935..c163ea43 100644 --- a/error_buffer_test.go +++ b/error_buffer_test.go @@ -7,16 +7,29 @@ import ( func TestErrBuffer_Write_Len(t *testing.T) { buf := newErrBuffer() - defer buf.Close() - - buf.Write([]byte("hello")) + defer func() { + err := buf.Close() + if err != nil { + t.Errorf("error during closing the buffer: error %v", err) + } + }() + + _, err := buf.Write([]byte("hello")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } assert.Equal(t, 5, buf.Len()) assert.Equal(t, "hello", buf.String()) } func TestErrBuffer_Write_Event(t *testing.T) { buf := newErrBuffer() - defer buf.Close() + defer func() { + err := buf.Close() + if err != nil { + t.Errorf("error during closing the buffer: error %v", err) + } + }() tr := make(chan interface{}) buf.Listen(func(event int, ctx interface{}) { @@ -25,8 +38,10 @@ func TestErrBuffer_Write_Event(t *testing.T) { close(tr) }) - buf.Write([]byte("hello\n")) - + _, err := buf.Write([]byte("hello\n")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } <-tr // messages are read @@ -35,7 +50,12 @@ func TestErrBuffer_Write_Event(t *testing.T) { func TestErrBuffer_Write_Event_Separated(t *testing.T) { buf := newErrBuffer() - defer buf.Close() + defer func() { + err := buf.Close() + if err != nil { + t.Errorf("error during closing the buffer: error %v", err) + } + }() tr := make(chan interface{}) buf.Listen(func(event int, ctx interface{}) { @@ -44,9 +64,20 @@ func TestErrBuffer_Write_Event_Separated(t *testing.T) { close(tr) }) - buf.Write([]byte("hel")) - buf.Write([]byte("lo\n")) - buf.Write([]byte("ending")) + _, err := buf.Write([]byte("hel")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } + + _, err = buf.Write([]byte("lo\n")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } + + _, err = buf.Write([]byte("ending")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } <-tr assert.Equal(t, 0, buf.Len()) @@ -55,11 +86,27 @@ func TestErrBuffer_Write_Event_Separated(t *testing.T) { func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) { buf := newErrBuffer() - defer buf.Close() - - buf.Write([]byte("hel")) - buf.Write([]byte("lo\n")) - buf.Write([]byte("ending")) + defer func() { + err := buf.Close() + if err != nil { + t.Errorf("error during closing the buffer: error %v", err) + } + }() + + _, err := buf.Write([]byte("hel")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } + + _, err = buf.Write([]byte("lo\n")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } + + _, err = buf.Write([]byte("ending")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } assert.Equal(t, 12, buf.Len()) assert.Equal(t, "hello\nending", buf.String()) @@ -67,9 +114,17 @@ func TestErrBuffer_Write_Event_Separated_NoListener(t *testing.T) { func TestErrBuffer_Write_Remaining(t *testing.T) { buf := newErrBuffer() - defer buf.Close() - - buf.Write([]byte("hel")) + defer func() { + err := buf.Close() + if err != nil { + t.Errorf("error during closing the buffer: error %v", err) + } + }() + + _, err := buf.Write([]byte("hel")) + if err != nil { + t.Errorf("fail to write: error %v", err) + } assert.Equal(t, 3, buf.Len()) assert.Equal(t, "hel", buf.String()) |