package pfile import ( "bytes" crand "crypto/rand" "path/filepath" "testing" "git.crumpington.com/public/jldb/lib/wal" "git.crumpington.com/public/jldb/mdb/change" ) func newForTesting(t *testing.T) (*File, *Index) { t.Helper() tmpDir := t.TempDir() filePath := filepath.Join(tmpDir, "pagefile") pf, err := Open(filePath) if err != nil { t.Fatal(err) } idx, err := NewIndex(pf) if err != nil { t.Fatal(err) } return pf, idx } func randBytes(size int) []byte { buf := make([]byte, size) if _, err := crand.Read(buf); err != nil { panic(err) } return buf } func changesToRec(changes []change.Change) wal.Record { buf := &bytes.Buffer{} if err := change.Write(changes, buf); err != nil { panic(err) } return wal.Record{ DataSize: int64(buf.Len()), Reader: buf, } } func TestChangesToRec(t *testing.T) { changes := []change.Change{ { CollectionID: 2, ItemID: 3, Store: true, Data: []byte{2, 3, 4}, WritePageIDs: []uint64{0, 1}, ClearPageIDs: []uint64{2, 3}, }, } rec := changesToRec(changes) c2 := []change.Change{} c2, _ = change.Read(c2, rec.Reader) }