This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
frostfs-rest-gw/internal/util/transformers_test.go

28 lines
781 B
Go
Raw Normal View History

package util
import (
"encoding/json"
"errors"
"fmt"
"testing"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-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 message = container not found","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))
}