From 707776976abd69c0bc0b0d5b113fd93477a33958 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 20:27:05 +0300 Subject: [PATCH] [#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 --- pkg/session/session.go | 4 ++++ pkg/session/session_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/session/session.go b/pkg/session/session.go index 99b71a1..3f58bff 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -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) } diff --git a/pkg/session/session_test.go b/pkg/session/session_test.go index 88ec809..1ce07b3 100644 --- a/pkg/session/session_test.go +++ b/pkg/session/session_test.go @@ -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()) + }) +}