forked from TrueCloudLab/frostfs-api-go
[#302] pkg/container: Convert nil UsedSpaceAnnouncement
to nil message
Document that `UsedSpaceAnnouncement.ToV2` method returns `nil` when is called on `nil`. Document that `NewAnnouncementFromV2` method returns `nil` when is called on `nil`. Add corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
31ca5c14d3
commit
c54dee82be
2 changed files with 21 additions and 0 deletions
|
@ -16,6 +16,8 @@ func NewAnnouncement() *UsedSpaceAnnouncement {
|
||||||
|
|
||||||
// NewAnnouncementFromV2 wraps protocol dependent version of
|
// NewAnnouncementFromV2 wraps protocol dependent version of
|
||||||
// UsedSpaceAnnouncement message.
|
// UsedSpaceAnnouncement message.
|
||||||
|
//
|
||||||
|
// Nil container.UsedSpaceAnnouncement converts to nil.
|
||||||
func NewAnnouncementFromV2(v *container.UsedSpaceAnnouncement) *UsedSpaceAnnouncement {
|
func NewAnnouncementFromV2(v *container.UsedSpaceAnnouncement) *UsedSpaceAnnouncement {
|
||||||
return (*UsedSpaceAnnouncement)(v)
|
return (*UsedSpaceAnnouncement)(v)
|
||||||
}
|
}
|
||||||
|
@ -53,6 +55,8 @@ func (a *UsedSpaceAnnouncement) SetUsedSpace(value uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToV2 returns protocol dependent version of UsedSpaceAnnouncement message.
|
// ToV2 returns protocol dependent version of UsedSpaceAnnouncement message.
|
||||||
|
//
|
||||||
|
// Nil UsedSpaceAnnouncement converts to nil.
|
||||||
func (a *UsedSpaceAnnouncement) ToV2() *container.UsedSpaceAnnouncement {
|
func (a *UsedSpaceAnnouncement) ToV2() *container.UsedSpaceAnnouncement {
|
||||||
return (*container.UsedSpaceAnnouncement)(a)
|
return (*container.UsedSpaceAnnouncement)(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||||
containertest "github.com/nspcc-dev/neofs-api-go/pkg/container/test"
|
containertest "github.com/nspcc-dev/neofs-api-go/pkg/container/test"
|
||||||
|
containerv2 "github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -64,3 +65,19 @@ func TestUsedSpaceEncoding(t *testing.T) {
|
||||||
require.Equal(t, a, a2)
|
require.Equal(t, a, a2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsedSpaceAnnouncement_ToV2(t *testing.T) {
|
||||||
|
t.Run("nil", func(t *testing.T) {
|
||||||
|
var x *container.UsedSpaceAnnouncement
|
||||||
|
|
||||||
|
require.Nil(t, x.ToV2())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewAnnouncementFromV2(t *testing.T) {
|
||||||
|
t.Run("from nil", func(t *testing.T) {
|
||||||
|
var x *containerv2.UsedSpaceAnnouncement
|
||||||
|
|
||||||
|
require.Nil(t, container.NewAnnouncementFromV2(x))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue