From 0ed01efdfd1316b688602e041093e7ac8d384b27 Mon Sep 17 00:00:00 2001 From: "jesse.tang" <1430482733@qq.com> Date: Thu, 15 Sep 2022 20:10:39 +0800 Subject: [PATCH] revise err logic or null pointer exception (#2376) --- config/reader_test.go | 6 ------ contrib/config/polaris/config_test.go | 6 +++--- transport/transport_test.go | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/config/reader_test.go b/config/reader_test.go index f2ac1444b..15f8f6178 100644 --- a/config/reader_test.go +++ b/config/reader_test.go @@ -132,9 +132,6 @@ a: t.Fatal(`vvv is not equal to 1`) } - if err != nil { - t.Fatal(`err is not nil`) - } vv, ok = r.Value("a.b.Y") if !ok { t.Fatal(`ok is false`) @@ -147,9 +144,6 @@ a: t.Fatal(`vvy is not equal to "lol"`) } - if err != nil { - t.Fatal(`err is not nil`) - } vv, ok = r.Value("a.b.z") if !ok { t.Fatal(`ok is false`) diff --git a/contrib/config/polaris/config_test.go b/contrib/config/polaris/config_test.go index bf8b6fd61..9559174fa 100644 --- a/contrib/config/polaris/config_test.go +++ b/contrib/config/polaris/config_test.go @@ -26,13 +26,13 @@ var ( func makeJSONRequest(uri string, data string, method string, headers map[string]string) ([]byte, error) { client := http.Client{} req, err := http.NewRequest(method, uri, strings.NewReader(data)) + if err != nil { + return nil, err + } req.Header.Add("Content-Type", "application/json") for k, v := range headers { req.Header.Add(k, v) } - if err != nil { - return nil, err - } res, err := client.Do(req) if err != nil { return nil, err diff --git a/transport/transport_test.go b/transport/transport_test.go index b83c8ee3c..cba7f2ae1 100644 --- a/transport/transport_test.go +++ b/transport/transport_test.go @@ -53,7 +53,7 @@ func TestServerTransport(t *testing.T) { t.Errorf("expected:%v got:%v", true, ok) } if mtr == nil { - t.Errorf("expected:%v got:%v", nil, mtr) + t.Fatalf("expected:%v got:%v", nil, mtr) } if mtr.Kind().String() != KindGRPC.String() { t.Errorf("expected:%v got:%v", KindGRPC.String(), mtr.Kind().String())