From deb4a23a09b2febab60fca70b1645592bd110704 Mon Sep 17 00:00:00 2001 From: Cael Rowley Date: Sun, 7 Jul 2024 02:20:40 +0200 Subject: [PATCH] chore: update deprecated and unused code in esutil --- esutil/bulk_indexer.go | 2 +- esutil/bulk_indexer_benchmark_test.go | 4 ++-- esutil/bulk_indexer_internal_test.go | 6 +++--- esutil/json_reader_benchmark_test.go | 5 ++--- esutil/json_reader_internal_test.go | 5 ++--- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/esutil/bulk_indexer.go b/esutil/bulk_indexer.go index 012dece2be..3e6ab7a5d6 100644 --- a/esutil/bulk_indexer.go +++ b/esutil/bulk_indexer.go @@ -176,7 +176,7 @@ func (item *BulkIndexerItem) marshallMeta() { } item.meta.WriteString(`"require_alias":`) item.meta.Write(strconv.AppendBool(aux, item.RequireAlias)) - aux = aux[:0] + _ = aux[:0] } if item.DocumentID != "" && item.IfSeqNo != nil && item.IfPrimaryTerm != nil { diff --git a/esutil/bulk_indexer_benchmark_test.go b/esutil/bulk_indexer_benchmark_test.go index 8ec356cedf..3158340cb8 100644 --- a/esutil/bulk_indexer_benchmark_test.go +++ b/esutil/bulk_indexer_benchmark_test.go @@ -23,7 +23,7 @@ package esutil_test import ( "bytes" "context" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -55,7 +55,7 @@ var mockResponseBody = `{ type mockTransp struct{} func (t *mockTransp) RoundTrip(req *http.Request) (*http.Response, error) { - return &http.Response{Body: ioutil.NopCloser(strings.NewReader(mockResponseBody))}, nil // 1x alloc + return &http.Response{Body: io.NopCloser(strings.NewReader(mockResponseBody))}, nil // 1x alloc } func BenchmarkBulkIndexer(b *testing.B) { diff --git a/esutil/bulk_indexer_internal_test.go b/esutil/bulk_indexer_internal_test.go index e78621e39d..aca0748e4f 100644 --- a/esutil/bulk_indexer_internal_test.go +++ b/esutil/bulk_indexer_internal_test.go @@ -283,17 +283,17 @@ func TestBulkIndexer(t *testing.T) { successFunc := func(ctx context.Context, item BulkIndexerItem, res BulkIndexerResponseItem) { atomic.AddUint64(&countSuccessful, 1) - buf, err := ioutil.ReadAll(item.Body) + buf, err := io.ReadAll(item.Body) if err != nil { t.Fatalf("Unexpected error: %s", err) } successfulItemBodies = append(successfulItemBodies, string(buf)) } - failureFunc := func(ctx context.Context, item BulkIndexerItem, res BulkIndexerResponseItem, err error) { + failureFunc := func(ctx context.Context, item BulkIndexerItem, res BulkIndexerResponseItem, _ error) { atomic.AddUint64(&countFailed, 1) failedIDs = append(failedIDs, item.DocumentID) - buf, err := ioutil.ReadAll(item.Body) + buf, err := io.ReadAll(item.Body) if err != nil { t.Fatalf("Unexpected error: %s", err) } diff --git a/esutil/json_reader_benchmark_test.go b/esutil/json_reader_benchmark_test.go index f9caa9e927..8794815827 100644 --- a/esutil/json_reader_benchmark_test.go +++ b/esutil/json_reader_benchmark_test.go @@ -25,7 +25,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "strings" "testing" @@ -71,7 +70,7 @@ func BenchmarkJSONReader(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - out, _ := ioutil.ReadAll(esutil.NewJSONReader(map[string]string{"foo": "bar"})) + out, _ := io.ReadAll(esutil.NewJSONReader(map[string]string{"foo": "bar"})) if string(out) != `{"foo":"bar"}`+"\n" { b.Fatalf("Unexpected output: %q", out) } @@ -95,7 +94,7 @@ func BenchmarkJSONReader(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - out, _ := ioutil.ReadAll(esutil.NewJSONReader(Foo{Bar: "baz"})) + out, _ := io.ReadAll(esutil.NewJSONReader(Foo{Bar: "baz"})) if string(out) != `{"bar":"BAZ"}`+"\n" { b.Fatalf("Unexpected output: %q", out) } diff --git a/esutil/json_reader_internal_test.go b/esutil/json_reader_internal_test.go index 6b3841f0c5..ca6f9d0031 100644 --- a/esutil/json_reader_internal_test.go +++ b/esutil/json_reader_internal_test.go @@ -24,7 +24,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "strings" "testing" ) @@ -49,14 +48,14 @@ func (f Foo) EncodeJSON(w io.Writer) error { func TestJSONReader(t *testing.T) { t.Run("Default", func(t *testing.T) { - out, _ := ioutil.ReadAll(NewJSONReader(map[string]string{"foo": "bar"})) + out, _ := io.ReadAll(NewJSONReader(map[string]string{"foo": "bar"})) if string(out) != `{"foo":"bar"}`+"\n" { t.Fatalf("Unexpected output: %s", out) } }) t.Run("Custom", func(t *testing.T) { - out, _ := ioutil.ReadAll(NewJSONReader(Foo{Bar: "baz"})) + out, _ := io.ReadAll(NewJSONReader(Foo{Bar: "baz"})) if string(out) != `{"bar":"BAZ"}`+"\n" { t.Fatalf("Unexpected output: %s", out) }