mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
contrib: remaining errors.Is conversions
Signed-off-by: redwrasse <mail@redwrasse.io>
This commit is contained in:
parent
d59fa331c5
commit
f6278ef2a9
@ -365,10 +365,10 @@ func (c *httpClusterClient) Do(ctx context.Context, act httpAction) (*http.Respo
|
||||
resp, body, err = hc.Do(ctx, action)
|
||||
if err != nil {
|
||||
cerr.Errors = append(cerr.Errors, err)
|
||||
if errors.Is(err, ctx.Err()) {
|
||||
if err == ctx.Err() {
|
||||
return nil, nil, ctx.Err()
|
||||
}
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
if err == context.Canceled || err == context.DeadlineExceeded {
|
||||
return nil, nil, err
|
||||
}
|
||||
} else if resp.StatusCode/100 == 5 {
|
||||
|
@ -169,7 +169,7 @@ func TestSimpleHTTPClientDoNilRequest(t *testing.T) {
|
||||
tr.errchan <- errors.New("fixture")
|
||||
|
||||
_, _, err := c.Do(context.Background(), &nilAction{})
|
||||
if !errors.Is(err, ErrNoRequest) {
|
||||
if err != ErrNoRequest {
|
||||
t.Fatalf("expected non-nil error, got nil")
|
||||
}
|
||||
}
|
||||
@ -256,7 +256,7 @@ func TestSimpleHTTPClientDoCancelContextResponseBodyClosedWithBlockingBody(t *te
|
||||
}()
|
||||
|
||||
_, _, err := c.Do(ctx, &fakeAction{})
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
if err != context.Canceled {
|
||||
t.Fatalf("expected %+v, got %+v", context.Canceled, err)
|
||||
}
|
||||
|
||||
@ -478,7 +478,7 @@ func TestHTTPClusterClientDoDeadlineExceedContext(t *testing.T) {
|
||||
|
||||
select {
|
||||
case err := <-errc:
|
||||
if !errors.Is(err, context.DeadlineExceeded) {
|
||||
if err != context.DeadlineExceeded {
|
||||
t.Errorf("err = %+v, want %+v", err, context.DeadlineExceeded)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
@ -528,7 +528,7 @@ func TestHTTPClusterClientDoCanceledContext(t *testing.T) {
|
||||
|
||||
select {
|
||||
case err := <-errc:
|
||||
if !errors.Is(err, errFakeCancelContext) {
|
||||
if err != errFakeCancelContext {
|
||||
t.Errorf("err = %+v, want %+v", err, errFakeCancelContext)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
@ -881,7 +881,7 @@ func TestHTTPClusterClientAutoSyncCancelContext(t *testing.T) {
|
||||
cancel()
|
||||
|
||||
err = hc.AutoSync(ctx, time.Hour)
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
if err != context.Canceled {
|
||||
t.Fatalf("incorrect error value: want=%v got=%v", context.Canceled, err)
|
||||
}
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ func (hw *httpWatcher) Next(ctx context.Context) (*Response, error) {
|
||||
|
||||
resp, err := unmarshalHTTPResponse(httpresp.StatusCode, httpresp.Header, body)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrEmptyBody) {
|
||||
if err == ErrEmptyBody {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
|
@ -17,7 +17,6 @@
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -65,7 +64,7 @@ func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error
|
||||
flock := wrlck
|
||||
if err = syscall.FcntlFlock(f.Fd(), unix.F_OFD_SETLK, &flock); err != nil {
|
||||
f.Close()
|
||||
if errors.Is(err, syscall.EWOULDBLOCK) {
|
||||
if err == syscall.EWOULDBLOCK {
|
||||
err = ErrLocked
|
||||
}
|
||||
return nil, err
|
||||
|
@ -17,7 +17,6 @@
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
@ -36,7 +35,7 @@ func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) {
|
||||
}
|
||||
if err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock); err != nil {
|
||||
f.Close()
|
||||
if errors.Is(err, syscall.EAGAIN) {
|
||||
if err == syscall.EAGAIN {
|
||||
err = ErrLocked
|
||||
}
|
||||
return nil, err
|
||||
|
@ -15,7 +15,6 @@
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@ -41,7 +40,7 @@ func TestLockAndUnlock(t *testing.T) {
|
||||
}
|
||||
|
||||
// try lock a locked file
|
||||
if _, err = TryLockFile(f.Name(), os.O_WRONLY, PrivateFileMode); !errors.Is(err, ErrLocked) {
|
||||
if _, err = TryLockFile(f.Name(), os.O_WRONLY, PrivateFileMode); err != ErrLocked {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,9 @@ func lockFile(fd windows.Handle, flags uint32) error {
|
||||
err := windows.LockFileEx(fd, flags|windows.LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &windows.Overlapped{})
|
||||
if err == nil {
|
||||
return nil
|
||||
} else if errors.Is(err, errLocked) {
|
||||
} else if err.Error() == errLocked.Error() {
|
||||
return ErrLocked
|
||||
} else if !errors.Is(err, windows.ERROR_LOCK_VIOLATION) {
|
||||
} else if err != windows.ERROR_LOCK_VIOLATION {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -17,7 +17,6 @@
|
||||
package fileutil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
@ -45,7 +44,7 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
|
||||
}
|
||||
|
||||
// wrong argument to fallocate syscall
|
||||
if errors.Is(err, unix.EINVAL) {
|
||||
if err == unix.EINVAL {
|
||||
// filesystem "st_blocks" are allocated in the units of
|
||||
// "Allocation Block Size" (run "diskutil info /" command)
|
||||
var stat syscall.Stat_t
|
||||
|
@ -294,7 +294,7 @@ func (c *Client) getToken(ctx context.Context) error {
|
||||
|
||||
resp, err := c.Auth.Authenticate(ctx, c.Username, c.Password)
|
||||
if err != nil {
|
||||
if errors.Is(err, rpctypes.ErrAuthNotEnabled) {
|
||||
if err == rpctypes.ErrAuthNotEnabled {
|
||||
c.authTokenBundle.UpdateAuthToken("")
|
||||
return nil
|
||||
}
|
||||
@ -627,7 +627,7 @@ func canceledByCaller(stopCtx context.Context, err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
|
||||
return err == context.Canceled || err == context.DeadlineExceeded
|
||||
}
|
||||
|
||||
// IsConnCanceled returns true, if error is from a closed gRPC connection.
|
||||
@ -645,7 +645,7 @@ func IsConnCanceled(err error) bool {
|
||||
}
|
||||
|
||||
// >= gRPC v1.10.x
|
||||
if errors.Is(err, context.Canceled) {
|
||||
if err == context.Canceled {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -449,7 +449,7 @@ func TestClientRejectOldCluster(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.checkVersion(); !errors.Is(err, tt.expectedError) {
|
||||
if err := c.checkVersion(); err != tt.expectedError {
|
||||
t.Errorf("heckVersion err:%v", err)
|
||||
}
|
||||
})
|
||||
|
@ -16,7 +16,6 @@ package recipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -52,7 +51,7 @@ func newUniqueKV(kv v3.KV, prefix string, val string) (*RemoteKV, error) {
|
||||
if err == nil {
|
||||
return &RemoteKV{kv, newKey, rev, val}, nil
|
||||
}
|
||||
if !errors.Is(err, ErrKeyExists) {
|
||||
if err != ErrKeyExists {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -156,7 +155,7 @@ func newUniqueEphemeralKV(s *concurrency.Session, prefix, val string) (ek *Ephem
|
||||
for {
|
||||
newKey := fmt.Sprintf("%s/%v", prefix, time.Now().UnixNano())
|
||||
ek, err = newEphemeralKV(s, newKey, val)
|
||||
if err == nil || !errors.Is(err, ErrKeyExists) {
|
||||
if err == nil || err != ErrKeyExists {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ func (w *watcher) Close() (err error) {
|
||||
}
|
||||
}
|
||||
// Consider context.Canceled as a successful close
|
||||
if errors.Is(err, context.Canceled) {
|
||||
if err == context.Canceled {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
|
@ -15,7 +15,6 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -83,7 +82,7 @@ func authEnableCommandFunc(cmd *cobra.Command, args []string) {
|
||||
if _, err = cli.AuthEnable(ctx); err == nil {
|
||||
break
|
||||
}
|
||||
if errors.Is(err, rpctypes.ErrRootRoleNotExist) {
|
||||
if err == rpctypes.ErrRootRoleNotExist {
|
||||
if _, err = cli.RoleAdd(ctx, "root"); err != nil {
|
||||
break
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@ -535,7 +534,7 @@ func Test_parseWatchArgs(t *testing.T) {
|
||||
}
|
||||
for i, ts := range tt {
|
||||
watchArgs, execArgs, err := parseWatchArgs(ts.osArgs, ts.commandArgs, ts.envKey, ts.envRange, ts.interactive)
|
||||
if !errors.Is(err, ts.err) {
|
||||
if err != ts.err {
|
||||
t.Fatalf("#%d: error expected %v, got %v", i, ts.err, err)
|
||||
}
|
||||
if !reflect.DeepEqual(watchArgs, ts.watchArgs) {
|
||||
|
@ -16,7 +16,6 @@ package ioutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
@ -29,7 +28,7 @@ func (rc *readerNilCloser) Close() error { return nil }
|
||||
func TestExactReadCloserExpectEOF(t *testing.T) {
|
||||
buf := bytes.NewBuffer(make([]byte, 10))
|
||||
rc := NewExactReadCloser(&readerNilCloser{buf}, 1)
|
||||
if _, err := rc.Read(make([]byte, 10)); !errors.Is(err, ErrExpectEOF) {
|
||||
if _, err := rc.Read(make([]byte, 10)); err != ErrExpectEOF {
|
||||
t.Fatalf("expected %v, got %v", ErrExpectEOF, err)
|
||||
}
|
||||
}
|
||||
@ -41,7 +40,7 @@ func TestExactReadCloserShort(t *testing.T) {
|
||||
if _, err := rc.Read(make([]byte, 10)); err != nil {
|
||||
t.Fatalf("Read expected nil err, got %v", err)
|
||||
}
|
||||
if err := rc.Close(); !errors.Is(err, ErrShortRead) {
|
||||
if err := rc.Close(); err != ErrShortRead {
|
||||
t.Fatalf("Close expected %v, got %v", ErrShortRead, err)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -140,7 +139,7 @@ func testJWTInfo(t *testing.T, opts map[string]string) {
|
||||
}
|
||||
|
||||
_, aerr := verify.assign(ctx, "abc", 123)
|
||||
if !errors.Is(aerr, ErrVerifyOnly) {
|
||||
if aerr != ErrVerifyOnly {
|
||||
t.Fatalf("unexpected error when attempting to sign with public key: %v", aerr)
|
||||
}
|
||||
|
||||
|
@ -165,13 +165,13 @@ func TestUserAdd(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserAlreadyExist) {
|
||||
if err != ErrUserAlreadyExist {
|
||||
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||
}
|
||||
|
||||
ua = &pb.AuthUserAddRequest{Name: "", Options: &authpb.UserAddOptions{NoPassword: false}}
|
||||
_, err = as.UserAdd(ua) // add a user with empty name
|
||||
if !errors.Is(err, ErrUserEmpty) {
|
||||
if err != ErrUserEmpty {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ func TestCheckPassword(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
if !errors.Is(err, ErrAuthFailed) {
|
||||
if err != ErrAuthFailed {
|
||||
t.Fatalf("expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ func TestCheckPassword(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
if !errors.Is(err, ErrAuthFailed) {
|
||||
if err != ErrAuthFailed {
|
||||
t.Fatalf("expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
}
|
||||
@ -264,7 +264,7 @@ func TestUserDelete(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ func TestUserDeleteAndPermCache(t *testing.T) {
|
||||
|
||||
// delete a non-existing user
|
||||
_, err = as.UserDelete(ud)
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ func TestRoleAdd(t *testing.T) {
|
||||
|
||||
// add a role with empty name
|
||||
_, err = as.RoleAdd(&pb.AuthRoleAddRequest{Name: ""})
|
||||
if !errors.Is(err, ErrRoleEmpty) {
|
||||
if err != ErrRoleEmpty {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -379,7 +379,7 @@ func TestUserGrant(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Errorf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
}
|
||||
@ -455,7 +455,7 @@ func TestIsOpPermitted(t *testing.T) {
|
||||
as.rangePermCacheMu.Lock()
|
||||
delete(as.rangePermCache, "foo")
|
||||
as.rangePermCacheMu.Unlock()
|
||||
if err := as.isOpPermitted("foo", as.Revision(), perm.Key, perm.RangeEnd, perm.PermType); !errors.Is(err, ErrPermissionDenied) {
|
||||
if err := as.isOpPermitted("foo", as.Revision(), perm.Key, perm.RangeEnd, perm.PermType); err != ErrPermissionDenied {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -545,7 +545,7 @@ func TestRoleGrantPermission(t *testing.T) {
|
||||
Name: "role-test-1",
|
||||
})
|
||||
|
||||
if !errors.Is(err, ErrPermissionNotGiven) {
|
||||
if err != ErrPermissionNotGiven {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -887,13 +887,13 @@ func TestAuthInfoFromCtx(t *testing.T) {
|
||||
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid Token"}))
|
||||
_, err = as.AuthInfoFromCtx(ctx)
|
||||
if !errors.Is(err, ErrInvalidAuthToken) {
|
||||
if err != ErrInvalidAuthToken {
|
||||
t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err)
|
||||
}
|
||||
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid.Token"}))
|
||||
_, err = as.AuthInfoFromCtx(ctx)
|
||||
if !errors.Is(err, ErrInvalidAuthToken) {
|
||||
if err != ErrInvalidAuthToken {
|
||||
t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err)
|
||||
}
|
||||
|
||||
@ -914,14 +914,14 @@ func TestAuthDisable(t *testing.T) {
|
||||
as.AuthDisable()
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err := as.Authenticate(ctx, "foo", "bar")
|
||||
if !errors.Is(err, ErrAuthNotEnabled) {
|
||||
if err != ErrAuthNotEnabled {
|
||||
t.Errorf("expected %v, got %v", ErrAuthNotEnabled, err)
|
||||
}
|
||||
|
||||
// Disabling disabled auth to make sure it can return safely if store is already disabled.
|
||||
as.AuthDisable()
|
||||
_, err = as.Authenticate(ctx, "foo", "bar")
|
||||
if !errors.Is(err, ErrAuthNotEnabled) {
|
||||
if err != ErrAuthNotEnabled {
|
||||
t.Errorf("expected %v, got %v", ErrAuthNotEnabled, err)
|
||||
}
|
||||
}
|
||||
@ -980,19 +980,19 @@ func TestIsAdminPermitted(t *testing.T) {
|
||||
|
||||
// invalid user
|
||||
err = as.IsAdminPermitted(&AuthInfo{Username: "rooti", Revision: 1})
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Errorf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
|
||||
// empty user
|
||||
err = as.IsAdminPermitted(&AuthInfo{Username: "", Revision: 1})
|
||||
if !errors.Is(err, ErrUserEmpty) {
|
||||
if err != ErrUserEmpty {
|
||||
t.Errorf("expected %v, got %v", ErrUserEmpty, err)
|
||||
}
|
||||
|
||||
// non-admin user
|
||||
err = as.IsAdminPermitted(&AuthInfo{Username: "foo", Revision: 1})
|
||||
if !errors.Is(err, ErrPermissionDenied) {
|
||||
if err != ErrPermissionDenied {
|
||||
t.Errorf("expected %v, got %v", ErrPermissionDenied, err)
|
||||
}
|
||||
|
||||
@ -1013,13 +1013,13 @@ func TestRecoverFromSnapshot(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserAlreadyExist) {
|
||||
if err != ErrUserAlreadyExist {
|
||||
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||
}
|
||||
|
||||
ua = &pb.AuthUserAddRequest{Name: "", Options: &authpb.UserAddOptions{NoPassword: false}}
|
||||
_, err = as.UserAdd(ua) // add a user with empty name
|
||||
if !errors.Is(err, ErrUserEmpty) {
|
||||
if err != ErrUserEmpty {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -1195,7 +1195,7 @@ func TestUserNoPasswordAdd(t *testing.T) {
|
||||
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err = as.Authenticate(ctx, username, "")
|
||||
if !errors.Is(err, ErrAuthFailed) {
|
||||
if err != ErrAuthFailed {
|
||||
t.Fatalf("expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
}
|
||||
@ -1237,7 +1237,7 @@ func TestUserChangePasswordWithOldLog(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
if !errors.Is(err, ErrUserNotFound) {
|
||||
if err != ErrUserNotFound {
|
||||
t.Fatalf("expected %v, got %v", ErrUserNotFound, err)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package embed
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
@ -33,7 +32,7 @@ func TestEmptyClientTLSInfo_createMetricsListener(t *testing.T) {
|
||||
Scheme: "https",
|
||||
Host: "localhost:8080",
|
||||
}
|
||||
if _, err := e.createMetricsListener(murl); !errors.Is(err, ErrMissingClientTLSInfoForMetricsURL) {
|
||||
if _, err := e.createMetricsListener(murl); err != ErrMissingClientTLSInfoForMetricsURL {
|
||||
t.Fatalf("expected error %v, got %v", ErrMissingClientTLSInfoForMetricsURL, err)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package embed
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -44,7 +43,7 @@ func TestStartEtcdWrongToken(t *testing.T) {
|
||||
cfg.Dir = tdir
|
||||
cfg.AuthToken = "wrong-token"
|
||||
|
||||
if _, err := StartEtcd(cfg); !errors.Is(err, auth.ErrInvalidAuthOpts) {
|
||||
if _, err := StartEtcd(cfg); err != auth.ErrInvalidAuthOpts {
|
||||
t.Fatalf("expected %v, got %v", auth.ErrInvalidAuthOpts, err)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package etcdmain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@ -225,7 +224,7 @@ func TestConfigParsingConflictClusteringFlags(t *testing.T) {
|
||||
|
||||
for i, tt := range conflictArgs {
|
||||
cfg := newConfig()
|
||||
if err := cfg.parse(tt); !errors.Is(err, embed.ErrConflictBootstrapFlags) {
|
||||
if err := cfg.parse(tt); err != embed.ErrConflictBootstrapFlags {
|
||||
t.Errorf("%d: err = %v, want %v", i, err, embed.ErrConflictBootstrapFlags)
|
||||
}
|
||||
}
|
||||
@ -268,7 +267,7 @@ func TestConfigFileConflictClusteringFlags(t *testing.T) {
|
||||
args := []string{fmt.Sprintf("--config-file=%s", tmpfile.Name())}
|
||||
|
||||
cfg := newConfig()
|
||||
if err := cfg.parse(args); !errors.Is(err, embed.ErrConflictBootstrapFlags) {
|
||||
if err := cfg.parse(args); err != embed.ErrConflictBootstrapFlags {
|
||||
t.Errorf("%d: err = %v, want %v", i, err, embed.ErrConflictBootstrapFlags)
|
||||
}
|
||||
}
|
||||
@ -311,7 +310,7 @@ func TestConfigParsingMissedAdvertiseClientURLsFlag(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
cfg := newConfig()
|
||||
if err := cfg.parse(tt.args); !errors.Is(err, tt.werr) {
|
||||
if err := cfg.parse(tt.args); err != tt.werr {
|
||||
t.Errorf("%d: err = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package membership
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
@ -459,7 +458,7 @@ func TestClusterValidateConfigurationChangeV2(t *testing.T) {
|
||||
}
|
||||
for i, tt := range tests {
|
||||
err := cl.ValidateConfigurationChange(tt.cc)
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: validateConfigurationChange error = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package rafthttp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -78,13 +77,13 @@ func TestMessage(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
b := &bytes.Buffer{}
|
||||
enc := &messageEncoder{w: b}
|
||||
if err := enc.encode(&tt.msg); !errors.Is(err, tt.encodeErr) {
|
||||
if err := enc.encode(&tt.msg); err != tt.encodeErr {
|
||||
t.Errorf("#%d: encode message error expected %v, got %v", i, tt.encodeErr, err)
|
||||
continue
|
||||
}
|
||||
dec := &messageDecoder{r: b}
|
||||
m, err := dec.decode()
|
||||
if !errors.Is(err, tt.decodeErr) {
|
||||
if err != tt.decodeErr {
|
||||
t.Errorf("#%d: decode message error expected %v, got %v", i, tt.decodeErr, err)
|
||||
continue
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ func (p *pipeline) post(data []byte) (err error) {
|
||||
p.picker.unreachable(u)
|
||||
// errMemberRemoved is a critical error since a removed member should
|
||||
// always be stopped. So we use reportCriticalError to report it to errorc.
|
||||
if errors.Is(err, errMemberRemoved) {
|
||||
if err == errMemberRemoved {
|
||||
reportCriticalError(err, p.errorc)
|
||||
}
|
||||
return err
|
||||
|
@ -17,7 +17,6 @@ package rafthttp
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
@ -111,7 +110,7 @@ func (s *snapshotSender) send(merged snap.Message) {
|
||||
|
||||
// errMemberRemoved is a critical error since a removed member should
|
||||
// always be stopped. So we use reportCriticalError to report it to errorc.
|
||||
if errors.Is(err, errMemberRemoved) {
|
||||
if err == errMemberRemoved {
|
||||
reportCriticalError(err, s.errorc)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package rafthttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -404,7 +403,7 @@ func (cr *streamReader) run() {
|
||||
for {
|
||||
rc, err := cr.dial(t)
|
||||
if err != nil {
|
||||
if !errors.Is(err, errUnsupportedStreamType) {
|
||||
if err != errUnsupportedStreamType {
|
||||
cr.status.deactivate(failureType{source: t.String(), action: "dial"}, err.Error())
|
||||
}
|
||||
} else {
|
||||
@ -429,7 +428,7 @@ func (cr *streamReader) run() {
|
||||
}
|
||||
switch {
|
||||
// all data is read out
|
||||
case errors.Is(err, io.EOF):
|
||||
case err == io.EOF:
|
||||
// connection is closed by the remote
|
||||
case transport.IsClosedConnError(err):
|
||||
default:
|
||||
|
@ -256,7 +256,7 @@ func TestStreamReaderDialDetectUnsupport(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := sr.dial(typ)
|
||||
if !errors.Is(err, errUnsupportedStreamType) {
|
||||
if err != errUnsupportedStreamType {
|
||||
t.Errorf("#%d: error = %v, want %v", i, err, errUnsupportedStreamType)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package snap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
@ -81,7 +80,7 @@ func TestBadCRC(t *testing.T) {
|
||||
crcTable = crc32.MakeTable(crc32.Koopman)
|
||||
|
||||
_, err = Read(zaptest.NewLogger(t), filepath.Join(dir, fmt.Sprintf("%016x-%016x.snap", 1, 1)))
|
||||
if err == nil || !errors.Is(err, ErrCRCMismatch) {
|
||||
if err == nil || err != ErrCRCMismatch {
|
||||
t.Errorf("err = %v, want %v", err, ErrCRCMismatch)
|
||||
}
|
||||
}
|
||||
@ -222,7 +221,7 @@ func TestNoSnapshot(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
ss := New(zaptest.NewLogger(t), dir)
|
||||
_, err = ss.Load()
|
||||
if !errors.Is(err, ErrNoSnapshot) {
|
||||
if err != ErrNoSnapshot {
|
||||
t.Errorf("err = %v, want %v", err, ErrNoSnapshot)
|
||||
}
|
||||
}
|
||||
@ -241,7 +240,7 @@ func TestEmptySnapshot(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = Read(zaptest.NewLogger(t), filepath.Join(dir, "1.snap"))
|
||||
if !errors.Is(err, ErrEmptySnapshot) {
|
||||
if err != ErrEmptySnapshot {
|
||||
t.Errorf("err = %v, want %v", err, ErrEmptySnapshot)
|
||||
}
|
||||
}
|
||||
@ -263,7 +262,7 @@ func TestAllSnapshotBroken(t *testing.T) {
|
||||
|
||||
ss := New(zaptest.NewLogger(t), dir)
|
||||
_, err = ss.Load()
|
||||
if !errors.Is(err, ErrNoSnapshot) {
|
||||
if err != ErrNoSnapshot {
|
||||
t.Errorf("err = %v, want %v", err, ErrNoSnapshot)
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ func (d *discovery) joinCluster(config string) (string, error) {
|
||||
func (d *discovery) getCluster() (string, error) {
|
||||
nodes, size, index, err := d.checkCluster()
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrFullCluster) {
|
||||
if err == ErrFullCluster {
|
||||
return nodesToCluster(nodes, size)
|
||||
}
|
||||
return "", err
|
||||
@ -227,7 +227,7 @@ func (d *discovery) checkCluster() ([]*client.Node, uint64, uint64, error) {
|
||||
if eerr, ok := err.(*client.Error); ok && eerr.Code == client.ErrorCodeKeyNotFound {
|
||||
return nil, 0, 0, ErrSizeNotFound
|
||||
}
|
||||
if errors.Is(err, client.ErrInvalidJSON) {
|
||||
if err == client.ErrInvalidJSON {
|
||||
return nil, 0, 0, ErrBadDiscoveryEndpoint
|
||||
}
|
||||
if ce, ok := err.(*client.ClusterError); ok {
|
||||
|
@ -212,7 +212,7 @@ func TestCheckCluster(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
ns, size, index, err := d.checkCluster()
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
if reflect.DeepEqual(ns, tt.nodes) {
|
||||
@ -336,7 +336,7 @@ func TestCreateSelf(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
d := newTestDiscovery(t, "1000", 1, tt.c)
|
||||
if err := d.createSelf(""); !errors.Is(err, tt.werr) {
|
||||
if err := d.createSelf(""); err != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, nil)
|
||||
}
|
||||
}
|
||||
@ -383,7 +383,7 @@ func TestNodesToCluster(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
cluster, err := nodesToCluster(tt.nodes, tt.size)
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
if !reflect.DeepEqual(cluster, tt.wcluster) {
|
||||
@ -435,7 +435,7 @@ func TestRetryFailure(t *testing.T) {
|
||||
fc.Advance(time.Second * (0x1 << i))
|
||||
}
|
||||
}()
|
||||
if _, _, _, err := d.checkCluster(); !errors.Is(err, ErrTooManyRetries) {
|
||||
if _, _, _, err := d.checkCluster(); err != ErrTooManyRetries {
|
||||
t.Errorf("err = %v, want %v", err, ErrTooManyRetries)
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func TestGetClusterSize(t *testing.T) {
|
||||
clusterToken: "fakeToken",
|
||||
}
|
||||
|
||||
if cs, err := d.getClusterSize(); !errors.Is(err, tc.expectedErr) {
|
||||
if cs, err := d.getClusterSize(); err != tc.expectedErr {
|
||||
t.Errorf("Unexpected error, expected: %v got: %v", tc.expectedErr, err)
|
||||
} else {
|
||||
if err == nil && cs != tc.expectedSize {
|
||||
@ -387,7 +387,7 @@ func TestCheckCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
clsInfo, _, _, err := d.checkCluster()
|
||||
if !errors.Is(err, tc.expectedError) {
|
||||
if err != tc.expectedError {
|
||||
t.Errorf("Unexpected error, expected: %v, got: %v", tc.expectedError, err)
|
||||
}
|
||||
|
||||
@ -724,7 +724,7 @@ func TestGetInitClusterStr(t *testing.T) {
|
||||
}
|
||||
|
||||
retStr, err := clsInfo.getInitClusterStr(tc.clusterSize)
|
||||
if !errors.Is(err, tc.expectedError) {
|
||||
if err != tc.expectedError {
|
||||
t.Errorf("Unexpected error, expected: %v, got: %v", tc.expectedError, err)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package v3rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@ -62,10 +61,10 @@ func (ls *LeaseServer) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeReques
|
||||
|
||||
func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) {
|
||||
resp, err := ls.le.LeaseTimeToLive(ctx, rr)
|
||||
if err != nil && !errors.Is(err, lease.ErrLeaseNotFound) {
|
||||
if err != nil && err != lease.ErrLeaseNotFound {
|
||||
return nil, togRPCError(err)
|
||||
}
|
||||
if errors.Is(err, lease.ErrLeaseNotFound) {
|
||||
if err == lease.ErrLeaseNotFound {
|
||||
resp = &pb.LeaseTimeToLiveResponse{
|
||||
Header: &pb.ResponseHeader{},
|
||||
ID: rr.ID,
|
||||
@ -81,7 +80,7 @@ func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesReques
|
||||
if err != nil && err != lease.ErrLeaseNotFound {
|
||||
return nil, togRPCError(err)
|
||||
}
|
||||
if errors.Is(err, lease.ErrLeaseNotFound) {
|
||||
if err == lease.ErrLeaseNotFound {
|
||||
resp = &pb.LeaseLeasesResponse{
|
||||
Header: &pb.ResponseHeader{},
|
||||
Leases: []*pb.LeaseStatus{},
|
||||
@ -101,7 +100,7 @@ func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err
|
||||
case <-stream.Context().Done():
|
||||
// the only server-side cancellation is noleader for now.
|
||||
err = stream.Context().Err()
|
||||
if errors.Is(err, context.Canceled) {
|
||||
if err == context.Canceled {
|
||||
err = rpctypes.ErrGRPCNoLeader
|
||||
}
|
||||
}
|
||||
@ -111,7 +110,7 @@ func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err
|
||||
func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error {
|
||||
for {
|
||||
req, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
@ -134,7 +133,7 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
|
||||
ls.hdr.fill(resp.Header)
|
||||
|
||||
ttl, err := ls.le.LeaseRenew(stream.Context(), lease.LeaseID(req.ID))
|
||||
if errors.Is(err, lease.ErrLeaseNotFound) {
|
||||
if err == lease.ErrLeaseNotFound {
|
||||
err = nil
|
||||
ttl = 0
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package v3rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
errorspkg "errors"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -96,7 +95,7 @@ var toGRPCErrorMap = map[error]error{
|
||||
|
||||
func togRPCError(err error) error {
|
||||
// let gRPC server convert to codes.Canceled, codes.DeadlineExceeded
|
||||
if errorspkg.Is(err, context.Canceled) || errorspkg.Is(err, context.DeadlineExceeded) {
|
||||
if err == context.Canceled || err == context.DeadlineExceeded {
|
||||
return err
|
||||
}
|
||||
grpcErr, ok := toGRPCErrorMap[err]
|
||||
|
@ -38,7 +38,7 @@ func TestGRPCError(t *testing.T) {
|
||||
{err: errors.New("foo"), exp: status.Error(codes.Unknown, "foo")},
|
||||
}
|
||||
for i := range tt {
|
||||
if err := togRPCError(tt[i].err); !errors.Is(err, tt[i].exp) {
|
||||
if err := togRPCError(tt[i].err); err != tt[i].exp {
|
||||
if _, ok := status.FromError(err); ok {
|
||||
if err.Error() == tt[i].exp.Error() {
|
||||
continue
|
||||
|
@ -16,7 +16,6 @@ package v3rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@ -212,13 +211,13 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) {
|
||||
// revisited.
|
||||
select {
|
||||
case err = <-errc:
|
||||
if errors.Is(err, context.Canceled) {
|
||||
if err == context.Canceled {
|
||||
err = rpctypes.ErrGRPCWatchCanceled
|
||||
}
|
||||
close(sws.ctrlStream)
|
||||
case <-stream.Context().Done():
|
||||
err = stream.Context().Err()
|
||||
if errors.Is(err, context.Canceled) {
|
||||
if err == context.Canceled {
|
||||
err = rpctypes.ErrGRPCWatchCanceled
|
||||
}
|
||||
}
|
||||
@ -242,7 +241,7 @@ func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) error
|
||||
func (sws *serverWatchStream) recvLoop() error {
|
||||
for {
|
||||
req, err := sws.gRPCStream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
@ -281,7 +280,7 @@ func (sws *serverWatchStream) recvLoop() error {
|
||||
case auth.ErrUserEmpty:
|
||||
cancelReason = rpctypes.ErrGRPCUserEmpty.Error()
|
||||
default:
|
||||
if !errors.Is(err, auth.ErrPermissionDenied) {
|
||||
if err != auth.ErrPermissionDenied {
|
||||
sws.lg.Error("unexpected error code", zap.Error(err))
|
||||
}
|
||||
cancelReason = rpctypes.ErrGRPCPermissionDenied.Error()
|
||||
|
@ -16,7 +16,6 @@ package v3rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
@ -70,7 +69,7 @@ func TestSendFragment(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
err := sendFragments(tt[i].wr, tt[i].maxRequestBytes, testSend)
|
||||
if !errors.Is(err, tt[i].werr) {
|
||||
if err != tt[i].werr {
|
||||
t.Errorf("#%d: expected error %v, got %v", i, tt[i].werr, err)
|
||||
}
|
||||
got := len(fragmentedResp)
|
||||
|
@ -16,7 +16,6 @@ package apply
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -388,8 +387,8 @@ func TestAuthApplierV3_AdminPermission(t *testing.T) {
|
||||
tc.request.Header = &pb.RequestHeader{Username: userReadOnly}
|
||||
}
|
||||
result := authApplier.Apply(ctx, tc.request, dummyApplyFunc)
|
||||
require.Equal(t, errors.Is(result.Err, auth.ErrPermissionDenied), tc.adminPermissionNeeded,
|
||||
"Admin permission needed: got %v, expect: %v", errors.Is(result.Err, auth.ErrPermissionDenied), tc.adminPermissionNeeded)
|
||||
require.Equal(t, result.Err == auth.ErrPermissionDenied, tc.adminPermissionNeeded,
|
||||
"Admin permission needed: got %v, expect: %v", result.Err == auth.ErrPermissionDenied, tc.adminPermissionNeeded)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package etcdserver
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
errorspkg "errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
@ -389,7 +388,7 @@ func TestApplyConfChangeError(t *testing.T) {
|
||||
cluster: cl,
|
||||
}
|
||||
_, err := srv.applyConfChange(tt.cc, nil, true)
|
||||
if !errorspkg.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: applyConfChange error = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
cc := raftpb.ConfChange{Type: tt.cc.Type, NodeID: raft.None, Context: tt.cc.Context}
|
||||
@ -1534,7 +1533,7 @@ func TestWaitAppliedIndex(t *testing.T) {
|
||||
|
||||
err := s.waitAppliedIndex()
|
||||
|
||||
if !errorspkg.Is(err, tc.ExpectedError) {
|
||||
if err != tc.ExpectedError {
|
||||
t.Errorf("Unexpected error, want (%v), got (%v)", tc.ExpectedError, err)
|
||||
}
|
||||
})
|
||||
|
@ -75,7 +75,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
ttl, rerr := h.l.Renew(lease.LeaseID(lreq.ID))
|
||||
if rerr != nil {
|
||||
if errors.Is(rerr, lease.ErrLeaseNotFound) {
|
||||
if rerr == lease.ErrLeaseNotFound {
|
||||
http.Error(w, rerr.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package lease
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -455,7 +454,7 @@ func TestLessorExpire(t *testing.T) {
|
||||
donec := make(chan struct{}, 1)
|
||||
go func() {
|
||||
// expired lease cannot be renewed
|
||||
if _, err := le.Renew(l.ID); !errors.Is(err, ErrLeaseNotFound) {
|
||||
if _, err := le.Renew(l.ID); err != ErrLeaseNotFound {
|
||||
t.Errorf("unexpected renew")
|
||||
}
|
||||
donec <- struct{}{}
|
||||
@ -508,7 +507,7 @@ func TestLessorExpireAndDemote(t *testing.T) {
|
||||
donec := make(chan struct{}, 1)
|
||||
go func() {
|
||||
// expired lease cannot be renewed
|
||||
if _, err := le.Renew(l.ID); !errors.Is(err, ErrNotPrimary) {
|
||||
if _, err := le.Renew(l.ID); err != ErrNotPrimary {
|
||||
t.Errorf("unexpected renew: %v", err)
|
||||
}
|
||||
donec <- struct{}{}
|
||||
@ -540,7 +539,7 @@ func TestLessorMaxTTL(t *testing.T) {
|
||||
defer le.Stop()
|
||||
|
||||
_, err := le.Grant(1, MaxLeaseTTL+1)
|
||||
if !errors.Is(err, ErrLeaseTTLTooLarge) {
|
||||
if err != ErrLeaseTTLTooLarge {
|
||||
t.Fatalf("grant unexpectedly succeeded")
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package grpcproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@ -246,7 +245,7 @@ type leaseProxyStream struct {
|
||||
func (lps *leaseProxyStream) recvLoop() error {
|
||||
for {
|
||||
rr, err := lps.stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -16,7 +16,6 @@ package grpcproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
|
||||
@ -51,7 +50,7 @@ func (mp *maintenanceProxy) Snapshot(sr *pb.SnapshotRequest, stream pb.Maintenan
|
||||
for {
|
||||
rr, err := sc.Recv()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -15,7 +15,6 @@
|
||||
package mvcc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -47,7 +46,7 @@ func TestIndexGet(t *testing.T) {
|
||||
}
|
||||
for i, tt := range tests {
|
||||
rev, created, ver, err := ti.Get([]byte("foo"), tt.rev)
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
if rev != tt.wrev {
|
||||
@ -131,11 +130,11 @@ func TestIndexTombstone(t *testing.T) {
|
||||
}
|
||||
|
||||
_, _, _, err = ti.Get([]byte("foo"), 2)
|
||||
if !errors.Is(err, ErrRevisionNotFound) {
|
||||
if err != ErrRevisionNotFound {
|
||||
t.Errorf("get error = %v, want ErrRevisionNotFound", err)
|
||||
}
|
||||
err = ti.Tombstone([]byte("foo"), Revision{Main: 3})
|
||||
if !errors.Is(err, ErrRevisionNotFound) {
|
||||
if err != ErrRevisionNotFound {
|
||||
t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package mvcc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -74,7 +73,7 @@ func TestKeyIndexGet(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
mod, creat, ver, err := ki.get(zaptest.NewLogger(t), tt.rev)
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
if mod != tt.wmod {
|
||||
@ -214,7 +213,7 @@ func TestKeyIndexTombstone(t *testing.T) {
|
||||
}
|
||||
|
||||
err = ki.tombstone(zaptest.NewLogger(t), 16, 0)
|
||||
if !errors.Is(err, ErrRevisionNotFound) {
|
||||
if err != ErrRevisionNotFound {
|
||||
t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package mvcc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -204,7 +203,7 @@ func testKVRangeBadRev(t *testing.T, f rangeFunc) {
|
||||
}
|
||||
for i, tt := range tests {
|
||||
_, err := f(s, []byte("foo"), []byte("foo3"), RangeOptions{Rev: tt.rev})
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: error = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
}
|
||||
@ -627,7 +626,7 @@ func TestKVCompactBad(t *testing.T) {
|
||||
}
|
||||
for i, tt := range tests {
|
||||
_, err := s.Compact(traceutil.TODO(), tt.rev)
|
||||
if !errors.Is(err, tt.werr) {
|
||||
if err != tt.werr {
|
||||
t.Errorf("#%d: compact error = %v, want %v", i, err, tt.werr)
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
mrand "math/rand"
|
||||
@ -519,7 +518,7 @@ func TestRestoreContinueUnfinishedCompaction(t *testing.T) {
|
||||
// wait for scheduled compaction to be finished
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
if _, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: 1}); !errors.Is(err, ErrCompacted) {
|
||||
if _, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: 1}); err != ErrCompacted {
|
||||
t.Errorf("range on compacted rev error = %v, want %v", err, ErrCompacted)
|
||||
}
|
||||
// check the key in backend is deleted
|
||||
|
@ -16,7 +16,6 @@ package mvcc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -109,7 +108,7 @@ func TestWatcherRequestsCustomID(t *testing.T) {
|
||||
for i, tcase := range tt {
|
||||
id, err := w.Watch(tcase.givenID, []byte("foo"), nil, 0)
|
||||
if tcase.expectedErr != nil || err != nil {
|
||||
if !errors.Is(err, tcase.expectedErr) {
|
||||
if err != tcase.expectedErr {
|
||||
t.Errorf("expected get error %q in test case %q, got %q", tcase.expectedErr, i, err)
|
||||
}
|
||||
} else if tcase.expectedID != id {
|
||||
@ -202,10 +201,10 @@ func TestWatcherWatchWrongRange(t *testing.T) {
|
||||
w := s.NewWatchStream()
|
||||
defer w.Close()
|
||||
|
||||
if _, err := w.Watch(0, []byte("foa"), []byte("foa"), 1); !errors.Is(err, ErrEmptyWatcherRange) {
|
||||
if _, err := w.Watch(0, []byte("foa"), []byte("foa"), 1); err != ErrEmptyWatcherRange {
|
||||
t.Fatalf("key == end range given; expected ErrEmptyWatcherRange, got %+v", err)
|
||||
}
|
||||
if _, err := w.Watch(0, []byte("fob"), []byte("foa"), 1); !errors.Is(err, ErrEmptyWatcherRange) {
|
||||
if _, err := w.Watch(0, []byte("fob"), []byte("foa"), 1); err != ErrEmptyWatcherRange {
|
||||
t.Fatalf("key > end range given; expected ErrEmptyWatcherRange, got %+v", err)
|
||||
}
|
||||
// watch request with 'WithFromKey' has empty-byte range end
|
||||
@ -279,7 +278,7 @@ func TestWatchStreamCancelWatcherByID(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
gerr := w.Cancel(tt.cancelID)
|
||||
|
||||
if !errors.Is(gerr, tt.werr) {
|
||||
if gerr != tt.werr {
|
||||
t.Errorf("#%d: err = %v, want %v", i, gerr, tt.werr)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -136,7 +135,7 @@ func TestActionListRevert(t *testing.T) {
|
||||
|
||||
UnsafeCreateMetaBucket(tx)
|
||||
err := tc.actions.unsafeExecute(lg, tx)
|
||||
if !errors.Is(err, tc.expectError) {
|
||||
if err != tc.expectError {
|
||||
t.Errorf("Unexpected error or lack thereof, expected: %v, got: %v", tc.expectError, err)
|
||||
}
|
||||
assertBucketState(t, tx, Meta, tc.expectState)
|
||||
|
@ -15,7 +15,6 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -179,7 +178,7 @@ func TestMigrationStepExecute(t *testing.T) {
|
||||
|
||||
step := newMigrationStep(tc.currentVersion, tc.isUpgrade, tc.changes)
|
||||
err := step.unsafeExecute(lg, tx)
|
||||
if !errors.Is(err, tc.expectError) {
|
||||
if err != tc.expectError {
|
||||
t.Errorf("Unexpected error or lack thereof, expected: %v, got: %v", tc.expectError, err)
|
||||
}
|
||||
v := UnsafeReadStorageVersion(tx)
|
||||
|
@ -16,7 +16,6 @@ package wal
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
@ -115,7 +114,7 @@ func (d *decoder) decodeRecord(rec *walpb.Record) error {
|
||||
if _, err = io.ReadFull(fileBufReader, data); err != nil {
|
||||
// ReadFull returns io.EOF only if no bytes were read
|
||||
// the decoder should treat this as an ErrUnexpectedEOF instead.
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
return err
|
||||
|
@ -15,7 +15,6 @@
|
||||
package wal
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -203,7 +202,7 @@ func TestRepairFailDeleteDir(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, _, err = w.ReadAll()
|
||||
if !errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
t.Fatalf("err = %v, want error %v", err, io.ErrUnexpectedEOF)
|
||||
}
|
||||
w.Close()
|
||||
|
@ -101,7 +101,7 @@ func TestCreateFailFromPollutedDir(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(p, "test.wal"), []byte("data"), os.ModeTemporary)
|
||||
|
||||
_, err := Create(zaptest.NewLogger(t), p, []byte("data"))
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
if err != os.ErrExist {
|
||||
t.Fatalf("expected %v, got %v", os.ErrExist, err)
|
||||
}
|
||||
}
|
||||
@ -152,7 +152,7 @@ func TestNewForInitedDir(t *testing.T) {
|
||||
p := t.TempDir()
|
||||
|
||||
os.Create(filepath.Join(p, walName(0, 0)))
|
||||
if _, err := Create(zaptest.NewLogger(t), p, nil); err == nil || !errors.Is(err, os.ErrExist) {
|
||||
if _, err := Create(zaptest.NewLogger(t), p, nil); err == nil || err != os.ErrExist {
|
||||
t.Errorf("err = %v, want %v", err, os.ErrExist)
|
||||
}
|
||||
}
|
||||
@ -663,7 +663,7 @@ func TestOpenWithMaxIndex(t *testing.T) {
|
||||
defer w2.Close()
|
||||
|
||||
_, _, _, err = w2.ReadAll()
|
||||
if !errors.Is(err, ErrSliceOutOfRange) {
|
||||
if err != ErrSliceOutOfRange {
|
||||
t.Fatalf("err = %v, want ErrSliceOutOfRange", err)
|
||||
}
|
||||
}
|
||||
@ -964,7 +964,7 @@ func TestReadAllFail(t *testing.T) {
|
||||
f.Close()
|
||||
// try to read without opening the WAL
|
||||
_, _, _, err = f.ReadAll()
|
||||
if err == nil || !errors.Is(err, ErrDecoderNotFound) {
|
||||
if err == nil || err != ErrDecoderNotFound {
|
||||
t.Fatalf("err = %v, want ErrDecoderNotFound", err)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package e2e
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
@ -194,7 +193,7 @@ func getMemberList(cx ctlCtx, serializable bool) (etcdserverpb.MemberListRespons
|
||||
|
||||
resp := etcdserverpb.MemberListResponse{}
|
||||
dec := json.NewDecoder(strings.NewReader(txt))
|
||||
if err := dec.Decode(&resp); errors.Is(err, io.EOF) {
|
||||
if err := dec.Decode(&resp); err == io.EOF {
|
||||
return etcdserverpb.MemberListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
@ -222,7 +221,7 @@ func memberListWithHexTest(cx ctlCtx) {
|
||||
}
|
||||
hexResp := etcdserverpb.MemberListResponse{}
|
||||
dec := json.NewDecoder(strings.NewReader(txt))
|
||||
if err := dec.Decode(&hexResp); errors.Is(err, io.EOF) {
|
||||
if err := dec.Decode(&hexResp); err == io.EOF {
|
||||
cx.t.Fatalf("memberListWithHexTest error (%v)", err)
|
||||
}
|
||||
num := len(resp.Members)
|
||||
|
@ -17,7 +17,6 @@ package e2e
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -157,7 +156,7 @@ func getSnapshotStatus(cx ctlCtx, fpath string) (snapshot.Status, error) {
|
||||
|
||||
resp := snapshot.Status{}
|
||||
dec := json.NewDecoder(strings.NewReader(txt))
|
||||
if err := dec.Decode(&resp); errors.Is(err, io.EOF) {
|
||||
if err := dec.Decode(&resp); err == io.EOF {
|
||||
return snapshot.Status{}, err
|
||||
}
|
||||
return resp, nil
|
||||
|
@ -16,7 +16,6 @@ package concurrency_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
@ -65,7 +64,7 @@ func ExampleMutex_TryLock() {
|
||||
if err = m2.TryLock(context.TODO()); err == nil {
|
||||
log.Fatal("should not acquire lock")
|
||||
}
|
||||
if errors.Is(err, concurrency.ErrLocked) {
|
||||
if err == concurrency.ErrLocked {
|
||||
fmt.Println("cannot acquire lock for s2, as already locked in another session")
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ package connectivity_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -114,7 +113,7 @@ func TestBalancerUnderBlackholeKeepAliveWatch(t *testing.T) {
|
||||
func TestBalancerUnderBlackholeNoKeepAlivePut(t *testing.T) {
|
||||
testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error {
|
||||
_, err := cli.Put(ctx, "foo", "bar")
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) {
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout {
|
||||
return errExpected
|
||||
}
|
||||
return err
|
||||
@ -124,7 +123,7 @@ func TestBalancerUnderBlackholeNoKeepAlivePut(t *testing.T) {
|
||||
func TestBalancerUnderBlackholeNoKeepAliveDelete(t *testing.T) {
|
||||
testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error {
|
||||
_, err := cli.Delete(ctx, "foo")
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) {
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout {
|
||||
return errExpected
|
||||
}
|
||||
return err
|
||||
@ -137,7 +136,7 @@ func TestBalancerUnderBlackholeNoKeepAliveTxn(t *testing.T) {
|
||||
If(clientv3.Compare(clientv3.Version("foo"), "=", 0)).
|
||||
Then(clientv3.OpPut("foo", "bar")).
|
||||
Else(clientv3.OpPut("foo", "baz")).Commit()
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) {
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout {
|
||||
return errExpected
|
||||
}
|
||||
return err
|
||||
@ -147,7 +146,7 @@ func TestBalancerUnderBlackholeNoKeepAliveTxn(t *testing.T) {
|
||||
func TestBalancerUnderBlackholeNoKeepAliveLinearizableGet(t *testing.T) {
|
||||
testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error {
|
||||
_, err := cli.Get(ctx, "a")
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) {
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout {
|
||||
return errExpected
|
||||
}
|
||||
return err
|
||||
@ -208,7 +207,7 @@ func testBalancerUnderBlackholeNoKeepAlive(t *testing.T, op func(*clientv3.Clien
|
||||
cancel()
|
||||
if err == nil {
|
||||
break
|
||||
} else if errors.Is(err, errExpected) {
|
||||
} else if err == errExpected {
|
||||
t.Logf("#%d: current error %v", i, err)
|
||||
} else {
|
||||
t.Errorf("#%d: failed with error %v", i, err)
|
||||
|
@ -35,7 +35,7 @@ var errExpected = errors.New("expected error")
|
||||
|
||||
func isErrorExpected(err error) bool {
|
||||
return clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) ||
|
||||
errors.Is(err, rpctypes.ErrTimeout) || errors.Is(err, rpctypes.ErrTimeoutDueToLeaderFail)
|
||||
err == rpctypes.ErrTimeout || err == rpctypes.ErrTimeoutDueToLeaderFail
|
||||
}
|
||||
|
||||
// TestBalancerUnderNetworkPartitionPut tests when one member becomes isolated,
|
||||
@ -145,7 +145,7 @@ func testBalancerUnderNetworkPartition(t *testing.T, op func(*clientv3.Client, c
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if !errors.Is(err, errExpected) {
|
||||
if err != errExpected {
|
||||
t.Errorf("#%d: expected '%v', got '%v'", i, errExpected, err)
|
||||
}
|
||||
// give enough time for endpoint switch
|
||||
@ -267,7 +267,7 @@ func testBalancerUnderNetworkPartitionWatch(t *testing.T, isolateLeader bool) {
|
||||
if len(ev.Events) != 0 {
|
||||
t.Fatal("expected no event")
|
||||
}
|
||||
if err = ev.Err(); !errors.Is(err, rpctypes.ErrNoLeader) {
|
||||
if err = ev.Err(); err != rpctypes.ErrNoLeader {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrNoLeader, err)
|
||||
}
|
||||
case <-time.After(integration2.RequestWaitTimeout): // enough time to detect leader lost
|
||||
@ -313,7 +313,7 @@ func TestDropReadUnderNetworkPartition(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||
_, err = kvc.Get(ctx, "a")
|
||||
cancel()
|
||||
if !errors.Is(err, rpctypes.ErrLeaderChanged) {
|
||||
if err != rpctypes.ErrLeaderChanged {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrLeaderChanged, err)
|
||||
}
|
||||
|
||||
@ -322,7 +322,7 @@ func TestDropReadUnderNetworkPartition(t *testing.T) {
|
||||
_, err = kvc.Get(ctx, "a")
|
||||
cancel()
|
||||
if err != nil {
|
||||
if errors.Is(err, rpctypes.ErrTimeout) {
|
||||
if err == rpctypes.ErrTimeout {
|
||||
<-time.After(time.Second)
|
||||
i++
|
||||
continue
|
||||
|
@ -17,7 +17,6 @@ package connectivity_test
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -102,7 +101,7 @@ func TestBalancerUnderServerShutdownWatch(t *testing.T) {
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) || errors.Is(err, rpctypes.ErrTimeoutDueToLeaderFail) {
|
||||
if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout || err == rpctypes.ErrTimeoutDueToLeaderFail {
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
|
@ -16,7 +16,6 @@ package recipes_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -150,7 +149,7 @@ func TestDoubleBarrierTooManyClients(t *testing.T) {
|
||||
// no any other client can enter the barrier.
|
||||
wgEntered.Wait()
|
||||
t.Log("Try to enter into double barrier")
|
||||
if err = b.Enter(); !errors.Is(err, recipe.ErrTooManyClients) {
|
||||
if err = b.Enter(); err != recipe.ErrTooManyClients {
|
||||
t.Errorf("Unexcepted error, expected: ErrTooManyClients, got: %v", err)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package recipes_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@ -140,7 +139,7 @@ func testMutexTryLock(t *testing.T, lockers int, chooseClient func() *clientv3.C
|
||||
case <-ctx.Done():
|
||||
t.Errorf("Thread: %v, Context failed: %v", i, err)
|
||||
}
|
||||
} else if errors.Is(err, concurrency.ErrLocked) {
|
||||
} else if err == concurrency.ErrLocked {
|
||||
select {
|
||||
case notlockedC <- m:
|
||||
case <-ctx.Done():
|
||||
|
@ -16,7 +16,6 @@ package lease_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
@ -896,7 +895,7 @@ func TestLeasingTxnCancel(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
cancel()
|
||||
}()
|
||||
if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); !errors.Is(err, context.Canceled) {
|
||||
if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); err != context.Canceled {
|
||||
t.Fatalf("expected %v, got %v", context.Canceled, err)
|
||||
}
|
||||
}
|
||||
@ -2018,7 +2017,7 @@ func TestLeasingSessionExpireCancel(t *testing.T) {
|
||||
|
||||
select {
|
||||
case err := <-errc:
|
||||
if !errors.Is(err, ctx.Err()) {
|
||||
if err != ctx.Err() {
|
||||
t.Errorf("#%d: expected %v of server unavailable, got %v", i, ctx.Err(), err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
@ -2049,7 +2048,7 @@ func waitForExpireAck(t *testing.T, kv clientv3.KV) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
|
||||
_, err := kv.Get(ctx, "abc")
|
||||
cancel()
|
||||
if errors.Is(err, ctx.Err()) {
|
||||
if err == ctx.Err() {
|
||||
return
|
||||
} else if err != nil {
|
||||
t.Logf("current error: %v", err)
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@ -136,7 +135,7 @@ func TestMaintenanceMoveLeader(t *testing.T) {
|
||||
|
||||
cli := clus.Client(targetIdx)
|
||||
_, err := cli.MoveLeader(context.Background(), target)
|
||||
if !errors.Is(err, rpctypes.ErrNotLeader) {
|
||||
if err != rpctypes.ErrNotLeader {
|
||||
t.Fatalf("error expected %v, got %v", rpctypes.ErrNotLeader, err)
|
||||
}
|
||||
|
||||
@ -187,7 +186,7 @@ func TestMaintenanceSnapshotCancel(t *testing.T) {
|
||||
|
||||
cancel()
|
||||
_, err = io.Copy(io.Discard, rc1)
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
if err != context.Canceled {
|
||||
t.Errorf("expected %v, got %v", context.Canceled, err)
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func TestDetectKvOrderViolation(t *testing.T) {
|
||||
t.Logf("Quering m2 after restart")
|
||||
v, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
|
||||
t.Logf("Quering m2 returned: v:%v err:%v ", v, err)
|
||||
if !errors.Is(err, errOrderViolation) {
|
||||
if err != errOrderViolation {
|
||||
t.Fatalf("expected %v, got err:%v v:%v", errOrderViolation, err, v)
|
||||
}
|
||||
}
|
||||
@ -155,7 +155,7 @@ func TestDetectTxnOrderViolation(t *testing.T) {
|
||||
cli.SetEndpoints(clus.Members[2].GRPCURL)
|
||||
time.Sleep(2 * time.Second) // FIXME: Figure out how pause SetEndpoints sufficiently that this is not needed
|
||||
_, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
|
||||
if !errors.Is(err, errOrderViolation) {
|
||||
if err != errOrderViolation {
|
||||
t.Fatalf("expected %v, got %v", errOrderViolation, err)
|
||||
}
|
||||
orderingTxn = orderingKv.Txn(ctx)
|
||||
@ -164,7 +164,7 @@ func TestDetectTxnOrderViolation(t *testing.T) {
|
||||
).Then(
|
||||
clientv3.OpGet("foo", clientv3.WithSerializable()),
|
||||
).Commit()
|
||||
if !errors.Is(err, errOrderViolation) {
|
||||
if err != errOrderViolation {
|
||||
t.Fatalf("expected %v, got %v", errOrderViolation, err)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package clientv3test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -79,7 +78,7 @@ func TestEndpointSwitchResolvesViolation(t *testing.T) {
|
||||
cli.SetEndpoints(clus.Members[2].GRPCURL)
|
||||
time.Sleep(1 * time.Second) // give enough time for the operation
|
||||
_, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
|
||||
if !errors.Is(err, ordering.ErrNoGreaterRev) {
|
||||
if err != ordering.ErrNoGreaterRev {
|
||||
t.Fatal("While speaking to partitioned leader, we should get ErrNoGreaterRev error")
|
||||
}
|
||||
|
||||
@ -157,7 +156,7 @@ func TestUnresolvableOrderViolation(t *testing.T) {
|
||||
time.Sleep(1 * time.Second) // give enough time for operation
|
||||
|
||||
_, err = OrderingKv.Get(ctx, "foo", clientv3.WithSerializable())
|
||||
if !errors.Is(err, ordering.ErrNoGreaterRev) {
|
||||
if err != ordering.ErrNoGreaterRev {
|
||||
t.Fatalf("expected %v, got %v", ordering.ErrNoGreaterRev, err)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package clientv3test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -37,7 +36,7 @@ func TestTxnError(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
|
||||
_, err := kv.Txn(ctx).Then(clientv3.OpPut("foo", "bar1"), clientv3.OpPut("foo", "bar2")).Commit()
|
||||
if !errors.Is(err, rpctypes.ErrDuplicateKey) {
|
||||
if err != rpctypes.ErrDuplicateKey {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrDuplicateKey, err)
|
||||
}
|
||||
|
||||
@ -46,7 +45,7 @@ func TestTxnError(t *testing.T) {
|
||||
ops[i] = clientv3.OpPut(fmt.Sprintf("foo%d", i), "")
|
||||
}
|
||||
_, err = kv.Txn(ctx).Then(ops...).Commit()
|
||||
if !errors.Is(err, rpctypes.ErrTooManyOps) {
|
||||
if err != rpctypes.ErrTooManyOps {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrTooManyOps, err)
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package clientv3test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -42,17 +41,17 @@ func TestUserError(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = authapi.UserAdd(context.TODO(), "foo", "bar")
|
||||
if !errors.Is(err, rpctypes.ErrUserAlreadyExist) {
|
||||
if err != rpctypes.ErrUserAlreadyExist {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrUserAlreadyExist, err)
|
||||
}
|
||||
|
||||
_, err = authapi.UserDelete(context.TODO(), "not-exist-user")
|
||||
if !errors.Is(err, rpctypes.ErrUserNotFound) {
|
||||
if err != rpctypes.ErrUserNotFound {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrUserNotFound, err)
|
||||
}
|
||||
|
||||
_, err = authapi.UserGrantRole(context.TODO(), "foo", "test-role-does-not-exist")
|
||||
if !errors.Is(err, rpctypes.ErrRoleNotFound) {
|
||||
if err != rpctypes.ErrRoleNotFound {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrRoleNotFound, err)
|
||||
}
|
||||
}
|
||||
@ -117,7 +116,7 @@ func TestUserErrorAuth(t *testing.T) {
|
||||
authSetupRoot(t, authapi.Auth)
|
||||
|
||||
// unauthenticated client
|
||||
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); !errors.Is(err, rpctypes.ErrUserEmpty) {
|
||||
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); err != rpctypes.ErrUserEmpty {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrUserEmpty, err)
|
||||
}
|
||||
|
||||
@ -128,11 +127,11 @@ func TestUserErrorAuth(t *testing.T) {
|
||||
DialOptions: []grpc.DialOption{grpc.WithBlock()},
|
||||
}
|
||||
cfg.Username, cfg.Password = "wrong-id", "123"
|
||||
if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) {
|
||||
if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err)
|
||||
}
|
||||
cfg.Username, cfg.Password = "root", "wrong-pass"
|
||||
if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) {
|
||||
if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed {
|
||||
t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err)
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
@ -115,7 +114,7 @@ func TestV3PutRestart(t *testing.T) {
|
||||
defer cancel()
|
||||
reqput := &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")}
|
||||
_, err := kvc.Put(ctx, reqput)
|
||||
if err != nil && errors.Is(err, ctx.Err()) {
|
||||
if err != nil && err == ctx.Err() {
|
||||
t.Fatalf("expected grpc error, got local ctx error (%v)", err)
|
||||
}
|
||||
}
|
||||
@ -1600,7 +1599,7 @@ func TestTLSGRPCRejectSecureClient(t *testing.T) {
|
||||
if client != nil || err == nil {
|
||||
client.Close()
|
||||
t.Fatalf("expected no client")
|
||||
} else if !errors.Is(err, context.DeadlineExceeded) {
|
||||
} else if err != context.DeadlineExceeded {
|
||||
t.Fatalf("unexpected error (%v)", err)
|
||||
}
|
||||
}
|
||||
@ -1777,7 +1776,7 @@ func testTLSReload(
|
||||
// 5. expect dial time-out when loading expired certs
|
||||
select {
|
||||
case gerr := <-errc:
|
||||
if !errors.Is(gerr, context.DeadlineExceeded) {
|
||||
if gerr != context.DeadlineExceeded {
|
||||
t.Fatalf("expected %v, got %v", context.DeadlineExceeded, gerr)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
|
@ -17,7 +17,6 @@ package integration
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -73,7 +72,7 @@ func testTLSCipherSuites(t *testing.T, valid bool) {
|
||||
if cli != nil {
|
||||
cli.Close()
|
||||
}
|
||||
if !valid && !errors.Is(cerr, context.DeadlineExceeded) {
|
||||
if !valid && cerr != context.DeadlineExceeded {
|
||||
t.Fatalf("expected %v with TLS handshake failure, got %v", context.DeadlineExceeded, cerr)
|
||||
}
|
||||
if valid && cerr != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user