forked from TrueCloudLab/frostfs-api-go
[#302] pkg/netmap: Convert nil `Filter` to nil message
Make `Filter.ToV2` method return `nil` when called on `nil`. Make `NewFilterFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>support/v2.15
parent
0206bd9a5d
commit
9a7e120485
|
@ -153,11 +153,15 @@ func NewFilter() *Filter {
|
|||
}
|
||||
|
||||
// NewFilterFromV2 converts v2 Filter to Filter.
|
||||
//
|
||||
// Nil netmap.Filter converts to nil.
|
||||
func NewFilterFromV2(f *netmap.Filter) *Filter {
|
||||
return (*Filter)(f)
|
||||
}
|
||||
|
||||
// ToV2 converts Filter to v2 Filter.
|
||||
//
|
||||
// Nil Filter converts to nil.
|
||||
func (f *Filter) ToV2() *netmap.Filter {
|
||||
return (*netmap.Filter)(f)
|
||||
}
|
||||
|
|
|
@ -213,6 +213,18 @@ func testFilter() *Filter {
|
|||
}
|
||||
|
||||
func TestFilterFromV2(t *testing.T) {
|
||||
t.Run("nil from V2", func(t *testing.T) {
|
||||
var x *netmap.Filter
|
||||
|
||||
require.Nil(t, NewFilterFromV2(x))
|
||||
})
|
||||
|
||||
t.Run("nil to V2", func(t *testing.T) {
|
||||
var x *Filter
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
|
||||
fV2 := new(netmap.Filter)
|
||||
fV2.SetOp(netmap.GE)
|
||||
fV2.SetName("name")
|
||||
|
|
Loading…
Reference in New Issue