aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httptest
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-10-16 00:49:02 -0400
committerRuss Cox <rsc@golang.org>2020-10-20 18:41:18 +0000
commit1b09d430678d4a6f73b2443463d11f75851aba8a (patch)
treefec040abfc6e1d897f8dcdbb856e77d5bccbb2ca /src/net/http/httptest
parentcb0a0f52e67f128c6ad69027c9a8c7a5caf58446 (diff)
downloadgo-1b09d430678d4a6f73b2443463d11f75851aba8a.tar.xz
all: update references to symbols moved from io/ioutil to io
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/net/http/httptest')
-rw-r--r--src/net/http/httptest/example_test.go9
-rw-r--r--src/net/http/httptest/httptest.go3
-rw-r--r--src/net/http/httptest/httptest_test.go3
-rw-r--r--src/net/http/httptest/recorder.go4
-rw-r--r--src/net/http/httptest/recorder_test.go3
-rw-r--r--src/net/http/httptest/server_test.go10
6 files changed, 14 insertions, 18 deletions
diff --git a/src/net/http/httptest/example_test.go b/src/net/http/httptest/example_test.go
index 54e77dbb84..a6738432eb 100644
--- a/src/net/http/httptest/example_test.go
+++ b/src/net/http/httptest/example_test.go
@@ -7,7 +7,6 @@ package httptest_test
import (
"fmt"
"io"
- "io/ioutil"
"log"
"net/http"
"net/http/httptest"
@@ -23,7 +22,7 @@ func ExampleResponseRecorder() {
handler(w, req)
resp := w.Result()
- body, _ := ioutil.ReadAll(resp.Body)
+ body, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode)
fmt.Println(resp.Header.Get("Content-Type"))
@@ -45,7 +44,7 @@ func ExampleServer() {
if err != nil {
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
@@ -67,7 +66,7 @@ func ExampleServer_hTTP2() {
if err != nil {
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
@@ -89,7 +88,7 @@ func ExampleNewTLSServer() {
log.Fatal(err)
}
- greeting, err := ioutil.ReadAll(res.Body)
+ greeting, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
diff --git a/src/net/http/httptest/httptest.go b/src/net/http/httptest/httptest.go
index f7202da92f..9bedefd2bc 100644
--- a/src/net/http/httptest/httptest.go
+++ b/src/net/http/httptest/httptest.go
@@ -10,7 +10,6 @@ import (
"bytes"
"crypto/tls"
"io"
- "io/ioutil"
"net/http"
"strings"
)
@@ -66,7 +65,7 @@ func NewRequest(method, target string, body io.Reader) *http.Request {
if rc, ok := body.(io.ReadCloser); ok {
req.Body = rc
} else {
- req.Body = ioutil.NopCloser(body)
+ req.Body = io.NopCloser(body)
}
}
diff --git a/src/net/http/httptest/httptest_test.go b/src/net/http/httptest/httptest_test.go
index ef7d943837..071add67ea 100644
--- a/src/net/http/httptest/httptest_test.go
+++ b/src/net/http/httptest/httptest_test.go
@@ -7,7 +7,6 @@ package httptest
import (
"crypto/tls"
"io"
- "io/ioutil"
"net/http"
"net/url"
"reflect"
@@ -155,7 +154,7 @@ func TestNewRequest(t *testing.T) {
} {
t.Run(tt.name, func(t *testing.T) {
got := NewRequest(tt.method, tt.uri, tt.body)
- slurp, err := ioutil.ReadAll(got.Body)
+ slurp, err := io.ReadAll(got.Body)
if err != nil {
t.Errorf("ReadAll: %v", err)
}
diff --git a/src/net/http/httptest/recorder.go b/src/net/http/httptest/recorder.go
index 66e67e78b3..2428482612 100644
--- a/src/net/http/httptest/recorder.go
+++ b/src/net/http/httptest/recorder.go
@@ -7,7 +7,7 @@ package httptest
import (
"bytes"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/textproto"
"strconv"
@@ -179,7 +179,7 @@ func (rw *ResponseRecorder) Result() *http.Response {
}
res.Status = fmt.Sprintf("%03d %s", res.StatusCode, http.StatusText(res.StatusCode))
if rw.Body != nil {
- res.Body = ioutil.NopCloser(bytes.NewReader(rw.Body.Bytes()))
+ res.Body = io.NopCloser(bytes.NewReader(rw.Body.Bytes()))
} else {
res.Body = http.NoBody
}
diff --git a/src/net/http/httptest/recorder_test.go b/src/net/http/httptest/recorder_test.go
index e9534894b6..a865e878b9 100644
--- a/src/net/http/httptest/recorder_test.go
+++ b/src/net/http/httptest/recorder_test.go
@@ -7,7 +7,6 @@ package httptest
import (
"fmt"
"io"
- "io/ioutil"
"net/http"
"testing"
)
@@ -42,7 +41,7 @@ func TestRecorder(t *testing.T) {
}
hasResultContents := func(want string) checkFunc {
return func(rec *ResponseRecorder) error {
- contentBytes, err := ioutil.ReadAll(rec.Result().Body)
+ contentBytes, err := io.ReadAll(rec.Result().Body)
if err != nil {
return err
}
diff --git a/src/net/http/httptest/server_test.go b/src/net/http/httptest/server_test.go
index 0aad15c5ed..39568b358c 100644
--- a/src/net/http/httptest/server_test.go
+++ b/src/net/http/httptest/server_test.go
@@ -6,7 +6,7 @@ package httptest
import (
"bufio"
- "io/ioutil"
+ "io"
"net"
"net/http"
"testing"
@@ -61,7 +61,7 @@ func testServer(t *testing.T, newServer newServerFunc) {
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
@@ -81,7 +81,7 @@ func testGetAfterClose(t *testing.T, newServer newServerFunc) {
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
@@ -93,7 +93,7 @@ func testGetAfterClose(t *testing.T, newServer newServerFunc) {
res, err = http.Get(ts.URL)
if err == nil {
- body, _ := ioutil.ReadAll(res.Body)
+ body, _ := io.ReadAll(res.Body)
t.Fatalf("Unexpected response after close: %v, %v, %s", res.Status, res.Header, body)
}
}
@@ -152,7 +152,7 @@ func testServerClient(t *testing.T, newTLSServer newServerFunc) {
if err != nil {
t.Fatal(err)
}
- got, err := ioutil.ReadAll(res.Body)
+ got, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)