Dmitrii Stepanov
76ff26039c
All checks were successful
DCO action / DCO (pull_request) Successful in 2m13s
Build / Build Components (1.20) (pull_request) Successful in 5m48s
Build / Build Components (1.21) (pull_request) Successful in 5m47s
Vulncheck / Vulncheck (pull_request) Successful in 5m47s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m33s
Tests and linters / Staticcheck (pull_request) Successful in 7m37s
Tests and linters / Lint (pull_request) Successful in 8m8s
Tests and linters / Tests (1.20) (pull_request) Successful in 10m38s
Tests and linters / Tests with -race (pull_request) Successful in 11m22s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
"github.com/stretchr/testify/require"
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func TestBlobovniczaIterate(t *testing.T) {
|
|
filename := filepath.Join(t.TempDir(), "blob")
|
|
b := New(WithPath(filename))
|
|
require.NoError(t, b.Open())
|
|
require.NoError(t, b.Init())
|
|
|
|
data := [][]byte{{0, 1, 2, 3}, {5, 6, 7, 8}}
|
|
addr := oidtest.Address()
|
|
_, err := b.Put(context.Background(), PutPrm{addr: addr, objData: data[0]})
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, b.boltDB.Update(func(tx *bbolt.Tx) error {
|
|
buck := tx.Bucket(bucketKeyFromBounds(firstBucketBound))
|
|
return buck.Put([]byte("invalid address"), data[1])
|
|
}))
|
|
|
|
seen := make([][]byte, 0, 2)
|
|
inc := func(e IterationElement) error {
|
|
seen = append(seen, bytes.Clone(e.data))
|
|
return nil
|
|
}
|
|
|
|
_, err = b.Iterate(context.Background(), IteratePrm{handler: inc})
|
|
require.NoError(t, err)
|
|
require.ElementsMatch(t, seen, data)
|
|
|
|
seen = seen[:0]
|
|
_, err = b.Iterate(context.Background(), IteratePrm{handler: inc, decodeAddresses: true})
|
|
require.Error(t, err)
|
|
|
|
seen = seen[:0]
|
|
_, err = b.Iterate(context.Background(), IteratePrm{handler: inc, decodeAddresses: true, ignoreErrors: true})
|
|
require.NoError(t, err)
|
|
require.ElementsMatch(t, seen, data[:1])
|
|
|
|
seen = seen[:0]
|
|
expectedErr := errors.New("stop iteration")
|
|
_, err = b.Iterate(context.Background(), IteratePrm{
|
|
decodeAddresses: true,
|
|
handler: func(IterationElement) error { return expectedErr },
|
|
ignoreErrors: true,
|
|
})
|
|
require.ErrorIs(t, err, expectedErr)
|
|
}
|