forked from bsm/sntable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sntable_test.go
48 lines (40 loc) · 1001 Bytes
/
sntable_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
package sntable_test
import (
"bytes"
"fmt"
"math/rand"
"testing"
"github.com/bsm/sntable"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestSuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "sntable")
}
// --------------------------------------------------------------------
func seedReader(sz int) (*sntable.Reader, error) {
buf := new(bytes.Buffer)
if err := seedTable(buf, sz); err != nil {
return nil, err
}
return sntable.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
}
func seedTable(buf *bytes.Buffer, sz int) error {
twr := sntable.NewWriter(buf, &sntable.WriterOptions{
Compression: sntable.NoCompression,
})
rnd := rand.New(rand.NewSource(1))
val := make([]byte, 128)
for i := 0; i < sz; i++ {
key := uint64(i * 4)
if _, err := rnd.Read(val); err != nil {
return err
}
val = append(val[:120], fmt.Sprintf("%08d", key)...)
if err := twr.Append(key, val); err != nil {
return err
}
}
return twr.Close()
}