-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwriter_test.go
67 lines (54 loc) · 1.91 KB
/
writer_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
package feedx_test
import (
"bytes"
"context"
"time"
"github.com/bsm/bfs"
"github.com/bsm/feedx"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("Writer", func() {
var plain, compressed *bfs.Object
var ctx = context.Background()
BeforeEach(func() {
plain = bfs.NewInMemObject("path/to/file.json")
compressed = bfs.NewInMemObject("path/to/file.jsonz")
})
It("writes plain", func() {
w := feedx.NewWriter(context.Background(), plain, &feedx.WriterOptions{
LastMod: time.Unix(1515151515, 123456789),
})
defer w.Discard()
Expect(w.Write(bytes.Repeat([]byte{'x'}, 10000))).To(Equal(10000))
Expect(w.Commit()).To(Succeed())
info, err := plain.Head(ctx)
Expect(err).NotTo(HaveOccurred())
Expect(info.Size).To(Equal(int64(10000)))
Expect(info.Metadata).To(Equal(bfs.Metadata{"X-Feedx-Last-Modified": "1515151515123"}))
})
It("writes compressed", func() {
w := feedx.NewWriter(context.Background(), compressed, &feedx.WriterOptions{
LastMod: time.Unix(1515151515, 123456789),
})
defer w.Discard()
Expect(w.Write(bytes.Repeat([]byte{'x'}, 10000))).To(Equal(10000))
Expect(w.Commit()).To(Succeed())
info, err := compressed.Head(ctx)
Expect(err).NotTo(HaveOccurred())
Expect(info.Size).To(BeNumerically("~", 50, 20))
Expect(info.Metadata).To(Equal(bfs.Metadata{"X-Feedx-Last-Modified": "1515151515123"}))
})
It("encodes", func() {
Expect(writeMulti(plain, 10, time.Time{})).To(Succeed())
Expect(writeMulti(compressed, 10, mockTime)).To(Succeed())
info, err := plain.Head(ctx)
Expect(err).NotTo(HaveOccurred())
Expect(info.Size).To(BeNumerically("~", 370, 10))
Expect(info.Metadata).To(Equal(bfs.Metadata{"X-Feedx-Last-Modified": "0"}))
info, err = compressed.Head(ctx)
Expect(err).NotTo(HaveOccurred())
Expect(info.Size).To(BeNumerically("~", 76, 10))
Expect(info.Metadata).To(Equal(bfs.Metadata{"X-Feedx-Last-Modified": "1515151515123"}))
})
})