[#302] pkg/session: Convert nil Token
to nil message
Document that `Token.ToV2` method return `nil` when called on `nil`. Document that `NewTokenFromV2` 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
2d7a658059
commit
707776976a
2 changed files with 21 additions and 0 deletions
|
@ -17,6 +17,8 @@ type Token session.SessionToken
|
|||
|
||||
// NewTokenFromV2 wraps session.SessionToken message structure
|
||||
// into Token.
|
||||
//
|
||||
// Nil session.SessionToken converts to nil.
|
||||
func NewTokenFromV2(tV2 *session.SessionToken) *Token {
|
||||
return (*Token)(tV2)
|
||||
}
|
||||
|
@ -27,6 +29,8 @@ func NewToken() *Token {
|
|||
}
|
||||
|
||||
// ToV2 converts Token to session.SessionToken message structure.
|
||||
//
|
||||
// Nil Token converts to nil.
|
||||
func (t *Token) ToV2() *session.SessionToken {
|
||||
return (*session.SessionToken)(t)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -162,3 +163,19 @@ func TestToken_Iat(t *testing.T) {
|
|||
|
||||
require.EqualValues(t, iat, tok.Iat())
|
||||
}
|
||||
|
||||
func TestNewTokenFromV2(t *testing.T) {
|
||||
t.Run("from nil", func(t *testing.T) {
|
||||
var x *sessionv2.SessionToken
|
||||
|
||||
require.Nil(t, session.NewTokenFromV2(x))
|
||||
})
|
||||
}
|
||||
|
||||
func TestToken_ToV2(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var x *session.Token
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue