-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbadgerdb_test.go
59 lines (50 loc) · 1.45 KB
/
badgerdb_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
package sprout
import (
"fmt"
"math/rand"
"testing"
"github.com/dgraph-io/badger/v3"
)
func TestBadgerDB(t *testing.T) {
db := NewBadger()
t.Run("it successfully puts a new value", func(t *testing.T) {
key, val := []byte("foo"), []byte("var")
err := db.Put(key, val)
if err != nil {
t.Errorf("Expected no error when a value is put in the db, got %v", err)
}
})
t.Run("it gets the previously inserted value", func(t *testing.T) {
key, val := []byte("foo"), []byte("var")
db.Put(key, val)
val, err := db.Get(key)
if err != nil {
t.Errorf("Expected no error when a value is retrieved from the db, got %v", err)
}
if string(val) != "var" {
t.Errorf("Expected to get value 'var', got %s", val)
}
})
}
func TestBadgerDB_WithOptions(t *testing.T) {
tmpDir := fmt.Sprintf("/tmp/badger%d.db", rand.Int())
db := NewBadger(badger.DefaultOptions(tmpDir))
t.Run("it successfully puts a new value", func(t *testing.T) {
key, val := []byte("foo"), []byte("var")
err := db.Put(key, val)
if err != nil {
t.Errorf("Expected no error when a value is put in the db, got %v", err)
}
})
t.Run("it gets the previously inserted value", func(t *testing.T) {
key, val := []byte("foo"), []byte("var")
db.Put(key, val)
val, err := db.Get(key)
if err != nil {
t.Errorf("Expected no error when a value is retrieved from the db, got %v", err)
}
if string(val) != "var" {
t.Errorf("Expected to get value 'var', got %s", val)
}
})
}