frostfs-rest-gw/internal/util/transformers_test.go
Denis Kirillov 9fba8d7f23 [#15] Use extended error response
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-07-12 11:36:32 +03:00

27 lines
740 B
Go

package util
import (
"encoding/json"
"errors"
"fmt"
"testing"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/stretchr/testify/require"
)
func TestErrors(t *testing.T) {
apiErr := fmt.Errorf("some context: %w", apistatus.ContainerNotFound{})
resp := NewErrorResponse(apiErr)
data, err := json.Marshal(resp)
require.NoError(t, err)
require.Equal(t, `{"code":3072,"message":"some context: status: code = 3072","type":"API"}`, string(data))
gwErr := fmt.Errorf("some context: %w", errors.New("sanity check error"))
resp = NewErrorResponse(gwErr)
data, err = json.Marshal(resp)
require.NoError(t, err)
require.Equal(t, `{"message":"some context: sanity check error","type":"GW"}`, string(data))
}