forked from TrueCloudLab/frostfs-api-go
[#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:
parent
d4327ec018
commit
cce7ecbc00
2 changed files with 28 additions and 6 deletions
|
@ -12,6 +12,9 @@ import (
|
|||
type PeerID reputation.PeerID
|
||||
|
||||
// NewPeerID creates and returns blank PeerID.
|
||||
//
|
||||
// Defaults:
|
||||
// - publicKey: nil.
|
||||
func NewPeerID() *PeerID {
|
||||
return PeerIDFromV2(new(reputation.PeerID))
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ func TestPeerID_ToV2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPeerID_String(t *testing.T) {
|
||||
t.Run("Parse/String", func(t *testing.T) {
|
||||
id := reputationtest.GeneratePeerID()
|
||||
|
||||
strID := id.String()
|
||||
|
@ -34,6 +35,13 @@ func TestPeerID_String(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
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) {
|
||||
|
@ -67,3 +75,14 @@ func TestPeerIDFromV2(t *testing.T) {
|
|||
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())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue