2021-11-08 10:04:45 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2023-09-08 14:15:08 +00:00
|
|
|
"crypto/rand"
|
2021-11-08 10:04:45 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"testing"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/tombstone"
|
2023-03-07 11:20:03 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-11-08 10:04:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-03-11 09:00:54 +00:00
|
|
|
func generateIDList(sz int) []oid.ID {
|
|
|
|
res := make([]oid.ID, sz)
|
2021-11-08 10:04:45 +00:00
|
|
|
cs := [sha256.Size]byte{}
|
|
|
|
|
2024-09-03 10:20:30 +00:00
|
|
|
for i := range sz {
|
2022-04-11 16:25:14 +00:00
|
|
|
var oID oid.ID
|
|
|
|
|
|
|
|
res[i] = oID
|
2021-11-08 10:04:45 +00:00
|
|
|
rand.Read(cs[:])
|
|
|
|
res[i].SetSHA256(cs)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTombstone(t *testing.T) {
|
|
|
|
ts := NewTombstone()
|
|
|
|
|
|
|
|
exp := uint64(13)
|
|
|
|
ts.SetExpirationEpoch(exp)
|
|
|
|
require.Equal(t, exp, ts.ExpirationEpoch())
|
|
|
|
|
|
|
|
splitID := NewSplitID()
|
|
|
|
ts.SetSplitID(splitID)
|
|
|
|
require.Equal(t, splitID, ts.SplitID())
|
|
|
|
|
|
|
|
members := generateIDList(3)
|
|
|
|
ts.SetMembers(members)
|
|
|
|
require.Equal(t, members, ts.Members())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTombstoneEncoding(t *testing.T) {
|
|
|
|
ts := NewTombstone()
|
|
|
|
ts.SetExpirationEpoch(13)
|
|
|
|
ts.SetSplitID(NewSplitID())
|
|
|
|
ts.SetMembers(generateIDList(5))
|
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := ts.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ts2 := NewTombstone()
|
|
|
|
require.NoError(t, ts2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, ts, ts2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := ts.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ts2 := NewTombstone()
|
|
|
|
require.NoError(t, ts2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, ts, ts2)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewTombstoneFromV2(t *testing.T) {
|
|
|
|
t.Run("from nil", func(t *testing.T) {
|
|
|
|
var x *tombstone.Tombstone
|
|
|
|
|
|
|
|
require.Nil(t, NewTombstoneFromV2(x))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewTombstone(t *testing.T) {
|
|
|
|
t.Run("default values", func(t *testing.T) {
|
|
|
|
ts := NewTombstone()
|
|
|
|
|
|
|
|
// check initial values
|
|
|
|
require.Nil(t, ts.SplitID())
|
|
|
|
require.Nil(t, ts.Members())
|
|
|
|
require.Zero(t, ts.ExpirationEpoch())
|
|
|
|
|
|
|
|
// convert to v2 message
|
|
|
|
tsV2 := ts.ToV2()
|
|
|
|
|
|
|
|
require.Nil(t, tsV2.GetSplitID())
|
|
|
|
require.Nil(t, tsV2.GetMembers())
|
|
|
|
require.Zero(t, tsV2.GetExpirationEpoch())
|
|
|
|
})
|
|
|
|
}
|