swarm/shed: add TestIndex/put_in_batch_twice test

This commit is contained in:
Janos Guljas 2018-11-25 17:16:22 +01:00
parent e2a7c0cc73
commit fb2de8049e

View file

@ -143,6 +143,40 @@ func TestIndex(t *testing.T) {
}) })
}) })
t.Run("put in batch twice", func(t *testing.T) {
// ensure that the last item of items with the same db keys
// is actually saved
batch := new(leveldb.Batch)
address := []byte("put-in-batch-twice-hash")
// put the first item
index.PutInBatch(batch, IndexItem{
Address: address,
Data: []byte("DATA"),
StoreTimestamp: time.Now().UTC().UnixNano(),
})
want := IndexItem{
Address: address,
Data: []byte("New DATA"),
StoreTimestamp: time.Now().UTC().UnixNano(),
}
// then put the item that will produce the same key
// but different value in the database
index.PutInBatch(batch, want)
db.WriteBatch(batch)
if err != nil {
t.Fatal(err)
}
got, err := index.Get(IndexItem{
Address: address,
})
if err != nil {
t.Fatal(err)
}
checkIndexItem(t, got, want)
})
t.Run("delete", func(t *testing.T) { t.Run("delete", func(t *testing.T) {
want := IndexItem{ want := IndexItem{
Address: []byte("delete-hash"), Address: []byte("delete-hash"),