Skip to content

Commit 3da8cab

Browse files
author
kositsyn-pa
committed
remove deprecated ioutil in load
commit_hash:70c948e7a85febf8f97cc9d55f57561b704452d4
1 parent 05efaa6 commit 3da8cab

8 files changed

Lines changed: 18 additions & 25 deletions

File tree

cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"context"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"os"
1111
"os/signal"
@@ -221,7 +221,7 @@ func readConfig(args []string) *CliConfig {
221221
log.Info("Pandora version", zap.String("version", Version))
222222
if useStdinConfig {
223223
v.SetConfigType("yaml")
224-
configBuffer, err := ioutil.ReadAll(bufio.NewReader(os.Stdin))
224+
configBuffer, err := io.ReadAll(bufio.NewReader(os.Stdin))
225225
if err != nil {
226226
log.Fatal("Cannot read from standard input", zap.Error(err))
227227
}

components/guns/http/base.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
1110
"net/http/httptrace"
@@ -244,7 +243,7 @@ func (b *BaseGun) Shoot(ammo Ammo) {
244243
sample.SetProtoCode(res.StatusCode)
245244
defer res.Body.Close()
246245
// TODO: measure body read time
247-
_, err = io.Copy(ioutil.Discard, res.Body) // Buffers are pooled for ioutil.Discard
246+
_, err = io.Copy(io.Discard, res.Body) // Buffers are pooled for io.Discard
248247
if err != nil {
249248
b.Log.Warn("Body read fail", zap.Error(err))
250249
return
@@ -260,7 +259,7 @@ func (b *BaseGun) Close() error {
260259

261260
func (b *BaseGun) verboseLogging(res *http.Response) {
262261
if res.Request.Body != nil {
263-
reqBody, err := ioutil.ReadAll(res.Request.Body)
262+
reqBody, err := io.ReadAll(res.Request.Body)
264263
if err != nil {
265264
b.Log.Debug("Body read failed for verbose logging of Request")
266265
} else {
@@ -275,7 +274,7 @@ func (b *BaseGun) verboseLogging(res *http.Response) {
275274
)
276275

277276
if res.Body != nil {
278-
respBody, err := ioutil.ReadAll(res.Body)
277+
respBody, err := io.ReadAll(res.Body)
279278
if err != nil {
280279
b.Log.Debug("Body read failed for verbose logging of Response")
281280
} else {
@@ -328,8 +327,8 @@ func autotag(depth int, URL *url.URL) string {
328327

329328
func GetBody(req *http.Request) []byte {
330329
if req.Body != nil && req.Body != http.NoBody {
331-
bodyBytes, _ := ioutil.ReadAll(req.Body)
332-
req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
330+
bodyBytes, _ := io.ReadAll(req.Body)
331+
req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
333332
return bodyBytes
334333
}
335334

components/guns/http/base_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"net/http/httptest"
109
"net/url"
@@ -160,7 +159,7 @@ func (s *BaseGunSuite) Test_Shoot() {
160159
am.On("Request").Return(req, sample).Maybe()
161160
res = &http.Response{
162161
StatusCode: http.StatusNotFound,
163-
Body: ioutil.NopCloser(body),
162+
Body: io.NopCloser(body),
164163
Request: req,
165164
}
166165
s.base.Shoot(am)
@@ -170,15 +169,15 @@ func (s *BaseGunSuite) Test_Shoot() {
170169

171170
s.Run("Do ok", func() {
172171
beforeEachDoOk := func() {
173-
body = ioutil.NopCloser(strings.NewReader("aaaaaaa"))
172+
body = io.NopCloser(strings.NewReader("aaaaaaa"))
174173
s.base.AnswLog = answlog.NewNop()
175174
s.base.Client = &testDecoratedClient{
176175
before: func(doReq *http.Request) {
177176
s.Require().Equal(req, doReq)
178177
},
179178
returnRes: &http.Response{
180179
StatusCode: http.StatusNotFound,
181-
Body: ioutil.NopCloser(body),
180+
Body: io.NopCloser(body),
182181
Request: req,
183182
},
184183
}

core/coretest/sink.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package coretest
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"testing"
87

@@ -13,7 +12,7 @@ import (
1312
)
1413

1514
func AssertSinkEqualStdStream(t *testing.T, expectedPtr **os.File, getSink func() core.DataSink) {
16-
temp, err := ioutil.TempFile("", "")
15+
temp, err := os.CreateTemp("", "")
1716
require.NoError(t, err)
1817

1918
backup := *expectedPtr
@@ -33,7 +32,7 @@ func AssertSinkEqualStdStream(t *testing.T, expectedPtr **os.File, getSink func(
3332
require.NoError(t, err)
3433

3534
_, _ = temp.Seek(0, io.SeekStart)
36-
data, _ := ioutil.ReadAll(temp)
35+
data, _ := io.ReadAll(temp)
3736
assert.Equal(t, testdata, string(data))
3837
}
3938

core/coretest/source.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package coretest
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"testing"
87

@@ -14,7 +13,7 @@ import (
1413
)
1514

1615
func AssertSourceEqualStdStream(t *testing.T, expectedPtr **os.File, getSource func() core.DataSource) {
17-
temp, err := ioutil.TempFile("", "")
16+
temp, err := os.CreateTemp("", "")
1817
require.NoError(t, err)
1918

2019
backup := *expectedPtr
@@ -33,7 +32,7 @@ func AssertSourceEqualStdStream(t *testing.T, expectedPtr **os.File, getSource f
3332
require.NoError(t, err, "std stream should not be closed")
3433

3534
_, _ = temp.Seek(0, io.SeekStart)
36-
data, _ := ioutil.ReadAll(temp)
35+
data, _ := io.ReadAll(temp)
3736
assert.Equal(t, testdata, string(data))
3837
}
3938

core/datasource/std.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package datasource
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"strings"
87

98
"github.com/yandex/pandora/core"
@@ -24,7 +23,7 @@ func (b buffer) OpenSource() (wc io.ReadCloser, err error) {
2423
}
2524

2625
// NewReader returns dummy core.DataSource that returns it on OpenSource call, wrapping it
27-
// ioutil.NopCloser if r is not io.Closer.
26+
// io.NopCloser if r is not io.Closer.
2827
// NOTE(skipor): such wrapping hides Seek and other methods that can be used.
2928
func NewReader(r io.Reader) core.DataSource {
3029
return &readerSource{r}
@@ -46,7 +45,7 @@ func (r *readerSource) OpenSource() (rc io.ReadCloser, err error) {
4645
ioutil2.NopCloser
4746
}{ReadSeeker: rs}, nil
4847
}
49-
return ioutil.NopCloser(r.source), nil
48+
return io.NopCloser(r.source), nil
5049
}
5150

5251
func NewString(s string) core.DataSource {

lib/confutil/property_var_resolver_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package confutil
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76

@@ -12,7 +11,7 @@ func TestPropertyTokenResolver(t *testing.T) {
1211
fileContent := []byte(`name=John Doe
1312
age=25
1413
email=johndoe@example.com`)
15-
tmpFile, err := ioutil.TempFile("", "testfile*.txt")
14+
tmpFile, err := os.CreateTemp("", "testfile*.txt")
1615
assert.NoError(t, err)
1716
defer os.Remove(tmpFile.Name())
1817
defer tmpFile.Close()

lib/testutil/afero.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package testutil
22

33
import (
44
"io"
5-
"io/ioutil"
65

76
"github.com/spf13/afero"
87
"github.com/stretchr/testify/assert"
98
"github.com/stretchr/testify/require"
109
)
1110

1211
func ReadString(t TestingT, r io.Reader) string {
13-
data, err := ioutil.ReadAll(r)
12+
data, err := io.ReadAll(r)
1413
require.NoError(t, err)
1514
return string(data)
1615
}

0 commit comments

Comments
 (0)