diff --git a/pkg/container/announcement.go b/pkg/container/announcement.go index 412272bf..bc8b6e4c 100644 --- a/pkg/container/announcement.go +++ b/pkg/container/announcement.go @@ -19,6 +19,16 @@ func NewAnnouncementFromV2(v *container.UsedSpaceAnnouncement) *UsedSpaceAnnounc return (*UsedSpaceAnnouncement)(v) } +// Epoch of the announcement. +func (a *UsedSpaceAnnouncement) Epoch() uint64 { + return (*container.UsedSpaceAnnouncement)(a).GetEpoch() +} + +// SetEpoch sets announcement epoch value. +func (a *UsedSpaceAnnouncement) SetEpoch(epoch uint64) { + (*container.UsedSpaceAnnouncement)(a).SetEpoch(epoch) +} + // ContainerID of the announcement. func (a *UsedSpaceAnnouncement) ContainerID() *ID { return NewIDFromV2( diff --git a/pkg/container/announcement_test.go b/pkg/container/announcement_test.go index 3fca102e..ad3b16f4 100644 --- a/pkg/container/announcement_test.go +++ b/pkg/container/announcement_test.go @@ -9,21 +9,23 @@ import ( ) func TestAnnouncement(t *testing.T) { - const usedSpace uint64 = 100 + const epoch, usedSpace uint64 = 10, 100 cidValue := [32]byte{1, 2, 3} cid := container.NewID() cid.SetSHA256(cidValue) a := container.NewAnnouncement() + a.SetEpoch(epoch) a.SetContainerID(cid) a.SetUsedSpace(usedSpace) + require.Equal(t, epoch, a.Epoch()) require.Equal(t, usedSpace, a.UsedSpace()) require.Equal(t, cid, a.ContainerID()) t.Run("test v2", func(t *testing.T) { - const newUsedSpace uint64 = 200 + const newEpoch, newUsedSpace uint64 = 20, 200 newCidValue := [32]byte{4, 5, 6} newCID := new(refs.ContainerID) @@ -31,13 +33,16 @@ func TestAnnouncement(t *testing.T) { v2 := a.ToV2() require.Equal(t, usedSpace, v2.GetUsedSpace()) + require.Equal(t, epoch, v2.GetEpoch()) require.Equal(t, cidValue[:], v2.GetContainerID().GetValue()) + v2.SetEpoch(newEpoch) v2.SetUsedSpace(newUsedSpace) v2.SetContainerID(newCID) newA := container.NewAnnouncementFromV2(v2) + require.Equal(t, newEpoch, newA.Epoch()) require.Equal(t, newUsedSpace, newA.UsedSpace()) require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID()) })