Skip to content

Commit ccea46c

Browse files
committed
Remove deprecated ioutil package
According to - golang/go#40025 - golang/go#42026 `ioutil` is deprecated, `io` and `os` packages should be used instead.
1 parent 4578a40 commit ccea46c

File tree

22 files changed

+109
-99
lines changed

22 files changed

+109
-99
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ See [examples](https://github.com/h2non/gock/tree/master/_examples) directory fo
125125
package test
126126

127127
import (
128-
"io/ioutil"
128+
"io"
129129
"net/http"
130130
"testing"
131131

@@ -145,7 +145,7 @@ func TestSimple(t *testing.T) {
145145
st.Expect(t, err, nil)
146146
st.Expect(t, res.StatusCode, 200)
147147

148-
body, _ := ioutil.ReadAll(res.Body)
148+
body, _ := io.ReadAll(res.Body)
149149
st.Expect(t, string(body)[:13], `{"foo":"bar"}`)
150150

151151
// Verify that we don't have pending mocks
@@ -159,7 +159,7 @@ func TestSimple(t *testing.T) {
159159
package test
160160

161161
import (
162-
"io/ioutil"
162+
"io"
163163
"net/http"
164164
"testing"
165165

@@ -185,7 +185,7 @@ func TestMatchHeaders(t *testing.T) {
185185
res, err := (&http.Client{}).Do(req)
186186
st.Expect(t, err, nil)
187187
st.Expect(t, res.StatusCode, 200)
188-
body, _ := ioutil.ReadAll(res.Body)
188+
body, _ := io.ReadAll(res.Body)
189189
st.Expect(t, string(body), "foo foo")
190190

191191
// Verify that we don't have pending mocks
@@ -199,7 +199,7 @@ func TestMatchHeaders(t *testing.T) {
199199
package test
200200

201201
import (
202-
"io/ioutil"
202+
"io"
203203
"net/http"
204204
"testing"
205205

@@ -221,7 +221,7 @@ func TestMatchParams(t *testing.T) {
221221
res, err := (&http.Client{}).Do(req)
222222
st.Expect(t, err, nil)
223223
st.Expect(t, res.StatusCode, 200)
224-
body, _ := ioutil.ReadAll(res.Body)
224+
body, _ := io.ReadAll(res.Body)
225225
st.Expect(t, string(body), "foo foo")
226226

227227
// Verify that we don't have pending mocks
@@ -236,7 +236,7 @@ package test
236236

237237
import (
238238
"bytes"
239-
"io/ioutil"
239+
"io"
240240
"net/http"
241241
"testing"
242242

@@ -259,7 +259,7 @@ func TestMockSimple(t *testing.T) {
259259
st.Expect(t, err, nil)
260260
st.Expect(t, res.StatusCode, 201)
261261

262-
resBody, _ := ioutil.ReadAll(res.Body)
262+
resBody, _ := io.ReadAll(res.Body)
263263
st.Expect(t, string(resBody)[:13], `{"bar":"foo"}`)
264264

265265
// Verify that we don't have pending mocks
@@ -273,7 +273,7 @@ func TestMockSimple(t *testing.T) {
273273
package test
274274

275275
import (
276-
"io/ioutil"
276+
"io"
277277
"net/http"
278278
"testing"
279279

@@ -295,7 +295,7 @@ func TestClient(t *testing.T) {
295295
res, err := client.Do(req)
296296
st.Expect(t, err, nil)
297297
st.Expect(t, res.StatusCode, 200)
298-
body, _ := ioutil.ReadAll(res.Body)
298+
body, _ := io.ReadAll(res.Body)
299299
st.Expect(t, string(body), "foo foo")
300300

301301
// Verify that we don't have pending mocks
@@ -310,7 +310,7 @@ package main
310310

311311
import (
312312
"fmt"
313-
"io/ioutil"
313+
"io"
314314
"net/http"
315315

316316
"github.com/h2non/gock"
@@ -336,7 +336,7 @@ func main() {
336336
// The server header comes from mock as well
337337
fmt.Printf("Server header: %s\n", res.Header.Get("Server"))
338338
// Response body is the original
339-
body, _ := ioutil.ReadAll(res.Body)
339+
body, _ := io.ReadAll(res.Body)
340340
fmt.Printf("Body: %s", string(body))
341341
}
342342
```

_examples/basic/basic_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import (
4-
"github.com/nbio/st"
5-
"github.com/h2non/gock"
6-
"io/ioutil"
4+
"io"
75
"net/http"
86
"testing"
7+
8+
"github.com/h2non/gock"
9+
"github.com/nbio/st"
910
)
1011

1112
func TestSimple(t *testing.T) {
@@ -20,7 +21,7 @@ func TestSimple(t *testing.T) {
2021
st.Expect(t, err, nil)
2122
st.Expect(t, res.StatusCode, 200)
2223

23-
body, _ := ioutil.ReadAll(res.Body)
24+
body, _ := io.ReadAll(res.Body)
2425
st.Expect(t, string(body)[:13], `{"foo":"bar"}`)
2526

2627
// Verify that we don't have pending mocks

_examples/body_file/file_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package test
22

33
import (
44
"bytes"
5-
"github.com/nbio/st"
6-
"github.com/h2non/gock"
7-
"io/ioutil"
5+
"io"
86
"net/http"
97
"testing"
8+
9+
"github.com/h2non/gock"
10+
"github.com/nbio/st"
1011
)
1112

1213
func TestMockBodyFile(t *testing.T) {
@@ -24,6 +25,6 @@ func TestMockBodyFile(t *testing.T) {
2425
st.Expect(t, err, nil)
2526
st.Expect(t, res.StatusCode, 201)
2627

27-
resBody, _ := ioutil.ReadAll(res.Body)
28+
resBody, _ := io.ReadAll(res.Body)
2829
st.Expect(t, string(resBody)[:13], `{"bar":"foo"}`)
2930
}

_examples/body_match/body_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package test
22

33
import (
44
"bytes"
5-
"github.com/nbio/st"
6-
"github.com/h2non/gock"
7-
"io/ioutil"
5+
"io"
86
"net/http"
97
"testing"
8+
9+
"github.com/h2non/gock"
10+
"github.com/nbio/st"
1011
)
1112

1213
func TestMockSimple(t *testing.T) {
@@ -24,6 +25,6 @@ func TestMockSimple(t *testing.T) {
2425
st.Expect(t, err, nil)
2526
st.Expect(t, res.StatusCode, 201)
2627

27-
resBody, _ := ioutil.ReadAll(res.Body)
28+
resBody, _ := io.ReadAll(res.Body)
2829
st.Expect(t, string(resBody)[:13], `{"bar":"foo"}`)
2930
}

_examples/compressed_body/compression_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package test
33
import (
44
"bytes"
55
"compress/gzip"
6-
"github.com/nbio/st"
7-
"github.com/h2non/gock"
8-
"io/ioutil"
6+
"io"
97
"net/http"
108
"testing"
9+
10+
"github.com/h2non/gock"
11+
"github.com/nbio/st"
1112
)
1213

1314
func TestMockSimple(t *testing.T) {
@@ -33,6 +34,6 @@ func TestMockSimple(t *testing.T) {
3334
st.Expect(t, err, nil)
3435
st.Expect(t, res.StatusCode, 201)
3536

36-
resBody, _ := ioutil.ReadAll(res.Body)
37+
resBody, _ := io.ReadAll(res.Body)
3738
st.Expect(t, string(resBody)[:13], `{"bar":"foo"}`)
3839
}

_examples/custom_client/client_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import (
4-
"github.com/nbio/st"
5-
"github.com/h2non/gock"
6-
"io/ioutil"
4+
"io"
75
"net/http"
86
"testing"
7+
8+
"github.com/h2non/gock"
9+
"github.com/nbio/st"
910
)
1011

1112
func TestClient(t *testing.T) {
@@ -22,6 +23,6 @@ func TestClient(t *testing.T) {
2223
res, err := client.Do(req)
2324
st.Expect(t, err, nil)
2425
st.Expect(t, res.StatusCode, 200)
25-
body, _ := ioutil.ReadAll(res.Body)
26+
body, _ := io.ReadAll(res.Body)
2627
st.Expect(t, string(body), "foo foo")
2728
}

_examples/match_headers/headers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package test
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
"testing"
77

8-
"github.com/nbio/st"
9-
"github.com/h2non/gock"
8+
"github.com/h2honngockock"
9+
"github.com/ibiosst
1010
)
1111

1212
func TestMatchHeaders(t *testing.T) {
@@ -27,6 +27,6 @@ func TestMatchHeaders(t *testing.T) {
2727
res, err := (&http.Client{}).Do(req)
2828
st.Expect(t, err, nil)
2929
st.Expect(t, res.StatusCode, 200)
30-
body, _ := ioutil.ReadAll(res.Body)
30+
body, _ := io.ReadAll(res.Body)
3131
st.Expect(t, string(body), "foo foo")
3232
}

_examples/match_query/query_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import (
4-
"github.com/nbio/st"
5-
"github.com/h2non/gock"
6-
"io/ioutil"
4+
"io"
75
"net/http"
86
"testing"
7+
8+
"github.com/h2non/gock"
9+
"github.com/nbio/st"
910
)
1011

1112
func TestMatchQueryParams(t *testing.T) {
@@ -22,6 +23,6 @@ func TestMatchQueryParams(t *testing.T) {
2223
res, err := (&http.Client{}).Do(req)
2324
st.Expect(t, err, nil)
2425
st.Expect(t, res.StatusCode, 200)
25-
body, _ := ioutil.ReadAll(res.Body)
26+
body, _ := io.ReadAll(res.Body)
2627
st.Expect(t, string(body), "foo foo")
2728
}

_examples/match_url/url_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import (
4-
"github.com/nbio/st"
5-
"github.com/h2non/gock"
6-
"io/ioutil"
4+
"io"
75
"net/http"
86
"testing"
7+
8+
"github.com/h2non/gock"
9+
"github.com/nbio/st"
910
)
1011

1112
func TestMatchURL(t *testing.T) {
@@ -18,6 +19,6 @@ func TestMatchURL(t *testing.T) {
1819
res, err := http.Get("http://foo.com")
1920
st.Expect(t, err, nil)
2021
st.Expect(t, res.StatusCode, 200)
21-
body, _ := ioutil.ReadAll(res.Body)
22+
body, _ := io.ReadAll(res.Body)
2223
st.Expect(t, string(body), "foo foo")
2324
}

_examples/multiple/multiple_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package test
22

33
import (
4-
"github.com/nbio/st"
5-
"github.com/h2non/gock"
6-
"io/ioutil"
4+
"io"
75
"net/http"
86
"testing"
7+
8+
"github.com/h2non/gock"
9+
"github.com/nbio/st"
910
)
1011

1112
func TestMultipleMocks(t *testing.T) {
@@ -38,7 +39,7 @@ func TestMultipleMocks(t *testing.T) {
3839
res, err := http.Get("http://server.com" + test.path)
3940
st.Expect(t, err, nil)
4041
st.Expect(t, res.StatusCode, 200)
41-
body, _ := ioutil.ReadAll(res.Body)
42+
body, _ := io.ReadAll(res.Body)
4243
st.Expect(t, string(body)[:15], `{"value":"`+test.path[1:]+`"}`)
4344
}
4445

0 commit comments

Comments
 (0)