From 1e1139f305f4b3af179442bdbb1be1294383c259 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 27 Jun 2022 10:48:27 +0300 Subject: [PATCH] [#278] pool: Avoid using `strings.Contains` for error assertion `client` package now provides functions for error checking. Signed-off-by: Leonard Lyubich --- pool/pool.go | 7 ++----- pool/pool_test.go | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index fdfaa84c..6e65f9c5 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -10,7 +10,6 @@ import ( "math" "math/rand" "sort" - "strings" "sync" "time" @@ -1225,8 +1224,7 @@ func (p *Pool) checkSessionTokenErr(err error, address string) bool { return false } - if strings.Contains(err.Error(), "session token does not exist") || - strings.Contains(err.Error(), "session token has been expired") { + if sdkClient.IsErrSessionNotFound(err) || sdkClient.IsErrSessionExpired(err) { p.cache.DeleteByPrefix(address) return true } @@ -1768,8 +1766,7 @@ func waitForContainerRemoved(ctx context.Context, cli client, cnrID *cid.ID, wai return waitFor(ctx, waitParams, func(ctx context.Context) bool { _, err := cli.containerGet(ctx, prm) - return sdkClient.IsErrContainerNotFound(err) || - err != nil && strings.Contains(err.Error(), "not found") + return sdkClient.IsErrContainerNotFound(err) }) } diff --git a/pool/pool_test.go b/pool/pool_test.go index 805bca85..9d1ff03d 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -13,6 +13,7 @@ import ( "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/container" neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa" "github.com/nspcc-dev/neofs-sdk-go/netmap" @@ -387,7 +388,7 @@ func TestSessionCache(t *testing.T) { }).MaxTimes(3) mockClient.EXPECT().networkInfo(gomock.Any(), gomock.Any()).Return(&netmap.NetworkInfo{}, nil).AnyTimes() - mockClient.EXPECT().objectGet(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("session token does not exist")) + mockClient.EXPECT().objectGet(gomock.Any(), gomock.Any()).Return(nil, apistatus.SessionTokenNotFound{}) mockClient.EXPECT().objectPut(gomock.Any(), gomock.Any()).Return(nil, nil) return mockClient, nil