forked from TrueCloudLab/frostfs-api-go
[#168] refs: Implement binary/JSON encoders/decoders on ContainerID
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
7289ff6c64
commit
c0f3ac51d4
6 changed files with 103 additions and 4 deletions
|
@ -90,3 +90,28 @@ func TestID_String(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestContainerIDEncoding(t *testing.T) {
|
||||
id := NewID()
|
||||
id.SetSHA256(randSHA256Checksum(t))
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := id.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
id2 := NewID()
|
||||
require.NoError(t, id2.Unmarshal(data))
|
||||
|
||||
require.Equal(t, id, id2)
|
||||
})
|
||||
|
||||
t.Run("json", func(t *testing.T) {
|
||||
data, err := id.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
a2 := NewID()
|
||||
require.NoError(t, a2.UnmarshalJSON(data))
|
||||
|
||||
require.Equal(t, id, a2)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue