-
Notifications
You must be signed in to change notification settings - Fork 1
/
autobatch_test.go
51 lines (42 loc) · 927 Bytes
/
autobatch_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
package autobatch
import (
"context"
"math/rand"
"testing"
"time"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-datastore"
blockstore "github.com/ipfs/go-ipfs-blockstore"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func randBlock() blocks.Block {
data := make([]byte, 2048)
rand.Read(data)
return blocks.NewBlock(data)
}
func TestBasicAutobatching(t *testing.T) {
ctx := context.TODO()
cold := blockstore.NewBlockstore(datastore.NewMapDatastore())
wal := blockstore.NewBlockstore(datastore.NewMapDatastore())
ab, err := NewBlockstore(cold, wal, 100, 100, false)
if err != nil {
t.Fatal(err)
}
blk1 := randBlock()
if err := ab.PutMany(ctx, []blocks.Block{blk1}); err != nil {
t.Fatal(err)
}
has, err := ab.Has(ctx, blk1.Cid())
if err != nil {
t.Fatal(err)
}
if !has {
t.Fatal("should have")
}
_, err = ab.Get(ctx, blk1.Cid())
if err != nil {
t.Fatal(err)
}
}