frostfs-api-go-pogpp/v2/acl/json_test.go
Alex Vanin 352e99d9b9 [#185] v2: Return errors in JSON converters
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2020-10-29 10:15:28 +03:00

66 lines
1.3 KiB
Go

package acl_test
import (
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/stretchr/testify/require"
)
func TestRecordJSON(t *testing.T) {
exp := generateRecord(false)
t.Run("non empty", func(t *testing.T) {
data, err := acl.RecordToJSON(exp)
require.NoError(t, err)
got, err := acl.RecordFromJSON(data)
require.NoError(t, err)
require.Equal(t, exp, got)
})
t.Run("empty", func(t *testing.T) {
_, err := acl.RecordToJSON(nil)
require.Error(t, err)
_, err = acl.RecordFromJSON(nil)
require.Error(t, err)
})
}
func TestEACLTableJSON(t *testing.T) {
exp := generateEACL()
t.Run("non empty", func(t *testing.T) {
data, err := acl.TableToJSON(exp)
require.NoError(t, err)
got, err := acl.TableFromJSON(data)
require.NoError(t, err)
require.Equal(t, exp, got)
})
t.Run("empty", func(t *testing.T) {
_, err := acl.TableToJSON(nil)
require.Error(t, err)
_, err = acl.TableFromJSON(nil)
require.Error(t, err)
})
}
func TestBearerTokenJSON(t *testing.T) {
exp := generateBearerToken("token")
t.Run("non empty", func(t *testing.T) {
data, err := acl.BearerTokenToJSON(exp)
require.NoError(t, err)
got, err := acl.BearerTokenFromJSON(data)
require.NoError(t, err)
require.Equal(t, exp, got)
})
}