forked from TrueCloudLab/frostfs-api-go
[#302] pkg/signature: Convert nil Signature
to nil message
Document that `Signature.ToV2` method return `nil` when called on `nil`. Document that `NewSignatureFromV2` 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
bf0d106e54
commit
b506970636
2 changed files with 22 additions and 0 deletions
|
@ -8,6 +8,8 @@ import (
|
||||||
type Signature refs.Signature
|
type Signature refs.Signature
|
||||||
|
|
||||||
// NewSignatureFromV2 wraps v2 Signature message to Signature.
|
// NewSignatureFromV2 wraps v2 Signature message to Signature.
|
||||||
|
//
|
||||||
|
// Nil refs.Signature converts to nil.
|
||||||
func NewSignatureFromV2(sV2 *refs.Signature) *Signature {
|
func NewSignatureFromV2(sV2 *refs.Signature) *Signature {
|
||||||
return (*Signature)(sV2)
|
return (*Signature)(sV2)
|
||||||
}
|
}
|
||||||
|
@ -39,6 +41,9 @@ func (s *Signature) SetSign(v []byte) {
|
||||||
(*refs.Signature)(s).SetSign(v)
|
(*refs.Signature)(s).SetSign(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToV2 converts Signature to v2 Signature message.
|
||||||
|
//
|
||||||
|
// Nil Signature converts to nil.
|
||||||
func (s *Signature) ToV2() *refs.Signature {
|
func (s *Signature) ToV2() *refs.Signature {
|
||||||
return (*refs.Signature)(s)
|
return (*refs.Signature)(s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -31,3 +32,19 @@ func TestSignatureEncoding(t *testing.T) {
|
||||||
require.Equal(t, s, s2)
|
require.Equal(t, s, s2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewSignatureFromV2(t *testing.T) {
|
||||||
|
t.Run("from nil", func(t *testing.T) {
|
||||||
|
var x *refs.Signature
|
||||||
|
|
||||||
|
require.Nil(t, NewSignatureFromV2(x))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSignature_ToV2(t *testing.T) {
|
||||||
|
t.Run("nil", func(t *testing.T) {
|
||||||
|
var x *Signature
|
||||||
|
|
||||||
|
require.Nil(t, x.ToV2())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue