forked from TrueCloudLab/frostfs-api-go
[#218] pkg/object: Define custom error for SplitInfo
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
1fdeca84e1
commit
e11b1728be
3 changed files with 54 additions and 2 deletions
|
@ -445,8 +445,9 @@ func (c *Client) getObjectV2(ctx context.Context, p *GetObjectParams, opts ...Ca
|
||||||
} else {
|
} else {
|
||||||
payload = append(payload, v.GetChunk()...)
|
payload = append(payload, v.GetChunk()...)
|
||||||
}
|
}
|
||||||
case *v2object.SplitInfo: // what else can we do here?
|
case *v2object.SplitInfo:
|
||||||
return nil, errors.New("object not found, split info has been provided")
|
si := object.NewSplitInfoFromV2(v)
|
||||||
|
return nil, object.NewSplitInfoError(si)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unexpected Get object part type %T", v))
|
panic(fmt.Sprintf("unexpected Get object part type %T", v))
|
||||||
}
|
}
|
||||||
|
|
19
pkg/object/error.go
Normal file
19
pkg/object/error.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package object
|
||||||
|
|
||||||
|
type SplitInfoError struct {
|
||||||
|
si *SplitInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
const splitInfoErrorMsg = "object not found, split info has been provided"
|
||||||
|
|
||||||
|
func (s SplitInfoError) Error() string {
|
||||||
|
return splitInfoErrorMsg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SplitInfoError) SplitInfo() *SplitInfo {
|
||||||
|
return s.si
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSplitInfoError(v *SplitInfo) SplitInfoError {
|
||||||
|
return SplitInfoError{si: v}
|
||||||
|
}
|
32
pkg/object/error_test.go
Normal file
32
pkg/object/error_test.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package object_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewSplitInfoError(t *testing.T) {
|
||||||
|
var (
|
||||||
|
si = generateSplitInfo()
|
||||||
|
|
||||||
|
err error = object.NewSplitInfoError(si)
|
||||||
|
)
|
||||||
|
|
||||||
|
require.True(t, errors.As(err, new(object.SplitInfoError)))
|
||||||
|
|
||||||
|
siErr, ok := err.(object.SplitInfoError)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, si, siErr.SplitInfo())
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateSplitInfo() *object.SplitInfo {
|
||||||
|
si := object.NewSplitInfo()
|
||||||
|
si.SetSplitID(object.NewSplitID())
|
||||||
|
si.SetLastPart(generateID())
|
||||||
|
si.SetLink(generateID())
|
||||||
|
|
||||||
|
return si
|
||||||
|
}
|
Loading…
Reference in a new issue