forked from TrueCloudLab/frostfs-api-go
[#302] pkg/token: Convert nil BearerToken
to nil message
Document that `BearerToken.ToV2` method return `nil` when called on `nil`. Write corresponding unit tests. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
3bc25f54d8
commit
00a0ea42a8
2 changed files with 17 additions and 1 deletions
|
@ -23,7 +23,14 @@ type BearerToken struct {
|
|||
token acl.BearerToken
|
||||
}
|
||||
|
||||
func (b BearerToken) ToV2() *acl.BearerToken {
|
||||
// ToV2 converts BearerToken to v2 BearerToken message.
|
||||
//
|
||||
// Nil BearerToken converts to nil.
|
||||
func (b *BearerToken) ToV2() *acl.BearerToken {
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &b.token
|
||||
}
|
||||
|
||||
|
@ -100,6 +107,7 @@ func NewBearerToken() *BearerToken {
|
|||
return b
|
||||
}
|
||||
|
||||
// ToV2 converts BearerToken to v2 BearerToken message.
|
||||
func NewBearerTokenFromV2(v2 *acl.BearerToken) *BearerToken {
|
||||
if v2 == nil {
|
||||
v2 = new(acl.BearerToken)
|
||||
|
|
|
@ -55,3 +55,11 @@ func TestFilterEncoding(t *testing.T) {
|
|||
require.Equal(t, f, d2)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBearerToken_ToV2(t *testing.T) {
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
var x *token.BearerToken
|
||||
|
||||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue