-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreader_test.go
94 lines (78 loc) · 2.04 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package feedx_test
import (
"context"
"io"
"time"
"github.com/bsm/bfs"
"github.com/bsm/feedx"
"github.com/bsm/feedx/internal/testdata"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("Reader", func() {
var subject *feedx.Reader
var obj *bfs.Object
var ctx = context.Background()
Describe("NewReader", func() {
BeforeEach(func() {
obj = bfs.NewInMemObject("path/to/file.json.gz")
Expect(writeMulti(obj, 3, time.Time{})).To(Succeed())
var err error
subject, err = feedx.NewReader(ctx, obj, nil)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
Expect(subject.Close()).To(Succeed())
})
It("reads", func() {
data, err := io.ReadAll(subject)
Expect(err).NotTo(HaveOccurred())
Expect(len(data)).To(Equal(111))
Expect(subject.NumRead()).To(Equal(int64(0)))
})
It("decodes", func() {
var msgs []*testdata.MockMessage
for {
var msg testdata.MockMessage
err := subject.Decode(&msg)
if err == io.EOF {
break
}
Expect(err).NotTo(HaveOccurred())
msgs = append(msgs, &msg)
}
Expect(msgs).To(ConsistOf(seed(), seed(), seed()))
Expect(subject.NumRead()).To(Equal(int64(3)))
})
})
Describe("MultiReader", func() {
BeforeEach(func() {
obj = bfs.NewInMemObject("path/to/file.json.gz")
Expect(writeMulti(obj, 3, time.Time{})).To(Succeed())
subject = feedx.MultiReader(ctx, []*bfs.Object{obj, obj}, nil)
})
AfterEach(func() {
Expect(subject.Close()).To(Succeed())
})
It("reads", func() {
data, err := io.ReadAll(subject)
Expect(err).NotTo(HaveOccurred())
Expect(len(data)).To(Equal(222))
Expect(subject.NumRead()).To(Equal(int64(0)))
})
It("decodes", func() {
var msgs []*testdata.MockMessage
for {
var msg testdata.MockMessage
err := subject.Decode(&msg)
if err == io.EOF {
break
}
Expect(err).NotTo(HaveOccurred())
msgs = append(msgs, &msg)
}
Expect(msgs).To(ConsistOf(seed(), seed(), seed(), seed(), seed(), seed()))
Expect(subject.NumRead()).To(Equal(int64(6)))
})
})
})