package pfile import ( crand "crypto/rand" "math/rand" "git.crumpington.com/public/jldb/mdb/change" ) func randomChangeList() (changes []change.Change) { count := 1 + rand.Intn(8) for i := 0; i < count; i++ { change := change.Change{ CollectionID: 1 + uint64(rand.Int63n(10)), ItemID: 1 + uint64(rand.Int63n(10)), } if rand.Float32() < 0.95 { change.Data = randBytes(1 + rand.Intn(pageDataSize*4)) change.Store = true } changes = append(changes, change) } return changes } type changeListBuilder []change.Change func (b *changeListBuilder) Clear() *changeListBuilder { *b = (*b)[:0] return b } func (b *changeListBuilder) Store(cID, iID, dataSize uint64) *changeListBuilder { data := make([]byte, dataSize) crand.Read(data) *b = append(*b, change.Change{ CollectionID: cID, ItemID: iID, Store: true, Data: data, }) return b } func (b *changeListBuilder) Delete(cID, iID uint64) *changeListBuilder { *b = append(*b, change.Change{ CollectionID: cID, ItemID: iID, Store: false, }) return b } func (b *changeListBuilder) Build() []change.Change { return *b }