summaryrefslogtreecommitdiff
path: root/pkg/util/io_test.go
diff options
context:
space:
mode:
authorKyren223 <ulmliad223@gmail.com>2024-10-16 16:03:21 +0300
committerKyren223 <ulmliad223@gmail.com>2024-10-16 16:03:21 +0300
commit8ff0032860cc4053e6f129e10da09535c27b55e8 (patch)
tree809a418e61cfd91ef68ef02bd00a2ba2ecc70810 /pkg/util/io_test.go
parent92306aea9b63181330f03b453dcc0d9e4fece17f (diff)
fix: channel reader incorrectly reading anything more than bufferSize
Diffstat (limited to 'pkg/util/io_test.go')
-rw-r--r--pkg/util/io_test.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/pkg/util/io_test.go b/pkg/util/io_test.go
index 9d63e5d..f05b833 100644
--- a/pkg/util/io_test.go
+++ b/pkg/util/io_test.go
@@ -16,9 +16,44 @@ func TestChannelReader(t *testing.T) {
select {
case data := <-reader.Out:
if !bytes.Equal(b, data) {
- t.Errorf("TestChannelReader() %v != %v", b, data)
+ t.Errorf("%v != %v", b, data)
}
case err := <-reader.Err:
- t.Errorf("TestChannelReader() err = %v", err)
+ t.Errorf("reading err: %v", err)
+ }
+}
+
+func TestChannelReaderMultiPartRead(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ defer cancel()
+
+ b := []byte("Testing FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting FramerTesting Framer")
+ b1 := b[:512]
+ b2 := b[512:]
+ reader := NewChannelReader(ctx, bytes.NewReader(b))
+
+ counter := 0
+outer:
+ for {
+ select {
+ case data := <-reader.Out:
+ if counter == 0 {
+ if !bytes.Equal(b1, data) {
+ t.Errorf("%v != %v", b, data)
+ }
+ } else {
+ if !bytes.Equal(b2[:len(data)], data) {
+ t.Errorf("%v != %v", b, data)
+ }
+ }
+ counter++
+ if counter == 2 {
+ break outer
+ }
+
+ case err := <-reader.Err:
+ t.Errorf("reading err: %v", err)
+ break outer
+ }
}
}