From bb0cd8e4c05181816d08749b9a19137102e3e207 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 8 Jun 2021 21:16:46 +0300 Subject: [PATCH] [#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 --- pkg/signature.go | 4 ++++ pkg/signature_test.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/signature.go b/pkg/signature.go index 1847dcd..0976946 100644 --- a/pkg/signature.go +++ b/pkg/signature.go @@ -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)) } diff --git a/pkg/signature_test.go b/pkg/signature_test.go index 5b8c32f..45a5f14 100644 --- a/pkg/signature_test.go +++ b/pkg/signature_test.go @@ -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()) + }) +}