frostfs-s3-gw/internal/frostfs/crdt/gset_test.go
Denis Kirillov 0590f84d68 [#135] crdt: Add GSet
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
2023-06-16 09:39:43 +03:00

38 lines
1.2 KiB
Go

package crdt
import (
"testing"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"github.com/stretchr/testify/require"
)
func TestObjectVersionsSort(t *testing.T) {
t.Run("sort by epoch", func(t *testing.T) {
versions := NewObjectVersions("test")
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3})
versions.AppendVersion(&ObjectVersion{CreationEpoch: 1})
versions.AppendVersion(&ObjectVersion{CreationEpoch: 2})
last := versions.GetLast()
require.Equal(t, uint64(3), last.CreationEpoch)
})
t.Run("sort by oids", func(t *testing.T) {
versions := NewObjectVersions("test")
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, OjbID: getTestOID(2)})
versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, OjbID: getTestOID(1)})
versions.AppendVersion(&ObjectVersion{CreationEpoch: 1, OjbID: getTestOID(3)})
versions.AppendVersion(&ObjectVersion{CreationEpoch: 2, OjbID: getTestOID(4)})
last := versions.GetLast()
require.Equal(t, uint64(3), last.CreationEpoch)
require.Equal(t, getTestOID(2).String(), last.VersionID())
})
}
func getTestOID(val byte) oid.ID {
var res oid.ID
res.SetSHA256([32]byte{val})
return res
}