2022-07-07 12:59:38 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 15:02:40 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-07-07 12:59:38 +00:00
|
|
|
"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)
|
2023-06-28 14:03:07 +00:00
|
|
|
require.Equal(t, `{"code":3072,"message":"some context: status: code = 3072 message = container not found","type":"API"}`, string(data))
|
2022-07-07 12:59:38 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|