forked from TrueCloudLab/frostfs-api-go
[#302] pkg/checksum: Document default values set in NewChecksum
Document field values of instance constructed via `NewChecksum`. Assert the values in corresponding unit test. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
35b6629e1c
commit
bf0d106e54
2 changed files with 22 additions and 2 deletions
|
@ -34,9 +34,13 @@ func NewChecksumFromV2(cV2 *refs.Checksum) *Checksum {
|
|||
return (*Checksum)(cV2)
|
||||
}
|
||||
|
||||
// NewVersion creates and initializes blank Version.
|
||||
// NewChecksum creates and initializes blank Checksum.
|
||||
//
|
||||
// Works similar as NewVersionFromV2(new(Version)).
|
||||
// Works similar as NewChecksumFromV2(new(Checksum)).
|
||||
//
|
||||
// Defaults:
|
||||
// - sum: nil;
|
||||
// - type: ChecksumUnknown.
|
||||
func NewChecksum() *Checksum {
|
||||
return NewChecksumFromV2(new(refs.Checksum))
|
||||
}
|
||||
|
|
|
@ -115,3 +115,19 @@ func TestChecksum_ToV2(t *testing.T) {
|
|||
require.Nil(t, x.ToV2())
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewChecksum(t *testing.T) {
|
||||
t.Run("default values", func(t *testing.T) {
|
||||
chs := NewChecksum()
|
||||
|
||||
// check initial values
|
||||
require.Equal(t, ChecksumUnknown, chs.Type())
|
||||
require.Nil(t, chs.Sum())
|
||||
|
||||
// convert to v2 message
|
||||
chsV2 := chs.ToV2()
|
||||
|
||||
require.Equal(t, refs.UnknownChecksum, chsV2.GetType())
|
||||
require.Nil(t, chsV2.GetSum())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue