-
Notifications
You must be signed in to change notification settings - Fork 0
/
delayed_eof_reader_test.go
49 lines (38 loc) · 1014 Bytes
/
delayed_eof_reader_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ioutils_test
import (
"bytes"
"io"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/koofr/go-ioutils"
)
var _ = Describe("DelayedEOFReader", func() {
It("should handle empty reader", func() {
r := NewDelayedEOFReader(bytes.NewReader(nil))
n, err := r.Read([]byte{0})
Expect(err).To(Equal(io.EOF))
Expect(n).To(Equal(0))
})
It("should handle reader", func() {
r := NewDelayedEOFReader(bytes.NewReader([]byte{1}))
p := []byte{0}
n, err := r.Read(p)
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(1))
Expect(p[0]).To(Equal(uint8(1)))
n, err = r.Read([]byte{0})
Expect(err).To(Equal(io.EOF))
Expect(n).To(Equal(0))
})
It("should delay the EOF", func() {
r := NewDelayedEOFReader(NewReadWithEOFReaderLen(1))
p := []byte{0}
n, err := r.Read(p)
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(1))
Expect(p).To(Equal([]byte{1}))
n, err = r.Read([]byte{0})
Expect(err).To(Equal(io.EOF))
Expect(n).To(Equal(0))
})
})