forked from TrueCloudLab/frostfs-api-go
[#302] pkg/xheader: Convert nil XHeader
to nil message
Document that `XHeader.ToV2` method return `nil` when called on `nil`. Document that `NewXHeaderFromV2` function return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
dc99d4edce
commit
41307a5e00
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,8 @@ import (
|
||||||
type XHeader session.XHeader
|
type XHeader session.XHeader
|
||||||
|
|
||||||
// NewXHeaderFromV2 wraps v2 XHeader message to XHeader.
|
// NewXHeaderFromV2 wraps v2 XHeader message to XHeader.
|
||||||
|
//
|
||||||
|
// Nil session.XHeader converts to nil.
|
||||||
func NewXHeaderFromV2(v *session.XHeader) *XHeader {
|
func NewXHeaderFromV2(v *session.XHeader) *XHeader {
|
||||||
return (*XHeader)(v)
|
return (*XHeader)(v)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +20,8 @@ func NewXHeader() *XHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToV2 converts XHeader to v2 XHeader message.
|
// ToV2 converts XHeader to v2 XHeader message.
|
||||||
|
//
|
||||||
|
// Nil XHeader converts to nil.
|
||||||
func (x *XHeader) ToV2() *session.XHeader {
|
func (x *XHeader) ToV2() *session.XHeader {
|
||||||
return (*session.XHeader)(x)
|
return (*session.XHeader)(x)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pkg
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,3 +24,19 @@ func TestXHeader(t *testing.T) {
|
||||||
require.Equal(t, key, xV2.GetKey())
|
require.Equal(t, key, xV2.GetKey())
|
||||||
require.Equal(t, val, xV2.GetValue())
|
require.Equal(t, val, xV2.GetValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewXHeaderFromV2(t *testing.T) {
|
||||||
|
t.Run("from nil", func(t *testing.T) {
|
||||||
|
var x *session.XHeader
|
||||||
|
|
||||||
|
require.Nil(t, NewXHeaderFromV2(x))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestXHeader_ToV2(t *testing.T) {
|
||||||
|
t.Run("nil", func(t *testing.T) {
|
||||||
|
var x *XHeader
|
||||||
|
|
||||||
|
require.Nil(t, x.ToV2())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue