forked from TrueCloudLab/frostfs-sdk-go
[#79] subnet/id: Add function which resets ID
to zero subnet
Add `MakeZero` function which makes `ID` instance to refer to zero subnet. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
e7ac7f339e
commit
755c01264e
2 changed files with 19 additions and 0 deletions
|
@ -87,3 +87,10 @@ func (x *ID) SetNumber(num uint32) {
|
|||
func IsZero(id ID) bool {
|
||||
return id.Equals(nil)
|
||||
}
|
||||
|
||||
// MakeZero makes ID to refer to zero subnet. Arg must not be nil (it is already zero).
|
||||
//
|
||||
// Makes no sense to call on zero value (e.g. declared using var).
|
||||
func MakeZero(id *ID) {
|
||||
id.SetNumber(0)
|
||||
}
|
||||
|
|
|
@ -92,3 +92,15 @@ func TestSubnetIDEncoding(t *testing.T) {
|
|||
require.True(t, id2.Equals(id))
|
||||
})
|
||||
}
|
||||
|
||||
func TestMakeZero(t *testing.T) {
|
||||
var id subnetid.ID
|
||||
|
||||
id.SetNumber(13)
|
||||
|
||||
require.False(t, subnetid.IsZero(id))
|
||||
|
||||
subnetid.MakeZero(&id)
|
||||
|
||||
require.True(t, subnetid.IsZero(id))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue