From c5dba4360acff23a89f301235401ddfe19ab99a8 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 15 Oct 2024 18:17:46 +0300 Subject: fix: channel reader blocks until EOF or an error was received --- pkg/util/io_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pkg/util/io_test.go (limited to 'pkg/util/io_test.go') 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) + } +} -- cgit v1.3.1