-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompression_test.go
78 lines (60 loc) · 2.22 KB
/
compression_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
package feedx_test
import (
"bytes"
"github.com/bsm/feedx"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("Compression", func() {
var data = bytes.Repeat([]byte("wxyz"), 1024)
runSharedTest := func(subject feedx.Compression) {
buf := new(bytes.Buffer)
w, err := subject.NewWriter(buf)
Expect(err).NotTo(HaveOccurred())
defer w.Close()
Expect(w.Write(data)).To(Equal(4096))
Expect(w.Write(data)).To(Equal(4096))
Expect(w.Close()).To(Succeed())
r, err := subject.NewReader(buf)
Expect(err).NotTo(HaveOccurred())
defer r.Close()
p := make([]byte, 20)
Expect(r.Read(p)).To(Equal(20))
Expect(string(p)).To(Equal("wxyzwxyzwxyzwxyzwxyz"))
Expect(r.Close()).To(Succeed())
}
It("detects the format", func() {
Expect(feedx.DetectCompression("/path/to/file.json")).To(Equal(feedx.NoCompression))
Expect(feedx.DetectCompression("/path/to/file.json.gz")).To(Equal(feedx.GZipCompression))
Expect(feedx.DetectCompression("/path/to/file.jsonz")).To(Equal(feedx.GZipCompression))
Expect(feedx.DetectCompression("/path/to/file.pb")).To(Equal(feedx.NoCompression))
Expect(feedx.DetectCompression("/path/to/file.pb.gz")).To(Equal(feedx.GZipCompression))
Expect(feedx.DetectCompression("/path/to/file.pbz")).To(Equal(feedx.GZipCompression))
Expect(feedx.DetectCompression("/path/to/file.flate")).To(Equal(feedx.FlateCompression))
Expect(feedx.DetectCompression("/path/to/file.whatever.flate")).To(Equal(feedx.FlateCompression))
Expect(feedx.DetectCompression("")).To(Equal(feedx.NoCompression))
Expect(feedx.DetectCompression("/path/to/file")).To(Equal(feedx.NoCompression))
Expect(feedx.DetectCompression("/path/to/file.txt")).To(Equal(feedx.NoCompression))
})
Describe("NoCompression", func() {
var subject = feedx.NoCompression
var _ feedx.Compression = subject
It("writes/reads", func() {
runSharedTest(subject)
})
})
Describe("GZipCompression", func() {
var subject = feedx.GZipCompression
var _ feedx.Compression = subject
It("writes/reads", func() {
runSharedTest(subject)
})
})
Describe("FlateCompression", func() {
var subject = feedx.FlateCompression
var _ feedx.Compression = subject
It("writes/reads", func() {
runSharedTest(subject)
})
})
})