-
Notifications
You must be signed in to change notification settings - Fork 0
/
hint_test.go
57 lines (44 loc) · 1.02 KB
/
hint_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
package gobitcask
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateNewHint(t *testing.T) {
err := os.MkdirAll("test", 0775)
assert.Nil(t, err)
defer os.RemoveAll("test")
h, err := NewHint("test", "1.hint")
assert.Nil(t, err)
assert.NotNil(t, h)
}
func TestSimpleWriteReadHint(t *testing.T) {
err := os.MkdirAll("test", 0775)
assert.Nil(t, err)
defer os.RemoveAll("test")
h, err := NewHint("test", "000001.hint")
assert.Nil(t, err)
assert.NotNil(t, h)
keyDir := NewKeyDir()
key := []byte("key1")
entry := &Entry{
FileID: "000001.merge",
ValueSize: 2,
ValuePos: 3,
Timestamp: uint32(1234),
}
keyDir.Set(key, entry)
err = h.Write(keyDir)
assert.Nil(t, err)
err = h.Close()
assert.Nil(t, err)
h2, err := OpenHint("test", "000001.hint")
assert.Nil(t, err)
assert.NotNil(t, h2)
readKeyDir, err := h2.Read()
assert.Nil(t, err)
assert.NotNil(t, readKeyDir)
fetchedEntry, exist := readKeyDir.Get(key)
assert.True(t, exist)
assert.EqualValues(t, entry, fetchedEntry)
}