-
-
Notifications
You must be signed in to change notification settings - Fork 361
/
index_test.go
49 lines (44 loc) · 900 Bytes
/
index_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
package commitlog
import (
"fmt"
"math/rand"
"os"
"path/filepath"
"testing"
"github.com/bmizerany/assert"
)
func TestIndex(t *testing.T) {
path := filepath.Join(os.TempDir(), fmt.Sprintf("commitlogtest%d", rand.Int63()))
os.RemoveAll(path)
os.MkdirAll(path, 0755)
path = filepath.Join(path, "test.index")
idx, err := newIndex(options{
path: path,
})
if err != nil {
t.Fatal(err)
}
entries := []Entry{}
for i := 0; i < 3; i++ {
entries = append(entries, Entry{
int64(i),
int64(i * 5),
})
}
for _, e := range entries {
if err := idx.WriteEntry(e); err != nil {
t.Fatal(err)
}
}
if err = idx.Sync(); err != nil {
t.Fatal(err)
}
act := &Entry{}
for i, exp := range entries {
if err = idx.ReadEntry(act, int64(i*entryWidth)); err != nil {
t.Fatal(err)
}
assert.Equal(t, exp.Offset, act.Offset)
assert.Equal(t, exp.Position, act.Position)
}
}