all: fix warning flagging the use of DeepEqual on error (#23624)

* core: fix warning flagging the use of DeepEqual on error

* apply the same change everywhere possible

* revert change that was committed by mistake

* fix build error

* Update config.go

* revert changes to ConfigCompatError

* review feedback

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Guillaume Ballet 2021-10-19 17:06:47 +02:00 committed by GitHub
parent 84d8eb2ca8
commit 0183256e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -20,13 +20,13 @@ import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex" "encoding/hex"
"errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"strings" "strings"
"testing" "testing"
@ -555,7 +555,7 @@ func (n *handshakeTestNode) expectDecode(t *testing.T, ptype byte, p []byte) Pac
func (n *handshakeTestNode) expectDecodeErr(t *testing.T, wantErr error, p []byte) { func (n *handshakeTestNode) expectDecodeErr(t *testing.T, wantErr error, p []byte) {
t.Helper() t.Helper()
if _, err := n.decode(p); !reflect.DeepEqual(err, wantErr) { if _, err := n.decode(p); !errors.Is(err, wantErr) {
t.Fatal(fmt.Errorf("(%s) got err %q, want %q", n.ln.ID().TerminalString(), err, wantErr)) t.Fatal(fmt.Errorf("(%s) got err %q, want %q", n.ln.ID().TerminalString(), err, wantErr))
} }
} }

View File

@ -370,6 +370,8 @@ func TestServerSetupConn(t *testing.T) {
clientkey, srvkey = newkey(), newkey() clientkey, srvkey = newkey(), newkey()
clientpub = &clientkey.PublicKey clientpub = &clientkey.PublicKey
srvpub = &srvkey.PublicKey srvpub = &srvkey.PublicKey
fooErr = errors.New("foo")
readErr = errors.New("read error")
) )
tests := []struct { tests := []struct {
dontstart bool dontstart bool
@ -387,10 +389,10 @@ func TestServerSetupConn(t *testing.T) {
wantCloseErr: errServerStopped, wantCloseErr: errServerStopped,
}, },
{ {
tt: &setupTransport{pubkey: clientpub, encHandshakeErr: errors.New("read error")}, tt: &setupTransport{pubkey: clientpub, encHandshakeErr: readErr},
flags: inboundConn, flags: inboundConn,
wantCalls: "doEncHandshake,close,", wantCalls: "doEncHandshake,close,",
wantCloseErr: errors.New("read error"), wantCloseErr: readErr,
}, },
{ {
tt: &setupTransport{pubkey: clientpub, phs: protoHandshake{ID: randomID().Bytes()}}, tt: &setupTransport{pubkey: clientpub, phs: protoHandshake{ID: randomID().Bytes()}},
@ -400,11 +402,11 @@ func TestServerSetupConn(t *testing.T) {
wantCloseErr: DiscUnexpectedIdentity, wantCloseErr: DiscUnexpectedIdentity,
}, },
{ {
tt: &setupTransport{pubkey: clientpub, protoHandshakeErr: errors.New("foo")}, tt: &setupTransport{pubkey: clientpub, protoHandshakeErr: fooErr},
dialDest: enode.NewV4(clientpub, nil, 0, 0), dialDest: enode.NewV4(clientpub, nil, 0, 0),
flags: dynDialedConn, flags: dynDialedConn,
wantCalls: "doEncHandshake,doProtoHandshake,close,", wantCalls: "doEncHandshake,doProtoHandshake,close,",
wantCloseErr: errors.New("foo"), wantCloseErr: fooErr,
}, },
{ {
tt: &setupTransport{pubkey: srvpub, phs: protoHandshake{ID: crypto.FromECDSAPub(srvpub)[1:]}}, tt: &setupTransport{pubkey: srvpub, phs: protoHandshake{ID: crypto.FromECDSAPub(srvpub)[1:]}},
@ -443,7 +445,7 @@ func TestServerSetupConn(t *testing.T) {
} }
p1, _ := net.Pipe() p1, _ := net.Pipe()
srv.SetupConn(p1, test.flags, test.dialDest) srv.SetupConn(p1, test.flags, test.dialDest)
if !reflect.DeepEqual(test.tt.closeErr, test.wantCloseErr) { if !errors.Is(test.tt.closeErr, test.wantCloseErr) {
t.Errorf("test %d: close error mismatch: got %q, want %q", i, test.tt.closeErr, test.wantCloseErr) t.Errorf("test %d: close error mismatch: got %q, want %q", i, test.tt.closeErr, test.wantCloseErr)
} }
if test.tt.calls != test.wantCalls { if test.tt.calls != test.wantCalls {

View File

@ -18,8 +18,8 @@ package rlp
import ( import (
"bytes" "bytes"
"errors"
"io" "io"
"reflect"
"testing" "testing"
"testing/quick" "testing/quick"
) )
@ -54,7 +54,7 @@ func TestCountValues(t *testing.T) {
if count != test.count { if count != test.count {
t.Errorf("test %d: count mismatch, got %d want %d\ninput: %s", i, count, test.count, test.input) t.Errorf("test %d: count mismatch, got %d want %d\ninput: %s", i, count, test.count, test.input)
} }
if !reflect.DeepEqual(err, test.err) { if !errors.Is(err, test.err) {
t.Errorf("test %d: err mismatch, got %q want %q\ninput: %s", i, err, test.err, test.input) t.Errorf("test %d: err mismatch, got %q want %q\ninput: %s", i, err, test.err, test.input)
} }
} }

View File

@ -18,13 +18,13 @@ package rpc
import ( import (
"context" "context"
"errors"
"io" "io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"reflect"
"strings" "strings"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -69,7 +69,7 @@ func TestWebsocketOriginCheck(t *testing.T) {
t.Fatal("no error for wrong origin") t.Fatal("no error for wrong origin")
} }
wantErr := wsHandshakeError{websocket.ErrBadHandshake, "403 Forbidden"} wantErr := wsHandshakeError{websocket.ErrBadHandshake, "403 Forbidden"}
if !reflect.DeepEqual(err, wantErr) { if !errors.Is(err, wantErr) {
t.Fatalf("wrong error for wrong origin: %q", err) t.Fatalf("wrong error for wrong origin: %q", err)
} }