*: use require.ErrorIs
where possible
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
3c39e6df11
commit
a4769d8624
8 changed files with 16 additions and 20 deletions
|
@ -2,7 +2,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -122,7 +121,7 @@ func Test_getKey(t *testing.T) {
|
|||
func checkKeyError(t *testing.T, desc string, err error) {
|
||||
viper.Set(walletPath, desc)
|
||||
_, actualErr := getKey()
|
||||
require.True(t, errors.Is(actualErr, err), "got: %v", actualErr)
|
||||
require.ErrorIs(t, actualErr, err)
|
||||
}
|
||||
|
||||
func checkKey(t *testing.T, desc string, expected *keys.PrivateKey) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
@ -70,14 +69,14 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
t.Run("nil identifier", func(t *testing.T) {
|
||||
obj := object.New()
|
||||
|
||||
require.True(t, errors.Is(v.Validate(obj, false), errNilID))
|
||||
require.ErrorIs(t, v.Validate(obj, false), errNilID)
|
||||
})
|
||||
|
||||
t.Run("nil container identifier", func(t *testing.T) {
|
||||
obj := object.New()
|
||||
obj.SetID(testObjectID(t))
|
||||
|
||||
require.True(t, errors.Is(v.Validate(obj, true), errNilCID))
|
||||
require.ErrorIs(t, v.Validate(obj, true), errNilCID)
|
||||
})
|
||||
|
||||
t.Run("unsigned object", func(t *testing.T) {
|
||||
|
@ -204,7 +203,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
t.Run("expired object", func(t *testing.T) {
|
||||
val := strconv.FormatUint(curEpoch-1, 10)
|
||||
err := v.Validate(fn(val), false)
|
||||
require.True(t, errors.Is(err, errExpired))
|
||||
require.ErrorIs(t, err, errExpired)
|
||||
})
|
||||
|
||||
t.Run("alive object", func(t *testing.T) {
|
||||
|
|
|
@ -53,5 +53,5 @@ func TestBlobovniczaIterate(t *testing.T) {
|
|||
handler: func(IterationElement) error { return expectedErr },
|
||||
ignoreErrors: true,
|
||||
})
|
||||
require.True(t, errors.Is(err, expectedErr), "got: %v")
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ func TestFSTree(t *testing.T) {
|
|||
return nil
|
||||
}))
|
||||
|
||||
require.True(t, errors.Is(err, errStop))
|
||||
require.ErrorIs(t, err, errStop)
|
||||
require.Equal(t, count-1, n)
|
||||
})
|
||||
|
||||
|
@ -152,7 +152,7 @@ func TestFSTree(t *testing.T) {
|
|||
}
|
||||
return nil
|
||||
}).WithIgnoreErrors(true))
|
||||
require.True(t, errors.Is(err, expectedErr), "got: %v")
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
require.Equal(t, count/2, n)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -204,6 +204,6 @@ func TestIterate_IgnoreErrors(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
_, err := bs.Iterate(prm)
|
||||
require.True(t, errors.Is(err, expectedErr), "got: %v")
|
||||
require.ErrorIs(t, err, expectedErr)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -182,7 +181,7 @@ func TestBlobstorFailback(t *testing.T) {
|
|||
require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload())
|
||||
|
||||
_, err = e.GetRange(&RngPrm{addr: addr, off: errSmallSize + 10, ln: 1})
|
||||
require.True(t, errors.Is(err, object.ErrRangeOutOfBounds), "got: %v", err)
|
||||
require.ErrorIs(t, err, object.ErrRangeOutOfBounds)
|
||||
}
|
||||
|
||||
checkShardState(t, e, id[0], 4, shard.ModeDegraded)
|
||||
|
|
|
@ -2,7 +2,6 @@ package shard_test
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
@ -59,7 +58,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
|
||||
t.Run("must be read-only", func(t *testing.T) {
|
||||
_, err := sh.Dump(prm)
|
||||
require.True(t, errors.Is(err, shard.ErrMustBeReadOnly), "got: %v", err)
|
||||
require.ErrorIs(t, err, shard.ErrMustBeReadOnly)
|
||||
})
|
||||
|
||||
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
||||
|
@ -119,7 +118,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
|
||||
t.Run("invalid path", func(t *testing.T) {
|
||||
_, err := sh.Restore(new(shard.RestorePrm))
|
||||
require.True(t, errors.Is(err, os.ErrNotExist), "got: %v", err)
|
||||
require.ErrorIs(t, err, os.ErrNotExist)
|
||||
})
|
||||
|
||||
t.Run("invalid file", func(t *testing.T) {
|
||||
|
@ -128,7 +127,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
require.NoError(t, os.WriteFile(out, []byte{0, 0, 0, 0}, os.ModePerm))
|
||||
|
||||
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
|
||||
require.True(t, errors.Is(err, shard.ErrInvalidMagic), "got: %v", err)
|
||||
require.ErrorIs(t, err, shard.ErrInvalidMagic)
|
||||
})
|
||||
|
||||
fileData, err := os.ReadFile(out)
|
||||
|
@ -140,7 +139,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
|
||||
|
||||
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
|
||||
require.True(t, errors.Is(err, io.ErrUnexpectedEOF), "got: %v", err)
|
||||
require.ErrorIs(t, err, io.ErrUnexpectedEOF)
|
||||
})
|
||||
t.Run("incomplete object data", func(t *testing.T) {
|
||||
out := out + ".wrongsize"
|
||||
|
@ -148,7 +147,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
|
||||
|
||||
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
|
||||
require.True(t, errors.Is(err, io.EOF), "got: %v", err)
|
||||
require.ErrorIs(t, err, io.EOF)
|
||||
})
|
||||
t.Run("invalid object", func(t *testing.T) {
|
||||
out := out + ".wrongobj"
|
||||
|
@ -175,7 +174,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
|||
require.NoError(t, sh.SetMode(shard.ModeReadOnly))
|
||||
|
||||
_, err := sh.Restore(prm)
|
||||
require.True(t, errors.Is(err, shard.ErrReadOnlyMode), "got: %v", err)
|
||||
require.ErrorIs(t, err, shard.ErrReadOnlyMode)
|
||||
})
|
||||
|
||||
require.NoError(t, sh.SetMode(shard.ModeReadWrite))
|
||||
|
|
|
@ -183,7 +183,7 @@ func TestGetLocalOnly(t *testing.T) {
|
|||
p := newPrm(cid, w)
|
||||
|
||||
err := svc.Search(ctx, p)
|
||||
require.True(t, errors.Is(err, testErr))
|
||||
require.ErrorIs(t, err, testErr)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue