[#302] pkg/session: Document default values set in NewToken

Document field values of instance constructed via `NewToken`.
Assert the values in corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 20:35:03 +03:00 committed by Alex Vanin
parent 707776976a
commit fb77bd3511
2 changed files with 30 additions and 0 deletions

View file

@ -24,6 +24,15 @@ func NewTokenFromV2(tV2 *session.SessionToken) *Token {
}
// NewToken creates and returns blank Token.
//
// Defaults:
// - body: nil;
// - id: nil;
// - ownerId: nil;
// - sessionKey: nil;
// - exp: 0;
// - iat: 0;
// - nbf: 0;
func NewToken() *Token {
return NewTokenFromV2(new(session.SessionToken))
}

View file

@ -179,3 +179,24 @@ func TestToken_ToV2(t *testing.T) {
require.Nil(t, x.ToV2())
})
}
func TestNewToken(t *testing.T) {
t.Run("default values", func(t *testing.T) {
token := session.NewToken()
// check initial values
require.Nil(t, token.Signature())
require.Nil(t, token.OwnerID())
require.Nil(t, token.SessionKey())
require.Nil(t, token.ID())
require.Zero(t, token.Exp())
require.Zero(t, token.Iat())
require.Zero(t, token.Nbf())
// convert to v2 message
tokenV2 := token.ToV2()
require.Nil(t, tokenV2.GetSignature())
require.Nil(t, tokenV2.GetBody())
})
}