-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer_test.go
75 lines (64 loc) · 1.36 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
68
69
70
71
72
73
74
75
package gopar3
import (
"bytes"
"encoding/hex"
"hash/crc32"
"testing"
"github.com/dkotik/gopar3/telomeres"
)
func TestCRC32(t *testing.T) {
testCases := [...]struct {
RawData string
HexCRC32 string
}{ // https://crccalc.com/
{RawData: "123456789", HexCRC32: "E3069283"},
{RawData: "This site uses cookies for analytics and ads.", HexCRC32: "7EC18835"},
{RawData: "9f834hkjfnfo783ofhlkdfh7834", HexCRC32: "FBA9ED08"},
}
for _, tc := range testCases {
w := crc32.New(castagnoliTable)
_, err := w.Write([]byte(tc.RawData))
if err != nil {
t.Fatal(err)
}
dehex, err := hex.DecodeString(tc.HexCRC32)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(w.Sum(nil), dehex) {
t.Fatal("did not match crc32.Castagnoli check")
}
}
}
func TestWriteShardsWithTagAndChecksum(t *testing.T) {
testCases := [...]string{
"1",
"22",
"333",
"4444",
"55555",
"6666:66666",
}
b := &bytes.Buffer{}
tlm, err := telomeres.NewEncoder(b, 4)
if err != nil {
t.Fatal(err)
}
sw := &ShardWriter{
Encoder: tlm,
Tagger: NewSequentialTagger(Tag{}, 5),
Hash: crc32.New(castagnoliTable),
}
shards := make(chan []byte, 2)
go func() {
defer close(shards)
for _, tc := range testCases {
shards <- []byte(tc)
}
}()
if err = sw.Stream(shards); err != nil {
t.Fatal(err)
}
t.Logf("%q", b.String())
// t.Fatal("check result")
}