[#223] pkg/object: Work with SplitInfoError via pointer

Closes #221

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-03 16:23:59 +03:00 committed by Alex Vanin
parent b683dbe7e6
commit 1fe0307711
2 changed files with 8 additions and 7 deletions

View file

@ -6,14 +6,14 @@ type SplitInfoError struct {
const splitInfoErrorMsg = "object not found, split info has been provided"
func (s SplitInfoError) Error() string {
func (s *SplitInfoError) Error() string {
return splitInfoErrorMsg
}
func (s SplitInfoError) SplitInfo() *SplitInfo {
func (s *SplitInfoError) SplitInfo() *SplitInfo {
return s.si
}
func NewSplitInfoError(v *SplitInfo) SplitInfoError {
return SplitInfoError{si: v}
func NewSplitInfoError(v *SplitInfo) *SplitInfoError {
return &SplitInfoError{si: v}
}

View file

@ -12,12 +12,13 @@ func TestNewSplitInfoError(t *testing.T) {
var (
si = generateSplitInfo()
err error = object.NewSplitInfoError(si)
err error = object.NewSplitInfoError(si)
expectedErr *object.SplitInfoError
)
require.True(t, errors.As(err, new(object.SplitInfoError)))
require.True(t, errors.As(err, &expectedErr))
siErr, ok := err.(object.SplitInfoError)
siErr, ok := err.(*object.SplitInfoError)
require.True(t, ok)
require.Equal(t, si, siErr.SplitInfo())
}