Skip to content

Commit 3fe59e8

Browse files
committed
rm more uses of ioutil
1 parent d882b57 commit 3fe59e8

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

httphelpers/certificates.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"crypto/x509/pkix"
1111
"encoding/pem"
1212
"fmt"
13-
"io/ioutil"
1413
"log"
1514
"math/big"
1615
"net"
@@ -26,7 +25,7 @@ import (
2625
// function's second and third parameters provide the CA certificate for configuring the client,
2726
// and a preconfigured CertPool in case that is more convenient to use.
2827
func WithSelfSignedServer(handler http.Handler, action func(*httptest.Server, []byte, *x509.CertPool)) {
29-
certFile, err := ioutil.TempFile("", "test")
28+
certFile, err := os.CreateTemp("", "test")
3029
if err != nil {
3130
panic(fmt.Errorf("can't create temp file: %s", err))
3231
}
@@ -39,7 +38,7 @@ func WithSelfSignedServer(handler http.Handler, action func(*httptest.Server, []
3938
}
4039
}
4140
defer tryToDelete(certFilePath)
42-
keyFile, err := ioutil.TempFile("", "test")
41+
keyFile, err := os.CreateTemp("", "test")
4342
if err != nil {
4443
panic(fmt.Errorf("can't create temp file: %s", err))
4544
}
@@ -50,7 +49,7 @@ func WithSelfSignedServer(handler http.Handler, action func(*httptest.Server, []
5049
if err != nil {
5150
panic(fmt.Errorf("can't create self-signed certificate: %s", err))
5251
}
53-
certData, err := ioutil.ReadFile(certFilePath) //nolint:gosec
52+
certData, err := os.ReadFile(certFilePath) //nolint:gosec
5453
if err != nil {
5554
panic(fmt.Errorf("can't read self-signed certificate: %s", err))
5655
}

httphelpers/handlers.go

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

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"io"
66
"log"
77
"net/http"
88
"net/http/httptest"
@@ -19,7 +19,7 @@ func getRequestBody(request *http.Request) []byte {
1919
if request.Body == nil {
2020
return nil
2121
}
22-
body, _ := ioutil.ReadAll(request.Body)
22+
body, _ := io.ReadAll(request.Body)
2323
return body
2424
}
2525

httphelpers/handlers_sse_test.go

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

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
"net/http/httptest"
77
"testing"
@@ -31,7 +31,7 @@ func TestSSEHandler(t *testing.T) {
3131
stream.Enqueue(SSEEvent{"", "event3", "data3", 500})
3232
stream.EndAll()
3333

34-
data, err := ioutil.ReadAll(resp1.Body)
34+
data, err := io.ReadAll(resp1.Body)
3535

3636
assert.NoError(t, err)
3737
assert.Equal(t, `id: id1

httphelpers/handlers_streaming_test.go

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

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
"net/http/httptest"
77
"testing"
@@ -79,7 +79,7 @@ func TestChunkedStreamingHandlerEndAll(t *testing.T) {
7979
}()
8080

8181
// ReadAll won't return until the stream is closed
82-
data, err := ioutil.ReadAll(resp1.Body)
82+
data, err := io.ReadAll(resp1.Body)
8383
require.NoError(t, err)
8484
assert.Equal(t, "hello,goodbye.", string(data))
8585

@@ -91,7 +91,7 @@ func TestChunkedStreamingHandlerEndAll(t *testing.T) {
9191
stream.EndAll()
9292
}()
9393

94-
data, err = ioutil.ReadAll(resp2.Body)
94+
data, err = io.ReadAll(resp2.Body)
9595
require.NoError(t, err)
9696
assert.Equal(t, "hello,", string(data))
9797
})
@@ -112,7 +112,7 @@ func TestChunkedStreamingHandlerClose(t *testing.T) {
112112
stream.Close()
113113
}()
114114

115-
data, err := ioutil.ReadAll(resp1.Body)
115+
data, err := io.ReadAll(resp1.Body)
116116
require.NoError(t, err)
117117
assert.Equal(t, "hello,goodbye.", string(data))
118118

0 commit comments

Comments
 (0)