[#302] pkg/reputation: Convert nil Trust,

`PeerToPeerTrust` and `GlobalTrust` to nil message

Document that `Trust.ToV2`, `PeerToPeerTrust.ToV2`
and `GlobalTrust.ToV2` methods return `nil`when
called on `nil`. Document that `TrustFromV2`,
`PeerToPeerTrustFromV2`and `GlobalTrustFromV2`
functions return `nil` when called on `nil`. Write
corresponding unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 20:07:09 +03:00 committed by Alex Vanin
parent cce7ecbc00
commit 8ab3abab4b
2 changed files with 61 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
reputationtest "github.com/nspcc-dev/neofs-api-go/pkg/reputation/test"
reputationV2 "github.com/nspcc-dev/neofs-api-go/v2/reputation"
reputationtestV2 "github.com/nspcc-dev/neofs-api-go/v2/reputation/test"
"github.com/stretchr/testify/require"
)
@ -150,3 +151,51 @@ func TestGlobalTrust(t *testing.T) {
})
})
}
func TestTrustFromV2(t *testing.T) {
t.Run("from nil", func(t *testing.T) {
var x *reputationV2.Trust
require.Nil(t, reputation.TrustFromV2(x))
})
}
func TestPeerToPeerTrustFromV2(t *testing.T) {
t.Run("from nil", func(t *testing.T) {
var x *reputationV2.PeerToPeerTrust
require.Nil(t, reputation.PeerToPeerTrustFromV2(x))
})
}
func TestGlobalTrustFromV2(t *testing.T) {
t.Run("from nil", func(t *testing.T) {
var x *reputationV2.GlobalTrust
require.Nil(t, reputation.GlobalTrustFromV2(x))
})
}
func TestTrust_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *reputation.Trust
require.Nil(t, x.ToV2())
})
}
func TestPeerToPeerTrust_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *reputation.PeerToPeerTrust
require.Nil(t, x.ToV2())
})
}
func TestGlobalTrust_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *reputation.GlobalTrust
require.Nil(t, x.ToV2())
})
}