From b849cfc18cc70268360e7b99e40f5ea43e695209 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 15:58:42 +0530 Subject: [PATCH] Fix unnecessary allocations due to `Index` calls --- .deepsource.toml | 12 ++++++++++++ adapter/httplib/httplib_test.go | 9 +++++---- client/httplib/httplib_test.go | 5 +++-- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 00000000..7901d2d2 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["**/*_test.go"] + +exclude_patterns = ["scripts/**"] + +[[analyzers]] +name = "go" +enabled = true + + [analyzers.meta] + import_paths = ["github.com/beego/beego"] diff --git a/adapter/httplib/httplib_test.go b/adapter/httplib/httplib_test.go index 350f716e..298d84f9 100644 --- a/adapter/httplib/httplib_test.go +++ b/adapter/httplib/httplib_test.go @@ -15,6 +15,7 @@ package httplib import ( + "bytes" "errors" "io/ioutil" "net" @@ -66,7 +67,7 @@ func TestDoRequest(t *testing.T) { } func TestGet(t *testing.T) { - + req := Get(getUrl) b, err := req.Bytes() if err != nil { @@ -222,7 +223,7 @@ func TestWithSetting(t *testing.T) { } func TestToJson(t *testing.T) { - + req := Get(ipUrl) resp, err := req.Response() if err != nil { @@ -261,7 +262,7 @@ func TestToFile(t *testing.T) { } defer os.Remove(f) b, err := ioutil.ReadFile(f) - if n := strings.Index(string(b), "origin"); n == -1 { + if n := bytes.Index(b, []byte("origin")); n == -1 { t.Fatal(err) } } @@ -275,7 +276,7 @@ func TestToFileDir(t *testing.T) { } defer os.RemoveAll("./files") b, err := ioutil.ReadFile(f) - if n := strings.Index(string(b), "origin"); n == -1 { + if n := bytes.Index(b, []byte("origin")); n == -1 { t.Fatal(err) } } diff --git a/client/httplib/httplib_test.go b/client/httplib/httplib_test.go index 1fde708a..9133ad5f 100644 --- a/client/httplib/httplib_test.go +++ b/client/httplib/httplib_test.go @@ -15,6 +15,7 @@ package httplib import ( + "bytes" "context" "errors" "io/ioutil" @@ -259,7 +260,7 @@ func TestToFile(t *testing.T) { } defer os.Remove(f) b, err := ioutil.ReadFile(f) - if n := strings.Index(string(b), "origin"); n == -1 { + if n := bytes.Index(b, []byte("origin")); n == -1 { t.Fatal(err) } } @@ -273,7 +274,7 @@ func TestToFileDir(t *testing.T) { } defer os.RemoveAll("./files") b, err := ioutil.ReadFile(f) - if n := strings.Index(string(b), "origin"); n == -1 { + if n := bytes.Index(b, []byte("origin")); n == -1 { t.Fatal(err) } }