[#302] pkg/signature: Document default values set in NewSignature

Document field values of instance constructed via
`NewSignature`. 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 21:16:46 +03:00 committed by Alex Vanin
parent b506970636
commit bb0cd8e4c0
2 changed files with 21 additions and 1 deletions

View file

@ -17,6 +17,10 @@ func NewSignatureFromV2(sV2 *refs.Signature) *Signature {
// NewSignature creates and initializes blank Signature.
//
// Works similar as NewSignatureFromV2(new(Signature)).
//
// Defaults:
// - key: nil;
// - signature: nil.
func NewSignature() *Signature {
return NewSignatureFromV2(new(refs.Signature))
}

View file

@ -1,9 +1,9 @@
package pkg
import (
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/stretchr/testify/require"
)
@ -48,3 +48,19 @@ func TestSignature_ToV2(t *testing.T) {
require.Nil(t, x.ToV2())
})
}
func TestNewSignature(t *testing.T) {
t.Run("default values", func(t *testing.T) {
sg := NewSignature()
// check initial values
require.Nil(t, sg.Key())
require.Nil(t, sg.Sign())
// convert to v2 message
sgV2 := sg.ToV2()
require.Nil(t, sgV2.GetKey())
require.Nil(t, sgV2.GetSign())
})
}