[#302] pkg/reputation: Document default values set in NewPeerID

Document field values of instance constructed via `NewPeerID`.
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 19:57:28 +03:00 committed by Alex Vanin
parent d4327ec018
commit cce7ecbc00
2 changed files with 28 additions and 6 deletions

View file

@ -12,6 +12,9 @@ import (
type PeerID reputation.PeerID type PeerID reputation.PeerID
// NewPeerID creates and returns blank PeerID. // NewPeerID creates and returns blank PeerID.
//
// Defaults:
// - publicKey: nil.
func NewPeerID() *PeerID { func NewPeerID() *PeerID {
return PeerIDFromV2(new(reputation.PeerID)) return PeerIDFromV2(new(reputation.PeerID))
} }

View file

@ -24,16 +24,24 @@ func TestPeerID_ToV2(t *testing.T) {
} }
func TestPeerID_String(t *testing.T) { func TestPeerID_String(t *testing.T) {
id := reputationtest.GeneratePeerID() t.Run("Parse/String", func(t *testing.T) {
id := reputationtest.GeneratePeerID()
strID := id.String() strID := id.String()
id2 := reputation.NewPeerID() id2 := reputation.NewPeerID()
err := id2.Parse(strID) err := id2.Parse(strID)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, id, id2) require.Equal(t, id, id2)
})
t.Run("nil", func(t *testing.T) {
id := reputation.NewPeerID()
require.Empty(t, id.String())
})
} }
func TestPeerIDEncoding(t *testing.T) { func TestPeerIDEncoding(t *testing.T) {
@ -67,3 +75,14 @@ func TestPeerIDFromV2(t *testing.T) {
require.Nil(t, reputation.PeerIDFromV2(x)) require.Nil(t, reputation.PeerIDFromV2(x))
}) })
} }
func TestNewPeerID(t *testing.T) {
t.Run("default values", func(t *testing.T) {
id := reputation.NewPeerID()
// convert to v2 message
idV2 := id.ToV2()
require.Nil(t, idV2.GetPublicKey())
})
}