forked from abdullin/cellar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbbolt_test.go
48 lines (38 loc) · 864 Bytes
/
bbolt_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 cellar
import (
"fmt"
"sync"
"testing"
"time"
"github.com/boltdb/bolt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pb "github.com/carapace/cellar/proto"
)
var mu = &sync.Mutex{}
var asked int
func newBoltMetaDB() (db *BoltMetaDB) {
mu.Lock()
defer mu.Unlock()
asked++
blt, err := bolt.Open(fmt.Sprintf("testdata/meta%d.bolt", asked), 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
panic(err)
}
db = &BoltMetaDB{DB: blt}
err = db.Init()
if err != nil {
panic(err)
}
return db
}
func TestBoltMetaDB_AddChunk_ListChunk(t *testing.T) {
db := newBoltMetaDB()
err := db.AddChunk(0, &pb.ChunkDto{})
require.NoError(t, err)
err = db.AddChunk(10, &pb.ChunkDto{})
require.NoError(t, err)
chunks, err := db.ListChunks()
require.NoError(t, err)
assert.True(t, len(chunks) == 2)
}