frostfs-sdk-go/object/transformer/channel_test.go
Dmitrii Stepanov 56debcfa56
All checks were successful
DCO / DCO (pull_request) Successful in 56s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m16s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m13s
Tests and linters / Lint (pull_request) Successful in 2m20s
[#190] sdk-go: Gofumpt fixes
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-11-22 19:21:20 +03:00

58 lines
1.5 KiB
Go

package transformer
import (
"context"
"crypto/rand"
"testing"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
"github.com/stretchr/testify/require"
)
func TestChannelTarget(t *testing.T) {
const maxSize = 100
ch := make(chan *objectSDK.Object, 10)
tt := new(testTarget)
ct := NewChannelTarget(ch)
chTarget, _ := newPayloadSizeLimiter(maxSize, 0, func() ObjectWriter { return ct })
testTarget, _ := newPayloadSizeLimiter(maxSize, 0, func() ObjectWriter { return tt })
ver := version.Current()
cnr := cidtest.ID()
hdr := objectSDK.New()
hdr.SetContainerID(cnr)
hdr.SetType(objectSDK.TypeRegular)
hdr.SetVersion(&ver)
payload := make([]byte, maxSize*2+maxSize/2)
_, _ = rand.Read(payload)
ctx := context.Background()
expectedIDs := writeObject(t, ctx, testTarget, hdr, payload)
actualIDs := writeObject(t, ctx, chTarget, hdr, payload)
_ = expectedIDs
_ = actualIDs
// require.Equal(t, expectedIDs, actualIDs)
for i := range tt.objects {
select {
case obj := <-ch:
// Because of the split ID objects can be different.
// However, payload and attributes must be the same.
require.Equal(t, tt.objects[i].Payload(), obj.Payload())
require.Equal(t, tt.objects[i].Attributes(), obj.Attributes())
default:
require.FailNow(t, "received less parts than expected")
}
}
select {
case <-ch:
require.FailNow(t, "received more parts than expected")
default:
}
}