*: use require.ErrorIs where possible

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-04-29 13:22:29 +03:00 committed by LeL
parent 3c39e6df11
commit a4769d8624
8 changed files with 16 additions and 20 deletions

View file

@ -2,7 +2,6 @@ package cmd
import ( import (
"bytes" "bytes"
"errors"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -122,7 +121,7 @@ func Test_getKey(t *testing.T) {
func checkKeyError(t *testing.T, desc string, err error) { func checkKeyError(t *testing.T, desc string, err error) {
viper.Set(walletPath, desc) viper.Set(walletPath, desc)
_, actualErr := getKey() _, 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) { func checkKey(t *testing.T, desc string, expected *keys.PrivateKey) {

View file

@ -4,7 +4,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"errors"
"strconv" "strconv"
"testing" "testing"
@ -70,14 +69,14 @@ func TestFormatValidator_Validate(t *testing.T) {
t.Run("nil identifier", func(t *testing.T) { t.Run("nil identifier", func(t *testing.T) {
obj := object.New() 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) { t.Run("nil container identifier", func(t *testing.T) {
obj := object.New() obj := object.New()
obj.SetID(testObjectID(t)) 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) { 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) { t.Run("expired object", func(t *testing.T) {
val := strconv.FormatUint(curEpoch-1, 10) val := strconv.FormatUint(curEpoch-1, 10)
err := v.Validate(fn(val), false) 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) { t.Run("alive object", func(t *testing.T) {

View file

@ -53,5 +53,5 @@ func TestBlobovniczaIterate(t *testing.T) {
handler: func(IterationElement) error { return expectedErr }, handler: func(IterationElement) error { return expectedErr },
ignoreErrors: true, ignoreErrors: true,
}) })
require.True(t, errors.Is(err, expectedErr), "got: %v") require.ErrorIs(t, err, expectedErr)
} }

View file

@ -115,7 +115,7 @@ func TestFSTree(t *testing.T) {
return nil return nil
})) }))
require.True(t, errors.Is(err, errStop)) require.ErrorIs(t, err, errStop)
require.Equal(t, count-1, n) require.Equal(t, count-1, n)
}) })
@ -152,7 +152,7 @@ func TestFSTree(t *testing.T) {
} }
return nil return nil
}).WithIgnoreErrors(true)) }).WithIgnoreErrors(true))
require.True(t, errors.Is(err, expectedErr), "got: %v") require.ErrorIs(t, err, expectedErr)
require.Equal(t, count/2, n) require.Equal(t, count/2, n)
}) })
}) })

View file

@ -204,6 +204,6 @@ func TestIterate_IgnoreErrors(t *testing.T) {
return nil return nil
}) })
_, err := bs.Iterate(prm) _, err := bs.Iterate(prm)
require.True(t, errors.Is(err, expectedErr), "got: %v") require.ErrorIs(t, err, expectedErr)
}) })
} }

View file

@ -1,7 +1,6 @@
package engine package engine
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -182,7 +181,7 @@ func TestBlobstorFailback(t *testing.T) {
require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload()) require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload())
_, err = e.GetRange(&RngPrm{addr: addr, off: errSmallSize + 10, ln: 1}) _, 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) checkShardState(t, e, id[0], 4, shard.ModeDegraded)

View file

@ -2,7 +2,6 @@ package shard_test
import ( import (
"bytes" "bytes"
"errors"
"io" "io"
"math/rand" "math/rand"
"os" "os"
@ -59,7 +58,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
t.Run("must be read-only", func(t *testing.T) { t.Run("must be read-only", func(t *testing.T) {
_, err := sh.Dump(prm) _, 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)) 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) { t.Run("invalid path", func(t *testing.T) {
_, err := sh.Restore(new(shard.RestorePrm)) _, 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) { 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)) require.NoError(t, os.WriteFile(out, []byte{0, 0, 0, 0}, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out)) _, 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) 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)) require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out)) _, 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) { t.Run("incomplete object data", func(t *testing.T) {
out := out + ".wrongsize" 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)) require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out)) _, 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) { t.Run("invalid object", func(t *testing.T) {
out := out + ".wrongobj" out := out + ".wrongobj"
@ -175,7 +174,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
require.NoError(t, sh.SetMode(shard.ModeReadOnly)) require.NoError(t, sh.SetMode(shard.ModeReadOnly))
_, err := sh.Restore(prm) _, 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)) require.NoError(t, sh.SetMode(shard.ModeReadWrite))

View file

@ -183,7 +183,7 @@ func TestGetLocalOnly(t *testing.T) {
p := newPrm(cid, w) p := newPrm(cid, w)
err := svc.Search(ctx, p) err := svc.Search(ctx, p)
require.True(t, errors.Is(err, testErr)) require.ErrorIs(t, err, testErr)
}) })
} }