From eba6831125f2873d9b15198522e0029aa1c2445d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 23 Feb 2023 17:13:13 +0300 Subject: [PATCH] [#19] transformer/test: Add helper functions Signed-off-by: Evgenii Stratonikov --- object/transformer/transformer_test.go | 35 +++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/object/transformer/transformer_test.go b/object/transformer/transformer_test.go index 545945d..f1f6722 100644 --- a/object/transformer/transformer_test.go +++ b/object/transformer/transformer_test.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "testing" + cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id" cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" "github.com/TrueCloudLab/frostfs-sdk-go/version" @@ -18,23 +19,13 @@ func TestTransformer(t *testing.T) { target, _ := newPayloadSizeLimiter(maxSize, tt) - ver := version.Current() cnr := cidtest.ID() - hdr := objectSDK.New() - hdr.SetContainerID(cnr) - hdr.SetType(objectSDK.TypeRegular) - hdr.SetVersion(&ver) - require.NoError(t, target.WriteHeader(hdr)) + hdr := newObject(cnr) expectedPayload := make([]byte, maxSize*2+maxSize/2) _, _ = rand.Read(expectedPayload) - _, err := target.Write(expectedPayload) - require.NoError(t, err) - - ids, err := target.Close() - require.NoError(t, err) - + ids := writeObject(t, target, hdr, expectedPayload) require.Equal(t, 4, len(tt.objects)) // 3 parts + linking object var actualPayload []byte @@ -62,13 +53,29 @@ func TestTransformer(t *testing.T) { require.Equal(t, expectedPayload, actualPayload) } -func BenchmarkTransformer(b *testing.B) { +func newObject(cnr cid.ID) *objectSDK.Object { ver := version.Current() - cnr := cidtest.ID() hdr := objectSDK.New() hdr.SetContainerID(cnr) hdr.SetType(objectSDK.TypeRegular) hdr.SetVersion(&ver) + return hdr +} + +func writeObject(t *testing.T, target ObjectTarget, header *objectSDK.Object, payload []byte) *AccessIdentifiers { + require.NoError(t, target.WriteHeader(header)) + + _, err := target.Write(payload) + require.NoError(t, err) + + ids, err := target.Close() + require.NoError(t, err) + + return ids +} + +func BenchmarkTransformer(b *testing.B) { + hdr := newObject(cidtest.ID()) b.Run("small", func(b *testing.B) { benchmarkTransformer(b, hdr, 8*1024)