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, ObjID: getTestOID(2)}) versions.AppendVersion(&ObjectVersion{CreationEpoch: 3, ObjID: getTestOID(1)}) versions.AppendVersion(&ObjectVersion{CreationEpoch: 1, ObjID: getTestOID(3)}) versions.AppendVersion(&ObjectVersion{CreationEpoch: 2, ObjID: 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 } func TestObjectVersionsSort1(t *testing.T) { t.Run("sort by headers", func(t *testing.T) { versions := NewObjectVersions("test") versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(2)}) versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(3)}) versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(4)}) versions.AppendVersion(&ObjectVersion{Headers: versions.GetCRDTHeaders(), ObjID: getTestOID(1)}) last := versions.GetLast() require.Equal(t, uint64(0), last.CreationEpoch) require.Equal(t, getTestOID(1).String(), last.VersionID()) }) }