diff options
author | Wolfy-J <[email protected]> | 2019-12-23 14:43:47 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-12-23 14:43:47 +0300 |
commit | c7b0a4a81827284f7565c56aa476eea34fb6382f (patch) | |
tree | ee30e93169c37fb058fbe55af6b3f954eabd9646 /error_buffer_test.go | |
parent | 7f694966730f6dac09d0d0ea3bf51276b8e4dfe4 (diff) |
- test fixes
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()) |