frostfs-sdk-go/container/size_test.go
Airat Arifullin 6281a25556
All checks were successful
/ DCO (pull_request) Successful in 1m17s
/ Lint (pull_request) Successful in 2m7s
/ Tests (1.19) (pull_request) Successful in 5m56s
/ Tests (1.20) (pull_request) Successful in 6m37s
[#100] types: Make sdk types as protobuf wrappers
Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-12 19:08:37 +03:00

95 lines
2.2 KiB
Go

package container_test
import (
"crypto/sha256"
"testing"
containergrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
refsgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
func TestSizeEstimation_Epoch(t *testing.T) {
val := container.NewSizeEstimation()
require.Zero(t, val.Epoch())
const epoch = 123
val.SetEpoch(epoch)
require.EqualValues(t, epoch, val.Epoch())
var msg containergrpc.AnnounceUsedSpaceRequest_Body_Announcement
val.WriteToV2(&msg)
require.EqualValues(t, epoch, msg.GetEpoch())
}
func TestSizeEstimation_Container(t *testing.T) {
val := container.NewSizeEstimation()
require.Zero(t, val.Container())
cnr := cidtest.ID()
val.SetContainer(cnr)
require.True(t, val.Container().Equals(cnr))
var msg containergrpc.AnnounceUsedSpaceRequest_Body_Announcement
val.WriteToV2(&msg)
var msgCnr refsgrpc.ContainerID
cnr.WriteToV2(&msgCnr)
require.True(t, proto.Equal(&msgCnr, msg.GetContainerId()))
}
func TestSizeEstimation_Value(t *testing.T) {
val := container.NewSizeEstimation()
require.Zero(t, val.Value())
const value = 876
val.SetValue(value)
require.EqualValues(t, value, val.Value())
var msg containergrpc.AnnounceUsedSpaceRequest_Body_Announcement
val.WriteToV2(&msg)
require.EqualValues(t, value, msg.GetUsedSpace())
}
func TestSizeEstimation_ReadFromV2(t *testing.T) {
const epoch = 654
const value = 903
var cnrMsg refsgrpc.ContainerID
msg := new(containergrpc.AnnounceUsedSpaceRequest_Body_Announcement)
val := container.NewSizeEstimation()
require.Error(t, val.ReadFromV2(msg))
msg.SetContainerId(&cnrMsg)
require.Error(t, val.ReadFromV2(msg))
cnrMsg.SetValue(make([]byte, sha256.Size))
var cnr cid.ID
require.NoError(t, cnr.ReadFromV2(&cnrMsg))
msg.SetEpoch(epoch)
msg.SetUsedSpace(value)
require.NoError(t, val.ReadFromV2(msg))
require.EqualValues(t, epoch, val.Epoch())
require.EqualValues(t, value, val.Value())
require.EqualValues(t, cnr, val.Container())
}