-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_test.go
50 lines (36 loc) · 1.38 KB
/
simple_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
package boltx_test
import (
"testing"
"github.com/simia-tech/boltx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPutInBucketAndGetFromBucket(t *testing.T) {
db, tearDown := setUpTestDB(t)
defer tearDown()
name, key, value := []byte("test"), []byte("test"), []byte("test")
assert.Error(t, boltx.PutInBucket(db, []byte(""), key, value))
require.NoError(t, boltx.PutInBucket(db, name, key, value))
value = boltx.GetFromBucket(db, []byte("missing"), key)
assert.Nil(t, value)
value = boltx.GetFromBucket(db, name, key)
assert.Equal(t, "test", string(value))
}
func TestDeleteFromBucket(t *testing.T) {
db, tearDown := setUpTestDB(t)
defer tearDown()
name, key, value := []byte("test"), []byte("test"), []byte("test")
require.NoError(t, boltx.PutInBucket(db, name, key, value))
assert.NoError(t, boltx.DeleteFromBucket(db, []byte("missing"), key))
assert.NoError(t, boltx.DeleteFromBucket(db, name, key))
}
func TestBucketSize(t *testing.T) {
db, tearDown := setUpTestDB(t)
defer tearDown()
name, key, value := []byte("test"), []byte("test"), []byte("test")
require.NoError(t, boltx.PutInBucket(db, name, key, value))
assert.Equal(t, 0, boltx.BucketSize(db, []byte("missing")))
assert.Equal(t, 1, boltx.BucketSize(db, name))
require.NoError(t, boltx.DeleteFromBucket(db, name, key))
assert.Equal(t, 0, boltx.BucketSize(db, name))
}