2020-10-19 18:23:11 +00:00
|
|
|
package container_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContainerJSON(t *testing.T) {
|
|
|
|
exp := generateContainer("container")
|
|
|
|
|
|
|
|
t.Run("non empty", func(t *testing.T) {
|
2020-10-28 12:10:54 +00:00
|
|
|
data, err := container.ContainerToJSON(exp)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 18:23:11 +00:00
|
|
|
|
2020-10-28 12:10:54 +00:00
|
|
|
got, err := container.ContainerFromJSON(data)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 18:23:11 +00:00
|
|
|
|
|
|
|
require.Equal(t, exp, got)
|
|
|
|
})
|
2020-10-28 12:10:54 +00:00
|
|
|
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
_, err := container.ContainerToJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
_, err = container.ContainerFromJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
2020-10-19 18:23:11 +00:00
|
|
|
}
|
2020-11-13 12:14:39 +00:00
|
|
|
|
|
|
|
func TestAttributeJSON(t *testing.T) {
|
|
|
|
b := generateAttribute("key", "value")
|
|
|
|
|
|
|
|
data, err := b.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
b2 := new(container.Attribute)
|
|
|
|
require.NoError(t, b2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, b, b2)
|
|
|
|
}
|