frostfs-api-go/pkg/object/attribute_test.go
Leonard Lyubich 0caff85fb7 [#168] object: Implement binary/JSON encoders/decoders on Attribute
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-11-13 18:07:26 +03:00

49 lines
863 B
Go

package object
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAttribute(t *testing.T) {
key, val := "some key", "some value"
a := NewAttribute()
a.SetKey(key)
a.SetValue(val)
require.Equal(t, key, a.GetKey())
require.Equal(t, val, a.GetValue())
aV2 := a.ToV2()
require.Equal(t, key, aV2.GetKey())
require.Equal(t, val, aV2.GetValue())
}
func TestAttributeEncoding(t *testing.T) {
a := NewAttribute()
a.SetKey("key")
a.SetValue("value")
t.Run("binary", func(t *testing.T) {
data, err := a.Marshal()
require.NoError(t, err)
a2 := NewAttribute()
require.NoError(t, a2.Unmarshal(data))
require.Equal(t, a, a2)
})
t.Run("json", func(t *testing.T) {
data, err := a.MarshalJSON()
require.NoError(t, err)
a2 := NewAttribute()
require.NoError(t, a2.UnmarshalJSON(data))
require.Equal(t, a, a2)
})
}