forked from TrueCloudLab/frostfs-api-go
b506970636
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>
50 lines
906 B
Go
50 lines
906 B
Go
package pkg
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSignatureEncoding(t *testing.T) {
|
|
s := NewSignature()
|
|
s.SetKey([]byte("key"))
|
|
s.SetSign([]byte("sign"))
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
data, err := s.Marshal()
|
|
require.NoError(t, err)
|
|
|
|
s2 := NewSignature()
|
|
require.NoError(t, s2.Unmarshal(data))
|
|
|
|
require.Equal(t, s, s2)
|
|
})
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
data, err := s.MarshalJSON()
|
|
require.NoError(t, err)
|
|
|
|
s2 := NewSignature()
|
|
require.NoError(t, s2.UnmarshalJSON(data))
|
|
|
|
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())
|
|
})
|
|
}
|