2023-06-13 09:33:03 +00:00
|
|
|
package crdt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-09-26 11:26:33 +00:00
|
|
|
oid "git.frostfs.info/mbiryukova/frostfs-sdk-go/object/id"
|
2023-06-13 09:33:03 +00:00
|
|
|
"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
|
|
|
|
}
|