50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
|
package object_test
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
"testing"
|
||
|
|
||
|
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
||
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||
|
objecttest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/test"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestExpirationEpoch(t *testing.T) {
|
||
|
obj := objecttest.Object()
|
||
|
|
||
|
var expEpoch uint64 = 42
|
||
|
expAttr := objectSDK.NewAttribute()
|
||
|
expAttr.SetKey(objectV2.SysAttributeExpEpoch)
|
||
|
expAttr.SetValue(strconv.FormatUint(expEpoch, 10))
|
||
|
|
||
|
t.Run("no attributes set", func(t *testing.T) {
|
||
|
obj.SetAttributes()
|
||
|
_, found := objectCore.ExpirationEpoch(obj)
|
||
|
require.False(t, found)
|
||
|
})
|
||
|
t.Run("no expiration epoch attribute", func(t *testing.T) {
|
||
|
obj.SetAttributes(*objecttest.Attribute(), *objectSDK.NewAttribute())
|
||
|
_, found := objectCore.ExpirationEpoch(obj)
|
||
|
require.False(t, found)
|
||
|
})
|
||
|
t.Run("valid expiration epoch attribute", func(t *testing.T) {
|
||
|
obj.SetAttributes(*objecttest.Attribute(), *expAttr, *objectSDK.NewAttribute())
|
||
|
epoch, found := objectCore.ExpirationEpoch(obj)
|
||
|
require.True(t, found)
|
||
|
require.Equal(t, expEpoch, epoch)
|
||
|
})
|
||
|
t.Run("invalid expiration epoch value", func(t *testing.T) {
|
||
|
expAttr.SetValue("-42")
|
||
|
obj.SetAttributes(*objecttest.Attribute(), *expAttr, *objectSDK.NewAttribute())
|
||
|
_, found := objectCore.ExpirationEpoch(obj)
|
||
|
require.False(t, found)
|
||
|
|
||
|
expAttr.SetValue("qwerty")
|
||
|
obj.SetAttributes(*objecttest.Attribute(), *expAttr, *objectSDK.NewAttribute())
|
||
|
_, found = objectCore.ExpirationEpoch(obj)
|
||
|
require.False(t, found)
|
||
|
})
|
||
|
}
|