diff options
| author | Kyren223 <ulmliad223@gmail.com> | 2024-10-15 18:17:46 +0300 |
|---|---|---|
| committer | Kyren223 <ulmliad223@gmail.com> | 2024-10-15 18:17:46 +0300 |
| commit | c5dba4360acff23a89f301235401ddfe19ab99a8 (patch) | |
| tree | af968d5fe4f655930dd07bc90a77e3ae1e83068a /pkg/util/io_test.go | |
| parent | 77dca0e1dfd609851a4c80ebb769b21838ec7093 (diff) | |
fix: channel reader blocks until EOF or an error was received
Diffstat (limited to 'pkg/util/io_test.go')
| -rw-r--r-- | pkg/util/io_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/util/io_test.go b/pkg/util/io_test.go new file mode 100644 index 0000000..9d63e5d --- /dev/null +++ b/pkg/util/io_test.go @@ -0,0 +1,24 @@ +package util + +import ( + "bytes" + "context" + "testing" + "time" +) + +func TestChannelReader(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + b := []byte{1, 2, 3, 4, 5, 6, 7, 8} + reader := NewChannelReader(ctx, bytes.NewReader(b)) + + select { + case data := <-reader.Out: + if !bytes.Equal(b, data) { + t.Errorf("TestChannelReader() %v != %v", b, data) + } + case err := <-reader.Err: + t.Errorf("TestChannelReader() err = %v", err) + } +} |
