frostfs-api-go/object/attributes_test.go
Airat Arifullin bc16a32c24
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 45s
Tests and linters / Lint (pull_request) Successful in 56s
Tests and linters / Tests (1.20) (pull_request) Successful in 2m3s
Tests and linters / Tests with -race (pull_request) Successful in 2m13s
[#40] types: Generate StableMarshaler/StableSize methods for protobufs
* Add plugin option for protogen in Makefile
* Fix the generator for the plugin in util/protogen
* Erase convertable types, move helpful methods to gRPC protobufs
* Erase helpers for convertations
* Generate StableMarshlal/StableSize for protobufs by the protoc plugin

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-10 12:08:48 +03:00

94 lines
1.8 KiB
Go

package object
import (
"strconv"
"testing"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
"github.com/stretchr/testify/require"
)
func TestSetNotification(t *testing.T) {
o := new(object.Object)
var ni = NotificationInfo{
epoch: 10,
topic: "test",
}
WriteNotificationInfo(o, ni)
var foundEpoch, foundTopic bool
for _, attr := range o.GetHeader().GetAttributes() {
switch key := attr.GetKey(); key {
case SysAttributeTickEpoch:
require.Equal(t, false, foundEpoch)
uEpoch, err := strconv.ParseUint(attr.GetValue(), 10, 64)
require.NoError(t, err)
require.Equal(t, ni.Epoch(), uEpoch)
foundEpoch = true
case SysAttributeTickTopic:
require.Equal(t, false, foundTopic)
require.Equal(t, ni.Topic(), attr.GetValue())
foundTopic = true
}
}
require.Equal(t, true, foundEpoch && foundTopic)
}
func TestGetNotification(t *testing.T) {
o := new(object.Object)
attr := []*object.Header_Attribute{
{
Key: SysAttributeTickEpoch, Value: "10",
},
{
Key: SysAttributeTickTopic, Value: "test",
},
}
h := new(object.Header)
h.SetAttributes(attr)
o.SetHeader(h)
t.Run("No error", func(t *testing.T) {
ni, err := GetNotificationInfo(o)
require.NoError(t, err)
require.Equal(t, uint64(10), ni.Epoch())
require.Equal(t, "test", ni.Topic())
})
}
func TestIntegration(t *testing.T) {
o := new(object.Object)
var (
ni1 = NotificationInfo{
epoch: 10,
topic: "",
}
ni2 = NotificationInfo{
epoch: 11,
topic: "test",
}
)
WriteNotificationInfo(o, ni1)
WriteNotificationInfo(o, ni2)
t.Run("double set", func(t *testing.T) {
ni, err := GetNotificationInfo(o)
require.NoError(t, err)
require.Equal(t, ni2.epoch, ni.Epoch())
require.Equal(t, ni2.topic, ni.Topic())
require.Equal(t, 2, len(o.GetHeader().GetAttributes()))
})
}