mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
cb0a0f52e6
commit
1b09d43067
135 changed files with 535 additions and 597 deletions
|
|
@ -7,7 +7,6 @@ package tar
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -104,7 +103,7 @@ func (tr *Reader) next() (*Header, error) {
|
|||
continue // This is a meta header affecting the next header
|
||||
case TypeGNULongName, TypeGNULongLink:
|
||||
format.mayOnlyBe(FormatGNU)
|
||||
realname, err := ioutil.ReadAll(tr)
|
||||
realname, err := io.ReadAll(tr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -294,7 +293,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
|
|||
// parsePAX parses PAX headers.
|
||||
// If an extended header (type 'x') is invalid, ErrHeader is returned
|
||||
func parsePAX(r io.Reader) (map[string]string, error) {
|
||||
buf, err := ioutil.ReadAll(r)
|
||||
buf, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -850,7 +849,7 @@ func discard(r io.Reader, n int64) error {
|
|||
}
|
||||
}
|
||||
|
||||
copySkipped, err := io.CopyN(ioutil.Discard, r, n-seekSkipped)
|
||||
copySkipped, err := io.CopyN(io.Discard, r, n-seekSkipped)
|
||||
if err == io.EOF && seekSkipped+copySkipped < n {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ func TestReadTruncation(t *testing.T) {
|
|||
}
|
||||
cnt++
|
||||
if s2 == "manual" {
|
||||
if _, err = tr.writeTo(ioutil.Discard); err != nil {
|
||||
if _, err = tr.writeTo(io.Discard); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ func TestRoundTrip(t *testing.T) {
|
|||
if !reflect.DeepEqual(rHdr, hdr) {
|
||||
t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
|
||||
}
|
||||
rData, err := ioutil.ReadAll(tr)
|
||||
rData, err := io.ReadAll(tr)
|
||||
if err != nil {
|
||||
t.Fatalf("Read: %v", err)
|
||||
}
|
||||
|
|
@ -805,9 +805,9 @@ func Benchmark(b *testing.B) {
|
|||
b.Run(v.label, func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
// Writing to ioutil.Discard because we want to
|
||||
// Writing to io.Discard because we want to
|
||||
// test purely the writer code and not bring in disk performance into this.
|
||||
tw := NewWriter(ioutil.Discard)
|
||||
tw := NewWriter(io.Discard)
|
||||
for _, file := range v.files {
|
||||
if err := tw.WriteHeader(file.hdr); err != nil {
|
||||
b.Errorf("unexpected WriteHeader error: %v", err)
|
||||
|
|
@ -845,7 +845,7 @@ func Benchmark(b *testing.B) {
|
|||
if _, err := tr.Next(); err != nil {
|
||||
b.Errorf("unexpected Next error: %v", err)
|
||||
}
|
||||
if _, err := io.Copy(ioutil.Discard, tr); err != nil {
|
||||
if _, err := io.Copy(io.Discard, tr); err != nil {
|
||||
b.Errorf("unexpected Copy error : %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -930,7 +930,7 @@ func returnBigZipBytes() (r io.ReaderAt, size int64) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
b, err = ioutil.ReadAll(f)
|
||||
b, err = io.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -987,7 +987,7 @@ func TestIssue10957(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
if f.UncompressedSize64 < 1e6 {
|
||||
n, err := io.Copy(ioutil.Discard, r)
|
||||
n, err := io.Copy(io.Discard, r)
|
||||
if i == 3 && err != io.ErrUnexpectedEOF {
|
||||
t.Errorf("File[3] error = %v; want io.ErrUnexpectedEOF", err)
|
||||
}
|
||||
|
|
@ -1029,7 +1029,7 @@ func TestIssue11146(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = ioutil.ReadAll(r)
|
||||
_, err = io.ReadAll(r)
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
t.Errorf("File[0] error = %v; want io.ErrUnexpectedEOF", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"compress/flate"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
|
@ -111,7 +110,7 @@ func init() {
|
|||
compressors.Store(Store, Compressor(func(w io.Writer) (io.WriteCloser, error) { return &nopCloser{w}, nil }))
|
||||
compressors.Store(Deflate, Compressor(func(w io.Writer) (io.WriteCloser, error) { return newFlateWriter(w), nil }))
|
||||
|
||||
decompressors.Store(Store, Decompressor(ioutil.NopCloser))
|
||||
decompressors.Store(Store, Decompressor(io.NopCloser))
|
||||
decompressors.Store(Deflate, Decompressor(newFlateReader))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ func TestWriterFlush(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriterDir(t *testing.T) {
|
||||
w := NewWriter(ioutil.Discard)
|
||||
w := NewWriter(io.Discard)
|
||||
dw, err := w.Create("dir/")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -380,7 +380,7 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
|
|||
if err != nil {
|
||||
t.Fatal("opening:", err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(rc)
|
||||
b, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
t.Fatal("reading:", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"hash"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -620,7 +619,7 @@ func testZip64(t testing.TB, size int64) *rleBuffer {
|
|||
t.Fatal("read:", err)
|
||||
}
|
||||
}
|
||||
gotEnd, err := ioutil.ReadAll(rc)
|
||||
gotEnd, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
t.Fatal("read end:", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
|
|
@ -886,7 +885,7 @@ func TestReadEmptyBuffer(t *testing.T) {
|
|||
|
||||
func TestLinesAfterRead(t *testing.T) {
|
||||
l := NewReaderSize(bytes.NewReader([]byte("foo")), minReadBufferSize)
|
||||
_, err := ioutil.ReadAll(l)
|
||||
_, err := io.ReadAll(l)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
|
@ -1130,7 +1129,7 @@ func TestWriterReadFromCounts(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// A writeCountingDiscard is like ioutil.Discard and counts the number of times
|
||||
// A writeCountingDiscard is like io.Discard and counts the number of times
|
||||
// Write is called on it.
|
||||
type writeCountingDiscard int
|
||||
|
||||
|
|
@ -1300,7 +1299,7 @@ func TestReaderReset(t *testing.T) {
|
|||
t.Errorf("buf = %q; want foo", buf)
|
||||
}
|
||||
r.Reset(strings.NewReader("bar bar"))
|
||||
all, err := ioutil.ReadAll(r)
|
||||
all, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -1645,13 +1644,13 @@ func BenchmarkReaderWriteToOptimal(b *testing.B) {
|
|||
buf := make([]byte, bufSize)
|
||||
r := bytes.NewReader(buf)
|
||||
srcReader := NewReaderSize(onlyReader{r}, 1<<10)
|
||||
if _, ok := ioutil.Discard.(io.ReaderFrom); !ok {
|
||||
b.Fatal("ioutil.Discard doesn't support ReaderFrom")
|
||||
if _, ok := io.Discard.(io.ReaderFrom); !ok {
|
||||
b.Fatal("io.Discard doesn't support ReaderFrom")
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
r.Seek(0, io.SeekStart)
|
||||
srcReader.Reset(onlyReader{r})
|
||||
n, err := srcReader.WriteTo(ioutil.Discard)
|
||||
n, err := srcReader.WriteTo(io.Discard)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
@ -1722,7 +1721,7 @@ func BenchmarkReaderEmpty(b *testing.B) {
|
|||
str := strings.Repeat("x", 16<<10)
|
||||
for i := 0; i < b.N; i++ {
|
||||
br := NewReader(strings.NewReader(str))
|
||||
n, err := io.Copy(ioutil.Discard, br)
|
||||
n, err := io.Copy(io.Discard, br)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
@ -1737,7 +1736,7 @@ func BenchmarkWriterEmpty(b *testing.B) {
|
|||
str := strings.Repeat("x", 1<<10)
|
||||
bs := []byte(str)
|
||||
for i := 0; i < b.N; i++ {
|
||||
bw := NewWriter(ioutil.Discard)
|
||||
bw := NewWriter(io.Discard)
|
||||
bw.Flush()
|
||||
bw.WriteByte('a')
|
||||
bw.Flush()
|
||||
|
|
@ -1752,7 +1751,7 @@ func BenchmarkWriterEmpty(b *testing.B) {
|
|||
|
||||
func BenchmarkWriterFlush(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
bw := NewWriter(ioutil.Discard)
|
||||
bw := NewWriter(io.Discard)
|
||||
str := strings.Repeat("x", 50)
|
||||
for i := 0; i < b.N; i++ {
|
||||
bw.WriteString(str)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
. "bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -235,7 +234,7 @@ func TestReaderCopyNothing(t *testing.T) {
|
|||
type justWriter struct {
|
||||
io.Writer
|
||||
}
|
||||
discard := justWriter{ioutil.Discard} // hide ReadFrom
|
||||
discard := justWriter{io.Discard} // hide ReadFrom
|
||||
|
||||
var with, withOut nErr
|
||||
with.n, with.err = io.Copy(discard, NewReader(nil))
|
||||
|
|
@ -248,7 +247,7 @@ func TestReaderCopyNothing(t *testing.T) {
|
|||
// tests that Len is affected by reads, but Size is not.
|
||||
func TestReaderLenSize(t *testing.T) {
|
||||
r := NewReader([]byte("abc"))
|
||||
io.CopyN(ioutil.Discard, r, 1)
|
||||
io.CopyN(io.Discard, r, 1)
|
||||
if r.Len() != 2 {
|
||||
t.Errorf("Len = %d; want 2", r.Len())
|
||||
}
|
||||
|
|
@ -268,7 +267,7 @@ func TestReaderReset(t *testing.T) {
|
|||
if err := r.UnreadRune(); err == nil {
|
||||
t.Errorf("UnreadRune: expected error, got nil")
|
||||
}
|
||||
buf, err := ioutil.ReadAll(r)
|
||||
buf, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll: unexpected error: %v", err)
|
||||
}
|
||||
|
|
@ -314,7 +313,7 @@ func TestReaderZero(t *testing.T) {
|
|||
t.Errorf("UnreadRune: got nil, want error")
|
||||
}
|
||||
|
||||
if n, err := (&Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil {
|
||||
if n, err := (&Reader{}).WriteTo(io.Discard); n != 0 || err != nil {
|
||||
t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"go/parser"
|
||||
"go/scanner"
|
||||
"go/token"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -128,7 +129,7 @@ func processFile(filename string, useStdin bool) error {
|
|||
defer f.Close()
|
||||
}
|
||||
|
||||
src, err := ioutil.ReadAll(f)
|
||||
src, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package clean
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -172,7 +173,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
|
|||
f, err := lockedfile.Edit(filepath.Join(dir, "testexpire.txt"))
|
||||
if err == nil {
|
||||
now := time.Now().UnixNano()
|
||||
buf, _ := ioutil.ReadAll(f)
|
||||
buf, _ := io.ReadAll(f)
|
||||
prev, _ := strconv.ParseInt(strings.TrimSpace(string(buf)), 10, 64)
|
||||
if now > prev {
|
||||
if err = f.Truncate(0); err == nil {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -418,7 +419,7 @@ this can exist because the parent directory is deleted
|
|||
t.Errorf("Open(%q): got error %v, want nil", tc.path, err)
|
||||
continue
|
||||
}
|
||||
contents, err := ioutil.ReadAll(f)
|
||||
contents, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error reading contents of file: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ func (r *importReader) readImport(imports *[]string) {
|
|||
r.readString(imports)
|
||||
}
|
||||
|
||||
// ReadComments is like ioutil.ReadAll, except that it only reads the leading
|
||||
// ReadComments is like io.ReadAll, except that it only reads the leading
|
||||
// block of comments in the file.
|
||||
func ReadComments(f io.Reader) ([]byte, error) {
|
||||
r := &importReader{b: bufio.NewReader(f)}
|
||||
|
|
@ -210,7 +210,7 @@ func ReadComments(f io.Reader) ([]byte, error) {
|
|||
return r.buf, r.err
|
||||
}
|
||||
|
||||
// ReadImports is like ioutil.ReadAll, except that it expects a Go file as input
|
||||
// ReadImports is like io.ReadAll, except that it expects a Go file as input
|
||||
// and stops reading the input once the imports have completed.
|
||||
func ReadImports(f io.Reader, reportSyntaxError bool, imports *[]string) ([]byte, error) {
|
||||
r := &importReader{b: bufio.NewReader(f)}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
|
@ -104,7 +103,7 @@ func Read(name string) ([]byte, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
return ioutil.ReadAll(f)
|
||||
return io.ReadAll(f)
|
||||
}
|
||||
|
||||
// Write opens the named file (creating it with the given permissions if needed),
|
||||
|
|
@ -136,7 +135,7 @@ func Transform(name string, t func([]byte) ([]byte, error)) (err error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
old, err := ioutil.ReadAll(f)
|
||||
old, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -832,7 +831,7 @@ func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return ioutil.NopCloser(bytes.NewReader(archive)), nil
|
||||
return io.NopCloser(bytes.NewReader(archive)), nil
|
||||
}
|
||||
|
||||
// ensureGitAttributes makes sure export-subst and export-ignore features are
|
||||
|
|
@ -863,7 +862,7 @@ func ensureGitAttributes(repoDir string) (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
b, err := ioutil.ReadAll(f)
|
||||
b, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
|
@ -433,7 +434,7 @@ func TestReadZip(t *testing.T) {
|
|||
if tt.err != "" {
|
||||
t.Fatalf("ReadZip: no error, wanted %v", tt.err)
|
||||
}
|
||||
zipdata, err := ioutil.ReadAll(rc)
|
||||
zipdata, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -115,7 +116,7 @@ func main() {
|
|||
fmt.Fprintf(os.Stderr, "?%s\n", err)
|
||||
continue
|
||||
}
|
||||
data, err := ioutil.ReadAll(rc)
|
||||
data, err := io.ReadAll(rc)
|
||||
rc.Close()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "?%s\n", err)
|
||||
|
|
|
|||
|
|
@ -1052,7 +1052,7 @@ type dataFile struct {
|
|||
func (f dataFile) Path() string { return f.name }
|
||||
func (f dataFile) Lstat() (fs.FileInfo, error) { return dataFileInfo{f}, nil }
|
||||
func (f dataFile) Open() (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(bytes.NewReader(f.data)), nil
|
||||
return io.NopCloser(bytes.NewReader(f.data)), nil
|
||||
}
|
||||
|
||||
type dataFileInfo struct {
|
||||
|
|
|
|||
|
|
@ -461,7 +461,7 @@ func checkMod(mod module.Version) {
|
|||
// goModSum returns the checksum for the go.mod contents.
|
||||
func goModSum(data []byte) (string, error) {
|
||||
return dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(bytes.NewReader(data)), nil
|
||||
return io.NopCloser(bytes.NewReader(data)), nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"path"
|
||||
pathpkg "path"
|
||||
|
|
@ -305,7 +304,7 @@ func (p *proxyRepo) getBytes(path string) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
defer body.Close()
|
||||
return ioutil.ReadAll(body)
|
||||
return io.ReadAll(body)
|
||||
}
|
||||
|
||||
func (p *proxyRepo) getBody(path string) (io.ReadCloser, error) {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -228,7 +228,7 @@ func (*dbClient) WriteConfig(file string, old, new []byte) error {
|
|||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
data, err := ioutil.ReadAll(f)
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -87,7 +86,7 @@ func GetBytes(u *url.URL) ([]byte, error) {
|
|||
if err := resp.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading %s: %v", u.Redacted(), err)
|
||||
}
|
||||
|
|
@ -130,7 +129,7 @@ func (r *Response) formatErrorDetail() string {
|
|||
}
|
||||
|
||||
// Ensure that r.errorDetail has been populated.
|
||||
_, _ = io.Copy(ioutil.Discard, r.Body)
|
||||
_, _ = io.Copy(io.Discard, r.Body)
|
||||
|
||||
s := r.errorDetail.buf.String()
|
||||
if !utf8.ValidString(s) {
|
||||
|
|
|
|||
|
|
@ -471,13 +471,13 @@ func proxyGoSum(path, vers string) ([]byte, error) {
|
|||
}
|
||||
h1, err := dirhash.Hash1(names, func(name string) (io.ReadCloser, error) {
|
||||
data := files[name]
|
||||
return ioutil.NopCloser(bytes.NewReader(data)), nil
|
||||
return io.NopCloser(bytes.NewReader(data)), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h1mod, err := dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) {
|
||||
return ioutil.NopCloser(bytes.NewReader(gomod)), nil
|
||||
return io.NopCloser(bytes.NewReader(gomod)), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ func TestOddFileContent(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(f)
|
||||
data, err := io.ReadAll(f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
|
|||
perm = fi.Mode().Perm()
|
||||
}
|
||||
|
||||
src, err := ioutil.ReadAll(in)
|
||||
src, err := io.ReadAll(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"crypto/tls"
|
||||
"debug/dwarf"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
|
@ -94,7 +94,7 @@ func getProfile(source string, timeout time.Duration) (*profile.Profile, error)
|
|||
func statusCodeError(resp *http.Response) error {
|
||||
if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
|
||||
// error is from pprof endpoint
|
||||
if body, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||
if body, err := io.ReadAll(resp.Body); err == nil {
|
||||
return fmt.Errorf("server response: %s - %s", resp.Status, body)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"cmd/internal/traceviewer"
|
||||
"context"
|
||||
"internal/trace"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
rtrace "runtime/trace"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -78,7 +78,7 @@ func TestGoroutineCount(t *testing.T) {
|
|||
|
||||
// Use the default viewerDataTraceConsumer but replace
|
||||
// consumeViewerEvent to intercept the ViewerEvents for testing.
|
||||
c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
|
||||
c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
|
||||
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
|
||||
if ev.Name == "Goroutines" {
|
||||
cnt := ev.Arg.(*goroutineCountersArg)
|
||||
|
|
@ -131,7 +131,7 @@ func TestGoroutineFilter(t *testing.T) {
|
|||
gs: map[uint64]bool{10: true},
|
||||
}
|
||||
|
||||
c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
|
||||
c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
|
||||
if err := generateTrace(params, c); err != nil {
|
||||
t.Fatalf("generateTrace failed: %v", err)
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ func TestPreemptedMarkAssist(t *testing.T) {
|
|||
endTime: int64(1<<63 - 1),
|
||||
}
|
||||
|
||||
c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
|
||||
c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
|
||||
|
||||
marks := 0
|
||||
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
|
||||
|
|
@ -214,7 +214,7 @@ func TestFoo(t *testing.T) {
|
|||
tasks: []*taskDesc{task},
|
||||
}
|
||||
|
||||
c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
|
||||
c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
|
||||
|
||||
var logBeforeTaskEnd, logAfterTaskEnd bool
|
||||
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"bytes"
|
||||
"cmd/internal/traceviewer"
|
||||
traceparser "internal/trace"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"runtime"
|
||||
"runtime/trace"
|
||||
"sync"
|
||||
|
|
@ -83,7 +83,7 @@ func TestGoroutineInSyscall(t *testing.T) {
|
|||
|
||||
// Check only one thread for the pipe read goroutine is
|
||||
// considered in-syscall.
|
||||
c := viewerDataTraceConsumer(ioutil.Discard, 0, 1<<63-1)
|
||||
c := viewerDataTraceConsumer(io.Discard, 0, 1<<63-1)
|
||||
c.consumeViewerEvent = func(ev *traceviewer.Event, _ bool) {
|
||||
if ev.Name == "Threads" {
|
||||
arg := ev.Arg.(*threadCountersArg)
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ func TestReader(t *testing.T) {
|
|||
|
||||
for i, v := range vectors {
|
||||
rd := NewReader(bytes.NewReader(v.input))
|
||||
buf, err := ioutil.ReadAll(rd)
|
||||
buf, err := io.ReadAll(rd)
|
||||
|
||||
if fail := bool(err != nil); fail != v.fail {
|
||||
if fail {
|
||||
|
|
@ -220,7 +220,7 @@ var (
|
|||
|
||||
func benchmarkDecode(b *testing.B, compressed []byte) {
|
||||
// Determine the uncompressed size of testfile.
|
||||
uncompressedSize, err := io.Copy(ioutil.Discard, NewReader(bytes.NewReader(compressed)))
|
||||
uncompressedSize, err := io.Copy(io.Discard, NewReader(bytes.NewReader(compressed)))
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ func benchmarkDecode(b *testing.B, compressed []byte) {
|
|||
|
||||
for i := 0; i < b.N; i++ {
|
||||
r := bytes.NewReader(compressed)
|
||||
io.Copy(ioutil.Discard, NewReader(r))
|
||||
io.Copy(io.Discard, NewReader(r))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func TestVeryLongSparseChunk(t *testing.T) {
|
|||
if testing.Short() {
|
||||
t.Skip("skipping sparse chunk during short test")
|
||||
}
|
||||
w, err := NewWriter(ioutil.Discard, 1)
|
||||
w, err := NewWriter(io.Discard, 1)
|
||||
if err != nil {
|
||||
t.Errorf("NewWriter: %v", err)
|
||||
return
|
||||
|
|
@ -294,7 +294,7 @@ func testSync(t *testing.T, level int, input []byte, name string) {
|
|||
|
||||
// stream should work for ordinary reader too
|
||||
r = NewReader(buf1)
|
||||
out, err = ioutil.ReadAll(r)
|
||||
out, err = io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Errorf("testSync: read: %s", err)
|
||||
return
|
||||
|
|
@ -322,7 +322,7 @@ func testToFromWithLevelAndLimit(t *testing.T, level int, input []byte, name str
|
|||
t.Logf("level: %d, size:%.2f%%, %d b\n", level, float64(buffer.Len()*100)/float64(limit), buffer.Len())
|
||||
}
|
||||
r := NewReader(&buffer)
|
||||
out, err := ioutil.ReadAll(r)
|
||||
out, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Errorf("read: %s", err)
|
||||
return
|
||||
|
|
@ -415,7 +415,7 @@ func TestReaderDict(t *testing.T) {
|
|||
w.Close()
|
||||
|
||||
r := NewReaderDict(&b, []byte(dict))
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -456,7 +456,7 @@ func TestRegression2508(t *testing.T) {
|
|||
t.Logf("test disabled with -short")
|
||||
return
|
||||
}
|
||||
w, err := NewWriter(ioutil.Discard, 1)
|
||||
w, err := NewWriter(io.Discard, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("NewWriter: %v", err)
|
||||
}
|
||||
|
|
@ -475,7 +475,7 @@ func TestWriterReset(t *testing.T) {
|
|||
if testing.Short() && level > 1 {
|
||||
break
|
||||
}
|
||||
w, err := NewWriter(ioutil.Discard, level)
|
||||
w, err := NewWriter(io.Discard, level)
|
||||
if err != nil {
|
||||
t.Fatalf("NewWriter: %v", err)
|
||||
}
|
||||
|
|
@ -487,9 +487,9 @@ func TestWriterReset(t *testing.T) {
|
|||
for i := 0; i < n; i++ {
|
||||
w.Write(buf)
|
||||
}
|
||||
w.Reset(ioutil.Discard)
|
||||
w.Reset(io.Discard)
|
||||
|
||||
wref, err := NewWriter(ioutil.Discard, level)
|
||||
wref, err := NewWriter(io.Discard, level)
|
||||
if err != nil {
|
||||
t.Fatalf("NewWriter: %v", err)
|
||||
}
|
||||
|
|
@ -654,7 +654,7 @@ func TestBestSpeed(t *testing.T) {
|
|||
}
|
||||
|
||||
r := NewReader(buf)
|
||||
got, err := ioutil.ReadAll(r)
|
||||
got, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Errorf("i=%d, firstN=%d, flush=%t: ReadAll: %v", i, firstN, flush, err)
|
||||
continue
|
||||
|
|
@ -881,7 +881,7 @@ func TestBestSpeedMaxMatchOffset(t *testing.T) {
|
|||
}
|
||||
|
||||
r := NewReader(buf)
|
||||
dst, err := ioutil.ReadAll(r)
|
||||
dst, err := io.ReadAll(r)
|
||||
r.Close()
|
||||
if err != nil {
|
||||
report("ReadAll: ", err)
|
||||
|
|
@ -968,7 +968,7 @@ func TestMaxStackSize(t *testing.T) {
|
|||
wg.Add(1)
|
||||
go func(level int) {
|
||||
defer wg.Done()
|
||||
zw, err := NewWriter(ioutil.Discard, level)
|
||||
zw, err := NewWriter(io.Discard, level)
|
||||
if err != nil {
|
||||
t.Errorf("level %d, NewWriter() = %v, want nil", level, err)
|
||||
}
|
||||
|
|
@ -978,7 +978,7 @@ func TestMaxStackSize(t *testing.T) {
|
|||
if err := zw.Close(); err != nil {
|
||||
t.Errorf("level %d, Close() = %v, want nil", level, err)
|
||||
}
|
||||
zw.Reset(ioutil.Discard)
|
||||
zw.Reset(io.Discard)
|
||||
}(level)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"bytes"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -243,7 +242,7 @@ func TestStreams(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err = ioutil.ReadAll(NewReader(bytes.NewReader(data)))
|
||||
data, err = io.ReadAll(NewReader(bytes.NewReader(data)))
|
||||
if tc.want == "fail" {
|
||||
if err == nil {
|
||||
t.Errorf("#%d (%s): got nil error, want non-nil", i, tc.desc)
|
||||
|
|
@ -266,7 +265,7 @@ func TestTruncatedStreams(t *testing.T) {
|
|||
|
||||
for i := 0; i < len(data)-1; i++ {
|
||||
r := NewReader(strings.NewReader(data[:i]))
|
||||
_, err := io.Copy(ioutil.Discard, r)
|
||||
_, err := io.Copy(io.Discard, r)
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
t.Errorf("io.Copy(%d) on truncated stream: got %v, want %v", i, err, io.ErrUnexpectedEOF)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package flate
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -57,7 +56,7 @@ func TestReaderTruncated(t *testing.T) {
|
|||
for i, v := range vectors {
|
||||
r := strings.NewReader(v.input)
|
||||
zr := NewReader(r)
|
||||
b, err := ioutil.ReadAll(zr)
|
||||
b, err := io.ReadAll(zr)
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
t.Errorf("test %d, error mismatch: got %v, want io.ErrUnexpectedEOF", i, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
func TestNlitOutOfRange(t *testing.T) {
|
||||
// Trying to decode this bogus flate data, which has a Huffman table
|
||||
// with nlit=288, should not panic.
|
||||
io.Copy(ioutil.Discard, NewReader(strings.NewReader(
|
||||
io.Copy(io.Discard, NewReader(strings.NewReader(
|
||||
"\xfc\xfe\x36\xe7\x5e\x1c\xef\xb3\x55\x58\x77\xb6\x56\xb5\x43\xf4"+
|
||||
"\x6f\xf2\xd2\xe6\x3d\x99\xa0\x85\x8c\x48\xeb\xf8\xda\x83\x04\x2a"+
|
||||
"\x75\xc4\xf8\x0f\x12\x11\xb9\xb4\x4b\x09\xa0\xbe\x8b\x91\x4c")))
|
||||
|
|
@ -54,7 +54,7 @@ func BenchmarkDecode(b *testing.B) {
|
|||
runtime.GC()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1)))
|
||||
io.Copy(io.Discard, NewReader(bytes.NewReader(buf1)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
|
@ -27,14 +26,14 @@ func BenchmarkEncode(b *testing.B) {
|
|||
copy(buf1[i:], buf0)
|
||||
}
|
||||
buf0 = nil
|
||||
w, err := NewWriter(ioutil.Discard, level)
|
||||
w, err := NewWriter(io.Discard, level)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
runtime.GC()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
w.Reset(ioutil.Discard)
|
||||
w.Reset(io.Discard)
|
||||
w.Write(buf1)
|
||||
w.Close()
|
||||
}
|
||||
|
|
@ -96,7 +95,7 @@ func TestWriteError(t *testing.T) {
|
|||
t.Fatal("Level", l, "Expected an error on close")
|
||||
}
|
||||
|
||||
w.Reset(ioutil.Discard)
|
||||
w.Reset(io.Discard)
|
||||
n2, err = w.Write([]byte{1, 2, 3, 4, 5, 6})
|
||||
if err != nil {
|
||||
t.Fatal("Level", l, "Got unexpected error after reset:", err)
|
||||
|
|
@ -206,7 +205,7 @@ func TestDeflateFast_Reset(t *testing.T) {
|
|||
w.Close()
|
||||
|
||||
for ; offset <= 256; offset *= 2 {
|
||||
w, err := NewWriter(ioutil.Discard, level)
|
||||
w, err := NewWriter(io.Discard, level)
|
||||
if err != nil {
|
||||
t.Fatalf("NewWriter: level %d: %v", level, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"compress/flate"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -430,7 +429,7 @@ func TestIssue6550(t *testing.T) {
|
|||
defer gzip.Close()
|
||||
done := make(chan bool, 1)
|
||||
go func() {
|
||||
_, err := io.Copy(ioutil.Discard, gzip)
|
||||
_, err := io.Copy(io.Discard, gzip)
|
||||
if err == nil {
|
||||
t.Errorf("Copy succeeded")
|
||||
} else {
|
||||
|
|
@ -467,7 +466,7 @@ Found:
|
|||
const hello = "hello world\n"
|
||||
|
||||
r.Multistream(false)
|
||||
data, err := ioutil.ReadAll(&r)
|
||||
data, err := io.ReadAll(&r)
|
||||
if string(data) != hello || err != nil {
|
||||
t.Fatalf("first stream = %q, %v, want %q, %v", string(data), err, hello, nil)
|
||||
}
|
||||
|
|
@ -476,7 +475,7 @@ Found:
|
|||
t.Fatalf("second reset: %v", err)
|
||||
}
|
||||
r.Multistream(false)
|
||||
data, err = ioutil.ReadAll(&r)
|
||||
data, err = io.ReadAll(&r)
|
||||
if string(data) != hello || err != nil {
|
||||
t.Fatalf("second stream = %q, %v, want %q, %v", string(data), err, hello, nil)
|
||||
}
|
||||
|
|
@ -507,7 +506,7 @@ func TestTruncatedStreams(t *testing.T) {
|
|||
}
|
||||
continue
|
||||
}
|
||||
_, err = io.Copy(ioutil.Discard, r)
|
||||
_, err = io.Copy(io.Discard, r)
|
||||
if ferr, ok := err.(*flate.ReadError); ok {
|
||||
err = ferr.Err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -29,7 +28,7 @@ func TestEmpty(t *testing.T) {
|
|||
if want := (Header{OS: 255}); !reflect.DeepEqual(r.Header, want) {
|
||||
t.Errorf("Header mismatch:\ngot %#v\nwant %#v", r.Header, want)
|
||||
}
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll: %v", err)
|
||||
}
|
||||
|
|
@ -62,7 +61,7 @@ func TestRoundTrip(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("NewReader: %v", err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll: %v", err)
|
||||
}
|
||||
|
|
@ -147,7 +146,7 @@ func TestLatin1RoundTrip(t *testing.T) {
|
|||
t.Errorf("NewReader: %v", err)
|
||||
continue
|
||||
}
|
||||
_, err = ioutil.ReadAll(r)
|
||||
_, err = io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll: %v", err)
|
||||
continue
|
||||
|
|
@ -217,7 +216,7 @@ func TestConcat(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if string(data) != "hello world\n" || err != nil {
|
||||
t.Fatalf("ReadAll = %q, %v, want %q, nil", data, err, "hello world")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func TestNoLongerSavingPriorExpansions(t *testing.T) {
|
|||
in = append(in, 0x80, 0xff, 0x0f, 0x08)
|
||||
|
||||
r := NewReader(bytes.NewReader(in), LSB, 8)
|
||||
nDecoded, err := io.Copy(ioutil.Discard, r)
|
||||
nDecoded, err := io.Copy(io.Discard, r)
|
||||
if err != nil {
|
||||
t.Fatalf("Copy: %v", err)
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ func BenchmarkDecoder(b *testing.B) {
|
|||
runtime.GC()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1), LSB, 8))
|
||||
io.Copy(io.Discard, NewReader(bytes.NewReader(buf1), LSB, 8))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ func testFile(t *testing.T, fn string, order Order, litWidth int) {
|
|||
defer lzwr.Close()
|
||||
|
||||
// Compare the two.
|
||||
b0, err0 := ioutil.ReadAll(golden)
|
||||
b1, err1 := ioutil.ReadAll(lzwr)
|
||||
b0, err0 := io.ReadAll(golden)
|
||||
b1, err1 := io.ReadAll(lzwr)
|
||||
if err0 != nil {
|
||||
t.Errorf("%s (order=%d litWidth=%d): %v", fn, order, litWidth, err0)
|
||||
return
|
||||
|
|
@ -107,7 +107,7 @@ func TestWriter(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWriterReturnValues(t *testing.T) {
|
||||
w := NewWriter(ioutil.Discard, LSB, 8)
|
||||
w := NewWriter(io.Discard, LSB, 8)
|
||||
n, err := w.Write([]byte("asdf"))
|
||||
if n != 4 || err != nil {
|
||||
t.Errorf("got %d, %v, want 4, nil", n, err)
|
||||
|
|
@ -115,7 +115,7 @@ func TestWriterReturnValues(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSmallLitWidth(t *testing.T) {
|
||||
w := NewWriter(ioutil.Discard, LSB, 2)
|
||||
w := NewWriter(io.Discard, LSB, 2)
|
||||
if _, err := w.Write([]byte{0x03}); err != nil {
|
||||
t.Fatalf("write a byte < 1<<2: %v", err)
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ func BenchmarkEncoder(b *testing.B) {
|
|||
b.Run(fmt.Sprint("1e", e), func(b *testing.B) {
|
||||
b.SetBytes(int64(n))
|
||||
for i := 0; i < b.N; i++ {
|
||||
w := NewWriter(ioutil.Discard, LSB, 8)
|
||||
w := NewWriter(io.Discard, LSB, 8)
|
||||
w.Write(buf1)
|
||||
w.Close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func testFileLevelDict(t *testing.T, fn string, level int, d string) {
|
|||
return
|
||||
}
|
||||
defer golden.Close()
|
||||
b0, err0 := ioutil.ReadAll(golden)
|
||||
b0, err0 := io.ReadAll(golden)
|
||||
if err0 != nil {
|
||||
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err0)
|
||||
return
|
||||
|
|
@ -74,7 +74,7 @@ func testLevelDict(t *testing.T, fn string, b0 []byte, level int, d string) {
|
|||
defer zlibr.Close()
|
||||
|
||||
// Compare the decompressed data.
|
||||
b1, err1 := ioutil.ReadAll(zlibr)
|
||||
b1, err1 := io.ReadAll(zlibr)
|
||||
if err1 != nil {
|
||||
t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err1)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -403,7 +403,7 @@ func testHandshake(t *testing.T, clientConfig, serverConfig *Config) (serverStat
|
|||
}
|
||||
defer cli.Close()
|
||||
clientState = cli.ConnectionState()
|
||||
buf, err := ioutil.ReadAll(cli)
|
||||
buf, err := io.ReadAll(cli)
|
||||
if err != nil {
|
||||
t.Errorf("failed to call cli.Read: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
"fmt"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net"
|
||||
"os"
|
||||
|
|
@ -594,7 +593,7 @@ func TestConnCloseWrite(t *testing.T) {
|
|||
}
|
||||
defer srv.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(srv)
|
||||
data, err := io.ReadAll(srv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -635,7 +634,7 @@ func TestConnCloseWrite(t *testing.T) {
|
|||
return fmt.Errorf("CloseWrite error = %v; want errShutdown", err)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
data, err := io.ReadAll(conn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -698,7 +697,7 @@ func TestWarningAlertFlood(t *testing.T) {
|
|||
}
|
||||
defer srv.Close()
|
||||
|
||||
_, err = ioutil.ReadAll(srv)
|
||||
_, err = io.ReadAll(srv)
|
||||
if err == nil {
|
||||
return errors.New("unexpected lack of error from server")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
der, err := ioutil.ReadAll(tr)
|
||||
der, err := io.ReadAll(tr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"compress/gzip"
|
||||
"debug/elf"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -287,7 +288,7 @@ func Test115PclnParsing(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
var dat []byte
|
||||
dat, err = ioutil.ReadAll(gzReader)
|
||||
dat, err = io.ReadAll(gzReader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package ascii85
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -118,7 +117,7 @@ func TestDecode(t *testing.T) {
|
|||
func TestDecoder(t *testing.T) {
|
||||
for _, p := range pairs {
|
||||
decoder := NewDecoder(strings.NewReader(p.encoded))
|
||||
dbuf, err := ioutil.ReadAll(decoder)
|
||||
dbuf, err := io.ReadAll(decoder)
|
||||
if err != nil {
|
||||
t.Fatal("Read failed", err)
|
||||
}
|
||||
|
|
@ -187,7 +186,7 @@ func TestBig(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Encoder.Close() = %v want nil", err)
|
||||
}
|
||||
decoded, err := ioutil.ReadAll(NewDecoder(encoded))
|
||||
decoded, err := io.ReadAll(NewDecoder(encoded))
|
||||
if err != nil {
|
||||
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
|
||||
}
|
||||
|
|
@ -205,7 +204,7 @@ func TestBig(t *testing.T) {
|
|||
|
||||
func TestDecoderInternalWhitespace(t *testing.T) {
|
||||
s := strings.Repeat(" ", 2048) + "z"
|
||||
decoded, err := ioutil.ReadAll(NewDecoder(strings.NewReader(s)))
|
||||
decoded, err := io.ReadAll(NewDecoder(strings.NewReader(s)))
|
||||
if err != nil {
|
||||
t.Errorf("Decode gave error %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -361,9 +360,9 @@ func TestBig(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Encoder.Close() = %v want nil", err)
|
||||
}
|
||||
decoded, err := ioutil.ReadAll(NewDecoder(StdEncoding, encoded))
|
||||
decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded))
|
||||
if err != nil {
|
||||
t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
|
||||
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(raw, decoded) {
|
||||
|
|
@ -428,14 +427,14 @@ LNEBUWIIDFON2CA3DBMJXXE5LNFY==
|
|||
encodedShort := strings.ReplaceAll(encoded, "\n", "")
|
||||
|
||||
dec := NewDecoder(StdEncoding, strings.NewReader(encoded))
|
||||
res1, err := ioutil.ReadAll(dec)
|
||||
res1, err := io.ReadAll(dec)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll failed: %v", err)
|
||||
}
|
||||
|
||||
dec = NewDecoder(StdEncoding, strings.NewReader(encodedShort))
|
||||
var res2 []byte
|
||||
res2, err = ioutil.ReadAll(dec)
|
||||
res2, err = io.ReadAll(dec)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll failed: %v", err)
|
||||
}
|
||||
|
|
@ -619,7 +618,7 @@ func TestBufferedDecodingSameError(t *testing.T) {
|
|||
}()
|
||||
|
||||
decoder := NewDecoder(StdEncoding, pr)
|
||||
_, err := ioutil.ReadAll(decoder)
|
||||
_, err := io.ReadAll(decoder)
|
||||
|
||||
if err != testcase.expected {
|
||||
t.Errorf("Expected %v, got %v; case %s %+v", testcase.expected, err, testcase.prefix, chunks)
|
||||
|
|
@ -718,7 +717,7 @@ func TestDecodeReadAll(t *testing.T) {
|
|||
encoded = strings.ReplaceAll(encoded, "=", "")
|
||||
}
|
||||
|
||||
decReader, err := ioutil.ReadAll(NewDecoder(encoding, strings.NewReader(encoded)))
|
||||
decReader, err := io.ReadAll(NewDecoder(encoding, strings.NewReader(encoded)))
|
||||
if err != nil {
|
||||
t.Errorf("NewDecoder error: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
|
@ -324,9 +323,9 @@ func TestBig(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Encoder.Close() = %v want nil", err)
|
||||
}
|
||||
decoded, err := ioutil.ReadAll(NewDecoder(StdEncoding, encoded))
|
||||
decoded, err := io.ReadAll(NewDecoder(StdEncoding, encoded))
|
||||
if err != nil {
|
||||
t.Fatalf("ioutil.ReadAll(NewDecoder(...)): %v", err)
|
||||
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(raw, decoded) {
|
||||
|
|
@ -403,7 +402,7 @@ func TestDecoderIssue3577(t *testing.T) {
|
|||
})
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ioutil.ReadAll(d)
|
||||
_, err := io.ReadAll(d)
|
||||
errc <- err
|
||||
}()
|
||||
select {
|
||||
|
|
@ -436,14 +435,14 @@ bqbPb06551Y4
|
|||
encodedShort := strings.ReplaceAll(encoded, "\n", "")
|
||||
|
||||
dec := NewDecoder(StdEncoding, strings.NewReader(encoded))
|
||||
res1, err := ioutil.ReadAll(dec)
|
||||
res1, err := io.ReadAll(dec)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll failed: %v", err)
|
||||
}
|
||||
|
||||
dec = NewDecoder(StdEncoding, strings.NewReader(encodedShort))
|
||||
var res2 []byte
|
||||
res2, err = ioutil.ReadAll(dec)
|
||||
res2, err = io.ReadAll(dec)
|
||||
if err != nil {
|
||||
t.Errorf("ReadAll failed: %v", err)
|
||||
}
|
||||
|
|
@ -517,14 +516,14 @@ func TestDecoderRaw(t *testing.T) {
|
|||
|
||||
// Through reader. Used to fail.
|
||||
r := NewDecoder(RawURLEncoding, bytes.NewReader([]byte(source)))
|
||||
dec2, err := ioutil.ReadAll(io.LimitReader(r, 100))
|
||||
dec2, err := io.ReadAll(io.LimitReader(r, 100))
|
||||
if err != nil || !bytes.Equal(dec2, want) {
|
||||
t.Errorf("reading NewDecoder(RawURLEncoding, %q) = %x, %v, want %x, nil", source, dec2, err, want)
|
||||
}
|
||||
|
||||
// Should work with padding.
|
||||
r = NewDecoder(URLEncoding, bytes.NewReader([]byte(source+"==")))
|
||||
dec3, err := ioutil.ReadAll(r)
|
||||
dec3, err := io.ReadAll(r)
|
||||
if err != nil || !bytes.Equal(dec3, want) {
|
||||
t.Errorf("reading NewDecoder(URLEncoding, %q) = %x, %v, want %x, nil", source+"==", dec3, err, want)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
|
@ -524,7 +523,7 @@ func BenchmarkWriteStruct(b *testing.B) {
|
|||
b.SetBytes(int64(Size(&s)))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Write(ioutil.Discard, BigEndian, &s)
|
||||
Write(io.Discard, BigEndian, &s)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -938,7 +938,7 @@ func encodeAndRecover(value interface{}) (encodeErr, panicErr error) {
|
|||
}
|
||||
}()
|
||||
|
||||
encodeErr = NewEncoder(ioutil.Discard).Encode(value)
|
||||
encodeErr = NewEncoder(io.Discard).Encode(value)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -150,7 +149,7 @@ func TestEncoderDecoder(t *testing.T) {
|
|||
func TestDecoderErr(t *testing.T) {
|
||||
for _, tt := range errTests {
|
||||
dec := NewDecoder(strings.NewReader(tt.in))
|
||||
out, err := ioutil.ReadAll(dec)
|
||||
out, err := io.ReadAll(dec)
|
||||
wantErr := tt.err
|
||||
// Decoder is reading from stream, so it reports io.ErrUnexpectedEOF instead of ErrLength.
|
||||
if wantErr == ErrLength {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"compress/gzip"
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
|
|
@ -52,7 +52,7 @@ func codeInit() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(gz)
|
||||
data, err := io.ReadAll(gz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func BenchmarkCodeEncoder(b *testing.B) {
|
|||
b.StartTimer()
|
||||
}
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
enc := NewEncoder(ioutil.Discard)
|
||||
enc := NewEncoder(io.Discard)
|
||||
for pb.Next() {
|
||||
if err := enc.Encode(&codeStruct); err != nil {
|
||||
b.Fatal("Encode:", err)
|
||||
|
|
@ -399,7 +399,7 @@ func BenchmarkEncodeMarshaler(b *testing.B) {
|
|||
}{}
|
||||
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
enc := NewEncoder(ioutil.Discard)
|
||||
enc := NewEncoder(io.Discard)
|
||||
|
||||
for pb.Next() {
|
||||
if err := enc.Encode(&m); err != nil {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package json
|
|||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -215,7 +214,7 @@ func TestDecoderBuffered(t *testing.T) {
|
|||
if m.Name != "Gopher" {
|
||||
t.Errorf("Name = %q; want Gopher", m.Name)
|
||||
}
|
||||
rest, err := ioutil.ReadAll(d.Buffered())
|
||||
rest, err := io.ReadAll(d.Buffered())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -318,7 +317,7 @@ func BenchmarkEncoderEncode(b *testing.B) {
|
|||
v := &T{"foo", "bar"}
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if err := NewEncoder(ioutil.Discard).Encode(v); err != nil {
|
||||
if err := NewEncoder(io.Discard).Encode(v); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package pem
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -271,7 +271,7 @@ func BenchmarkEncode(b *testing.B) {
|
|||
data := &Block{Bytes: make([]byte, 65536)}
|
||||
b.SetBytes(int64(len(data.Bytes)))
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, data)
|
||||
Encode(io.Discard, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"internal/testenv"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
|
@ -545,7 +544,7 @@ func TestGetters(t *testing.T) {
|
|||
func TestParseError(t *testing.T) {
|
||||
for _, typ := range []string{"bool", "int", "int64", "uint", "uint64", "float64", "duration"} {
|
||||
fs := NewFlagSet("parse error test", ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.SetOutput(io.Discard)
|
||||
_ = fs.Bool("bool", false, "")
|
||||
_ = fs.Int("int", 0, "")
|
||||
_ = fs.Int64("int64", 0, "")
|
||||
|
|
@ -576,7 +575,7 @@ func TestRangeError(t *testing.T) {
|
|||
}
|
||||
for _, arg := range bad {
|
||||
fs := NewFlagSet("parse error test", ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
fs.SetOutput(io.Discard)
|
||||
_ = fs.Int("int", 0, "")
|
||||
_ = fs.Int64("int64", 0, "")
|
||||
_ = fs.Uint("uint", 0, "")
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) Impo
|
|||
// Excluded for now: Standard gccgo doesn't support this import format currently.
|
||||
// case goimporterMagic:
|
||||
// var data []byte
|
||||
// data, err = ioutil.ReadAll(reader)
|
||||
// data, err = io.ReadAll(reader)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"go/token"
|
||||
"go/types"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -147,7 +146,7 @@ func Import(fset *token.FileSet, packages map[string]*types.Package, path, srcDi
|
|||
|
||||
case "$$B\n":
|
||||
var data []byte
|
||||
data, err = ioutil.ReadAll(buf)
|
||||
data, err = io.ReadAll(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func readSource(filename string, src interface{}) ([]byte, error) {
|
|||
return s.Bytes(), nil
|
||||
}
|
||||
case io.Reader:
|
||||
return ioutil.ReadAll(s)
|
||||
return io.ReadAll(s)
|
||||
}
|
||||
return nil, errors.New("invalid source")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,6 @@ func BenchmarkPrint(b *testing.B) {
|
|||
initialize()
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
testprint(ioutil.Discard, testfile)
|
||||
testprint(io.Discard, testfile)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ import (
|
|||
"go/scanner"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
|
@ -191,7 +191,7 @@ func parse(filename string, src interface{}) (*ast.File, error) {
|
|||
}
|
||||
|
||||
func parseStdin() (*ast.File, error) {
|
||||
src, err := ioutil.ReadAll(os.Stdin)
|
||||
src, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -171,7 +171,7 @@ func TestCloneThenParse(t *testing.T) {
|
|||
t.Error("adding a template to a clone added it to the original")
|
||||
}
|
||||
// double check that the embedded template isn't available in the original
|
||||
err := t0.ExecuteTemplate(ioutil.Discard, "a", nil)
|
||||
err := t0.ExecuteTemplate(io.Discard, "a", nil)
|
||||
if err == nil {
|
||||
t.Error("expected 'no such template' error")
|
||||
}
|
||||
|
|
@ -185,13 +185,13 @@ func TestFuncMapWorksAfterClone(t *testing.T) {
|
|||
|
||||
// get the expected error output (no clone)
|
||||
uncloned := Must(New("").Funcs(funcs).Parse("{{customFunc}}"))
|
||||
wantErr := uncloned.Execute(ioutil.Discard, nil)
|
||||
wantErr := uncloned.Execute(io.Discard, nil)
|
||||
|
||||
// toClone must be the same as uncloned. It has to be recreated from scratch,
|
||||
// since cloning cannot occur after execution.
|
||||
toClone := Must(New("").Funcs(funcs).Parse("{{customFunc}}"))
|
||||
cloned := Must(toClone.Clone())
|
||||
gotErr := cloned.Execute(ioutil.Discard, nil)
|
||||
gotErr := cloned.Execute(io.Discard, nil)
|
||||
|
||||
if wantErr.Error() != gotErr.Error() {
|
||||
t.Errorf("clone error message mismatch want %q got %q", wantErr, gotErr)
|
||||
|
|
@ -213,7 +213,7 @@ func TestTemplateCloneExecuteRace(t *testing.T) {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < 100; i++ {
|
||||
if err := tmpl.Execute(ioutil.Discard, "data"); err != nil {
|
||||
if err := tmpl.Execute(io.Discard, "data"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ func TestCloneGrowth(t *testing.T) {
|
|||
tmpl = Must(tmpl.Clone())
|
||||
Must(tmpl.Parse(`{{define "B"}}Text{{end}}`))
|
||||
for i := 0; i < 10; i++ {
|
||||
tmpl.Execute(ioutil.Discard, nil)
|
||||
tmpl.Execute(io.Discard, nil)
|
||||
}
|
||||
if len(tmpl.DefinedTemplates()) > 200 {
|
||||
t.Fatalf("too many templates: %v", len(tmpl.DefinedTemplates()))
|
||||
|
|
@ -257,7 +257,7 @@ func TestCloneRedefinedName(t *testing.T) {
|
|||
for i := 0; i < 2; i++ {
|
||||
t2 := Must(t1.Clone())
|
||||
t2 = Must(t2.New(fmt.Sprintf("%d", i)).Parse(page))
|
||||
err := t2.Execute(ioutil.Discard, nil)
|
||||
err := t2.Execute(io.Discard, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -1335,7 +1335,7 @@ func TestExecuteGivesExecError(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = tmpl.Execute(ioutil.Discard, 0)
|
||||
err = tmpl.Execute(io.Discard, 0)
|
||||
if err == nil {
|
||||
t.Fatal("expected error; got none")
|
||||
}
|
||||
|
|
@ -1481,7 +1481,7 @@ func TestEvalFieldErrors(t *testing.T) {
|
|||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
tmpl := Must(New("tmpl").Parse(tc.src))
|
||||
err := tmpl.Execute(ioutil.Discard, tc.value)
|
||||
err := tmpl.Execute(io.Discard, tc.value)
|
||||
got := "<nil>"
|
||||
if err != nil {
|
||||
got = err.Error()
|
||||
|
|
@ -1498,7 +1498,7 @@ func TestMaxExecDepth(t *testing.T) {
|
|||
t.Skip("skipping in -short mode")
|
||||
}
|
||||
tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`))
|
||||
err := tmpl.Execute(ioutil.Discard, nil)
|
||||
err := tmpl.Execute(io.Discard, nil)
|
||||
got := "<nil>"
|
||||
if err != nil {
|
||||
got = err.Error()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"image/color/palette"
|
||||
"image/draw"
|
||||
_ "image/png"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"reflect"
|
||||
|
|
@ -285,7 +285,7 @@ func TestEncodeMismatchDelay(t *testing.T) {
|
|||
Image: images,
|
||||
Delay: make([]int, 1),
|
||||
}
|
||||
if err := EncodeAll(ioutil.Discard, g0); err == nil {
|
||||
if err := EncodeAll(io.Discard, g0); err == nil {
|
||||
t.Error("expected error from mismatched delay and image slice lengths")
|
||||
}
|
||||
|
||||
|
|
@ -297,13 +297,13 @@ func TestEncodeMismatchDelay(t *testing.T) {
|
|||
for i := range g1.Disposal {
|
||||
g1.Disposal[i] = DisposalNone
|
||||
}
|
||||
if err := EncodeAll(ioutil.Discard, g1); err == nil {
|
||||
if err := EncodeAll(io.Discard, g1); err == nil {
|
||||
t.Error("expected error from mismatched disposal and image slice lengths")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeZeroGIF(t *testing.T) {
|
||||
if err := EncodeAll(ioutil.Discard, &GIF{}); err == nil {
|
||||
if err := EncodeAll(io.Discard, &GIF{}); err == nil {
|
||||
t.Error("expected error from providing empty gif")
|
||||
}
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ func TestEncodeAllFramesOutOfBounds(t *testing.T) {
|
|||
Height: upperBound,
|
||||
},
|
||||
}
|
||||
err := EncodeAll(ioutil.Discard, g)
|
||||
err := EncodeAll(io.Discard, g)
|
||||
if upperBound >= 8 {
|
||||
if err != nil {
|
||||
t.Errorf("upperBound=%d: %v", upperBound, err)
|
||||
|
|
@ -430,7 +430,7 @@ func TestEncodeImplicitConfigSize(t *testing.T) {
|
|||
Image: images,
|
||||
Delay: make([]int, len(images)),
|
||||
}
|
||||
err := EncodeAll(ioutil.Discard, g)
|
||||
err := EncodeAll(io.Discard, g)
|
||||
if lowerBound >= 0 {
|
||||
if err != nil {
|
||||
t.Errorf("lowerBound=%d: %v", lowerBound, err)
|
||||
|
|
@ -509,7 +509,7 @@ func TestEncodeBadPalettes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
err := EncodeAll(ioutil.Discard, &GIF{
|
||||
err := EncodeAll(io.Discard, &GIF{
|
||||
Image: []*image.Paletted{
|
||||
image.NewPaletted(image.Rect(0, 0, w, h), pal),
|
||||
},
|
||||
|
|
@ -668,7 +668,7 @@ func BenchmarkEncodeRandomPaletted(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, paletted, nil)
|
||||
Encode(io.Discard, paletted, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -691,7 +691,7 @@ func BenchmarkEncodeRandomRGBA(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, rgba, nil)
|
||||
Encode(io.Discard, rgba, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -708,7 +708,7 @@ func BenchmarkEncodeRealisticPaletted(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, paletted, nil)
|
||||
Encode(io.Discard, paletted, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -729,6 +729,6 @@ func BenchmarkEncodeRealisticRGBA(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, rgba, nil)
|
||||
Encode(io.Discard, rgba, nil)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
|
|
@ -261,7 +261,7 @@ func BenchmarkEncodeRGBA(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
options := &Options{Quality: 90}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img, options)
|
||||
Encode(io.Discard, img, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -283,6 +283,6 @@ func BenchmarkEncodeYCbCr(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
options := &Options{Quality: 90}
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img, options)
|
||||
Encode(io.Discard, img, options)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -169,7 +168,7 @@ func TestWriterPaletted(t *testing.T) {
|
|||
t.Error(err)
|
||||
return
|
||||
}
|
||||
n, err := io.Copy(ioutil.Discard, r)
|
||||
n, err := io.Copy(io.Discard, r)
|
||||
if err != nil {
|
||||
t.Errorf("got error while reading image data: %v", err)
|
||||
}
|
||||
|
|
@ -234,7 +233,7 @@ func BenchmarkEncodeGray(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -259,7 +258,7 @@ func BenchmarkEncodeGrayWithBufferPool(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
e.Encode(ioutil.Discard, img)
|
||||
e.Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +278,7 @@ func BenchmarkEncodeNRGBOpaque(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +291,7 @@ func BenchmarkEncodeNRGBA(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +304,7 @@ func BenchmarkEncodePaletted(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -325,7 +324,7 @@ func BenchmarkEncodeRGBOpaque(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,6 +337,6 @@ func BenchmarkEncodeRGBA(b *testing.B) {
|
|||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Encode(ioutil.Discard, img)
|
||||
Encode(io.Discard, img)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,5 +47,5 @@ func ReadFile(name string) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
return ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
|
||||
return io.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -125,7 +124,7 @@ type Function struct {
|
|||
// may be a gzip-compressed encoded protobuf or one of many legacy
|
||||
// profile formats which may be unsupported in the future.
|
||||
func Parse(r io.Reader) (*Profile, error) {
|
||||
orig, err := ioutil.ReadAll(r)
|
||||
orig, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -136,7 +135,7 @@ func Parse(r io.Reader) (*Profile, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("decompressing profile: %v", err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(gz)
|
||||
data, err := io.ReadAll(gz)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decompressing profile: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -141,7 +140,7 @@ func ExampleTeeReader() {
|
|||
r = io.TeeReader(r, os.Stdout)
|
||||
|
||||
// Everything read from r will be copied to stdout.
|
||||
ioutil.ReadAll(r)
|
||||
io.ReadAll(r)
|
||||
|
||||
// Output:
|
||||
// some io.Reader stream to be read
|
||||
|
|
@ -245,7 +244,7 @@ func ExamplePipe() {
|
|||
func ExampleReadAll() {
|
||||
r := strings.NewReader("Go is a general-purpose language designed with systems programming in mind.")
|
||||
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ var Discard Writer = discard{}
|
|||
type discard struct{}
|
||||
|
||||
// discard implements ReaderFrom as an optimization so Copy to
|
||||
// ioutil.Discard can avoid doing unnecessary work.
|
||||
// io.Discard can avoid doing unnecessary work.
|
||||
var _ ReaderFrom = discard{}
|
||||
|
||||
func (discard) Write(p []byte) (int, error) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
. "io"
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -142,7 +141,7 @@ func testMultiWriter(t *testing.T, sink interface {
|
|||
}
|
||||
}
|
||||
|
||||
// writerFunc is an io.Writer implemented by the underlying func.
|
||||
// writerFunc is an Writer implemented by the underlying func.
|
||||
type writerFunc func(p []byte) (int, error)
|
||||
|
||||
func (f writerFunc) Write(p []byte) (int, error) {
|
||||
|
|
@ -196,7 +195,7 @@ func TestMultiReaderCopy(t *testing.T) {
|
|||
slice := []Reader{strings.NewReader("hello world")}
|
||||
r := MultiReader(slice...)
|
||||
slice[0] = nil
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := ReadAll(r)
|
||||
if err != nil || string(data) != "hello world" {
|
||||
t.Errorf("ReadAll() = %q, %v, want %q, nil", data, err, "hello world")
|
||||
}
|
||||
|
|
@ -217,7 +216,7 @@ func TestMultiWriterCopy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// readerFunc is an io.Reader implemented by the underlying func.
|
||||
// readerFunc is an Reader implemented by the underlying func.
|
||||
type readerFunc func(p []byte) (int, error)
|
||||
|
||||
func (f readerFunc) Read(p []byte) (int, error) {
|
||||
|
|
@ -261,7 +260,7 @@ func TestMultiReaderFlatten(t *testing.T) {
|
|||
}
|
||||
|
||||
// byteAndEOFReader is a Reader which reads one byte (the underlying
|
||||
// byte) and io.EOF at once in its Read call.
|
||||
// byte) and EOF at once in its Read call.
|
||||
type byteAndEOFReader byte
|
||||
|
||||
func (b byteAndEOFReader) Read(p []byte) (n int, err error) {
|
||||
|
|
@ -276,7 +275,7 @@ func (b byteAndEOFReader) Read(p []byte) (n int, err error) {
|
|||
|
||||
// This used to yield bytes forever; issue 16795.
|
||||
func TestMultiReaderSingleByteWithEOF(t *testing.T) {
|
||||
got, err := ioutil.ReadAll(LimitReader(MultiReader(byteAndEOFReader('a'), byteAndEOFReader('b')), 10))
|
||||
got, err := ReadAll(LimitReader(MultiReader(byteAndEOFReader('a'), byteAndEOFReader('b')), 10))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package mime
|
|||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -182,7 +181,7 @@ func TestCharsetDecoder(t *testing.T) {
|
|||
if charset != test.charsets[i] {
|
||||
t.Errorf("DecodeHeader(%q), got charset %q, want %q", test.src, charset, test.charsets[i])
|
||||
}
|
||||
content, err := ioutil.ReadAll(input)
|
||||
content, err := io.ReadAll(input)
|
||||
if err != nil {
|
||||
t.Errorf("DecodeHeader(%q), error in reader: %v", test.src, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
)
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ func ExampleWordDecoder_Decode() {
|
|||
// Fake character set for example.
|
||||
// Real use would integrate with packages such
|
||||
// as code.google.com/p/go-charset
|
||||
content, err := ioutil.ReadAll(input)
|
||||
content, err := io.ReadAll(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -77,7 +76,7 @@ func ExampleWordDecoder_DecodeHeader() {
|
|||
// Fake character set for example.
|
||||
// Real use would integrate with packages such
|
||||
// as code.google.com/p/go-charset
|
||||
content, err := ioutil.ReadAll(input)
|
||||
content, err := io.ReadAll(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package multipart_test
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
|
|
@ -39,7 +38,7 @@ func ExampleNewReader() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(p)
|
||||
slurp, err := io.ReadAll(p)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/quotedprintable"
|
||||
"net/textproto"
|
||||
|
|
@ -278,7 +277,7 @@ func matchAfterPrefix(buf, prefix []byte, readErr error) int {
|
|||
}
|
||||
|
||||
func (p *Part) Close() error {
|
||||
io.Copy(ioutil.Discard, p)
|
||||
io.Copy(io.Discard, p)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"reflect"
|
||||
|
|
@ -307,7 +306,7 @@ Oh no, premature EOF!
|
|||
if err != nil {
|
||||
t.Fatalf("didn't get a part")
|
||||
}
|
||||
_, err = io.Copy(ioutil.Discard, part)
|
||||
_, err = io.Copy(io.Discard, part)
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
t.Fatalf("expected error io.ErrUnexpectedEOF; got %v", err)
|
||||
}
|
||||
|
|
@ -372,7 +371,7 @@ Body 2
|
|||
if !reflect.DeepEqual(part.Header, hdr) {
|
||||
t.Errorf("Part %d: part.Header = %v, want %v", i, part.Header, hdr)
|
||||
}
|
||||
data, err := ioutil.ReadAll(part)
|
||||
data, err := io.ReadAll(part)
|
||||
expectEq(t, body, string(data), fmt.Sprintf("Part %d body", i))
|
||||
if err != nil {
|
||||
t.Fatalf("Part %d: ReadAll failed: %v", i, err)
|
||||
|
|
@ -530,14 +529,14 @@ func TestNested(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("reading text/plain part: %v", err)
|
||||
}
|
||||
if b, err := ioutil.ReadAll(p); string(b) != "*body*\r\n" || err != nil {
|
||||
if b, err := io.ReadAll(p); string(b) != "*body*\r\n" || err != nil {
|
||||
t.Fatalf("reading text/plain part: got %q, %v", b, err)
|
||||
}
|
||||
p, err = mr2.NextPart()
|
||||
if err != nil {
|
||||
t.Fatalf("reading text/html part: %v", err)
|
||||
}
|
||||
if b, err := ioutil.ReadAll(p); string(b) != "<b>body</b>\r\n" || err != nil {
|
||||
if b, err := io.ReadAll(p); string(b) != "<b>body</b>\r\n" || err != nil {
|
||||
t.Fatalf("reading text/html part: got %q, %v", b, err)
|
||||
}
|
||||
|
||||
|
|
@ -850,7 +849,7 @@ Cases:
|
|||
t.Errorf("in test %q, NextPart: %v", tt.name, err)
|
||||
continue Cases
|
||||
}
|
||||
pbody, err := ioutil.ReadAll(p)
|
||||
pbody, err := io.ReadAll(p)
|
||||
if err != nil {
|
||||
t.Errorf("in test %q, error reading part: %v", tt.name, err)
|
||||
continue Cases
|
||||
|
|
@ -882,7 +881,7 @@ func partsFromReader(r *Reader) ([]headerBody, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("NextPart: %v", err)
|
||||
}
|
||||
pbody, err := ioutil.ReadAll(p)
|
||||
pbody, err := io.ReadAll(p)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading part: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package multipart
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"mime"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
|
|
@ -51,7 +51,7 @@ func TestWriter(t *testing.T) {
|
|||
if g, e := part.FormName(), "myfile"; g != e {
|
||||
t.Errorf("part 1: want form name %q, got %q", e, g)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(part)
|
||||
slurp, err := io.ReadAll(part)
|
||||
if err != nil {
|
||||
t.Fatalf("part 1: ReadAll: %v", err)
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ func TestWriter(t *testing.T) {
|
|||
if g, e := part.FormName(), "key"; g != e {
|
||||
t.Errorf("part 2: want form name %q, got %q", e, g)
|
||||
}
|
||||
slurp, err = ioutil.ReadAll(part)
|
||||
slurp, err = io.ReadAll(part)
|
||||
if err != nil {
|
||||
t.Fatalf("part 2: ReadAll: %v", err)
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ func TestWriterBoundaryGoroutines(t *testing.T) {
|
|||
// different goroutines. This was previously broken by
|
||||
// https://codereview.appspot.com/95760043/ and reverted in
|
||||
// https://codereview.appspot.com/117600043/
|
||||
w := NewWriter(ioutil.Discard)
|
||||
w := NewWriter(io.Discard)
|
||||
done := make(chan int)
|
||||
go func() {
|
||||
w.CreateFormField("foo")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package quotedprintable_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"mime/quotedprintable"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -18,7 +18,7 @@ func ExampleNewReader() {
|
|||
`invalid escape: <b style="font-size: 200%">hello</b>`,
|
||||
"Hello, Gophers! This symbol will be unescaped: =3D and this will be written in =\r\none line.",
|
||||
} {
|
||||
b, err := ioutil.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
|
||||
b, err := io.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
|
||||
fmt.Printf("%s %v\n", b, err)
|
||||
}
|
||||
// Output:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package quotedprintable
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -128,7 +128,7 @@ func TestRoundTrip(t *testing.T) {
|
|||
}
|
||||
|
||||
r := NewReader(buf)
|
||||
gotBytes, err := ioutil.ReadAll(r)
|
||||
gotBytes, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatalf("Error while reading from Reader: %v", err)
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ var testMsg = []byte("Quoted-Printable (QP) est un format d'encodage de données
|
|||
|
||||
func BenchmarkWriter(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
w := NewWriter(ioutil.Discard)
|
||||
w := NewWriter(io.Discard)
|
||||
w.Write(testMsg)
|
||||
w.Close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
. "net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
|
@ -49,7 +48,7 @@ func TestNextProtoUpgrade(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -93,7 +92,7 @@ func TestNextProtoUpgrade(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
conn.Write([]byte("GET /foo\n"))
|
||||
body, err := ioutil.ReadAll(conn)
|
||||
body, err := io.ReadAll(conn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -32,7 +31,7 @@ func Request() (*http.Request, error) {
|
|||
return nil, err
|
||||
}
|
||||
if r.ContentLength > 0 {
|
||||
r.Body = ioutil.NopCloser(io.LimitReader(os.Stdin, r.ContentLength))
|
||||
r.Body = io.NopCloser(io.LimitReader(os.Stdin, r.ContentLength))
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
|
@ -282,7 +281,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, d
|
|||
if resp.ContentLength > 0 && req.Method != "HEAD" {
|
||||
return nil, didTimeout, fmt.Errorf("http: RoundTripper implementation (%T) returned a *Response with content length %d but a nil Body", rt, resp.ContentLength)
|
||||
}
|
||||
resp.Body = ioutil.NopCloser(strings.NewReader(""))
|
||||
resp.Body = io.NopCloser(strings.NewReader(""))
|
||||
}
|
||||
if !deadline.IsZero() {
|
||||
resp.Body = &cancelTimerBody{
|
||||
|
|
@ -697,7 +696,7 @@ func (c *Client) do(req *Request) (retres *Response, reterr error) {
|
|||
// fails, the Transport won't reuse it anyway.
|
||||
const maxBodySlurpSize = 2 << 10
|
||||
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
|
||||
io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
|
||||
io.CopyN(io.Discard, resp.Body, maxBodySlurpSize)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
. "net/http"
|
||||
|
|
@ -35,7 +34,7 @@ var robotsTxtHandler = HandlerFunc(func(w ResponseWriter, r *Request) {
|
|||
fmt.Fprintf(w, "User-agent: go\nDisallow: /something/")
|
||||
})
|
||||
|
||||
// pedanticReadAll works like ioutil.ReadAll but additionally
|
||||
// pedanticReadAll works like io.ReadAll but additionally
|
||||
// verifies that r obeys the documented io.Reader contract.
|
||||
func pedanticReadAll(r io.Reader) (b []byte, err error) {
|
||||
var bufa [64]byte
|
||||
|
|
@ -190,7 +189,7 @@ func TestPostFormRequestFormat(t *testing.T) {
|
|||
if g, e := tr.req.ContentLength, int64(len(expectedBody)); g != e {
|
||||
t.Errorf("got ContentLength %d, want %d", g, e)
|
||||
}
|
||||
bodyb, err := ioutil.ReadAll(tr.req.Body)
|
||||
bodyb, err := io.ReadAll(tr.req.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll on req.Body: %v", err)
|
||||
}
|
||||
|
|
@ -421,7 +420,7 @@ func testRedirectsByMethod(t *testing.T, method string, table []redirectTest, wa
|
|||
var ts *httptest.Server
|
||||
ts = httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
log.Lock()
|
||||
slurp, _ := ioutil.ReadAll(r.Body)
|
||||
slurp, _ := io.ReadAll(r.Body)
|
||||
fmt.Fprintf(&log.Buffer, "%s %s %q", r.Method, r.RequestURI, slurp)
|
||||
if cl := r.Header.Get("Content-Length"); r.Method == "GET" && len(slurp) == 0 && (r.ContentLength != 0 || cl != "") {
|
||||
fmt.Fprintf(&log.Buffer, " (but with body=%T, content-length = %v, %q)", r.Body, r.ContentLength, cl)
|
||||
|
|
@ -452,7 +451,7 @@ func testRedirectsByMethod(t *testing.T, method string, table []redirectTest, wa
|
|||
for _, tt := range table {
|
||||
content := tt.redirectBody
|
||||
req, _ := NewRequest(method, ts.URL+tt.suffix, strings.NewReader(content))
|
||||
req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(strings.NewReader(content)), nil }
|
||||
req.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(strings.NewReader(content)), nil }
|
||||
res, err := c.Do(req)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -522,7 +521,7 @@ func TestClientRedirectUseResponse(t *testing.T) {
|
|||
t.Errorf("status = %d; want %d", res.StatusCode, StatusFound)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -1042,7 +1041,7 @@ func testClientHeadContentLength(t *testing.T, h2 bool) {
|
|||
if res.ContentLength != tt.want {
|
||||
t.Errorf("Content-Length = %d; want %d", res.ContentLength, tt.want)
|
||||
}
|
||||
bs, err := ioutil.ReadAll(res.Body)
|
||||
bs, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -1257,7 +1256,7 @@ func testClientTimeout(t *testing.T, h2 bool) {
|
|||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ioutil.ReadAll(res.Body)
|
||||
_, err := io.ReadAll(res.Body)
|
||||
errc <- err
|
||||
res.Body.Close()
|
||||
}()
|
||||
|
|
@ -1348,7 +1347,7 @@ func TestClientTimeoutCancel(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
cancel()
|
||||
_, err = io.Copy(ioutil.Discard, res.Body)
|
||||
_, err = io.Copy(io.Discard, res.Body)
|
||||
if err != ExportErrRequestCanceled {
|
||||
t.Fatalf("error = %v; want errRequestCanceled", err)
|
||||
}
|
||||
|
|
@ -1372,7 +1371,7 @@ func testClientRedirectEatsBody(t *testing.T, h2 bool) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = ioutil.ReadAll(res.Body)
|
||||
_, err = io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -1450,7 +1449,7 @@ func (issue15577Tripper) RoundTrip(*Request) (*Response, error) {
|
|||
resp := &Response{
|
||||
StatusCode: 303,
|
||||
Header: map[string][]string{"Location": {"http://www.example.com/"}},
|
||||
Body: ioutil.NopCloser(strings.NewReader("")),
|
||||
Body: io.NopCloser(strings.NewReader("")),
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -1591,7 +1590,7 @@ func TestClientCopyHostOnRedirect(t *testing.T) {
|
|||
if resp.StatusCode != 200 {
|
||||
t.Fatal(resp.Status)
|
||||
}
|
||||
if got, err := ioutil.ReadAll(resp.Body); err != nil || string(got) != wantBody {
|
||||
if got, err := io.ReadAll(resp.Body); err != nil || string(got) != wantBody {
|
||||
t.Errorf("body = %q; want %q", got, wantBody)
|
||||
}
|
||||
}
|
||||
|
|
@ -2020,7 +2019,7 @@ func TestClientPopulatesNilResponseBody(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
if b, err := ioutil.ReadAll(resp.Body); err != nil {
|
||||
if b, err := io.ReadAll(resp.Body); err != nil {
|
||||
t.Errorf("read error from substitute Response.Body: %v", err)
|
||||
} else if len(b) != 0 {
|
||||
t.Errorf("substitute Response.Body was unexpectedly non-empty: %q", b)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
. "net/http"
|
||||
|
|
@ -53,7 +52,7 @@ func (t *clientServerTest) getURL(u string) string {
|
|||
t.t.Fatal(err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.t.Fatal(err)
|
||||
}
|
||||
|
|
@ -152,7 +151,7 @@ func TestChunkedResponseHeaders_h2(t *testing.T) { testChunkedResponseHeaders(t,
|
|||
|
||||
func testChunkedResponseHeaders(t *testing.T, h2 bool) {
|
||||
defer afterTest(t)
|
||||
log.SetOutput(ioutil.Discard) // is noisy otherwise
|
||||
log.SetOutput(io.Discard) // is noisy otherwise
|
||||
defer log.SetOutput(os.Stderr)
|
||||
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
w.Header().Set("Content-Length", "intentional gibberish") // we check that this is deleted
|
||||
|
|
@ -266,11 +265,11 @@ func (tt h12Compare) normalizeRes(t *testing.T, res *Response, wantProto string)
|
|||
} else {
|
||||
t.Errorf("got %q response; want %q", res.Proto, wantProto)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
|
||||
res.Body.Close()
|
||||
res.Body = slurpResult{
|
||||
ReadCloser: ioutil.NopCloser(bytes.NewReader(slurp)),
|
||||
ReadCloser: io.NopCloser(bytes.NewReader(slurp)),
|
||||
body: slurp,
|
||||
err: err,
|
||||
}
|
||||
|
|
@ -477,7 +476,7 @@ func test304Responses(t *testing.T, h2 bool) {
|
|||
if len(res.TransferEncoding) > 0 {
|
||||
t.Errorf("expected no TransferEncoding; got %v", res.TransferEncoding)
|
||||
}
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -564,7 +563,7 @@ func testCancelRequestMidBody(t *testing.T, h2 bool) {
|
|||
|
||||
close(cancel)
|
||||
|
||||
rest, err := ioutil.ReadAll(res.Body)
|
||||
rest, err := io.ReadAll(res.Body)
|
||||
all := string(firstRead) + string(rest)
|
||||
if all != "Hello" {
|
||||
t.Errorf("Read %q (%q + %q); want Hello", all, firstRead, rest)
|
||||
|
|
@ -587,7 +586,7 @@ func testTrailersClientToServer(t *testing.T, h2 bool) {
|
|||
}
|
||||
sort.Strings(decl)
|
||||
|
||||
slurp, err := ioutil.ReadAll(r.Body)
|
||||
slurp, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Errorf("Server reading request body: %v", err)
|
||||
}
|
||||
|
|
@ -721,7 +720,7 @@ func testResponseBodyReadAfterClose(t *testing.T, h2 bool) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
res.Body.Close()
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if len(data) != 0 || err == nil {
|
||||
t.Fatalf("ReadAll returned %q, %v; want error", data, err)
|
||||
}
|
||||
|
|
@ -740,7 +739,7 @@ func testConcurrentReadWriteReqBody(t *testing.T, h2 bool) {
|
|||
// Read in one goroutine.
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if string(data) != reqBody {
|
||||
t.Errorf("Handler read %q; want %q", data, reqBody)
|
||||
}
|
||||
|
|
@ -770,7 +769,7 @@ func testConcurrentReadWriteReqBody(t *testing.T, h2 bool) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
data, err := io.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -887,7 +886,7 @@ func testTransportUserAgent(t *testing.T, h2 bool) {
|
|||
t.Errorf("%d. RoundTrip = %v", i, err)
|
||||
continue
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
t.Errorf("%d. read body = %v", i, err)
|
||||
|
|
@ -1019,7 +1018,7 @@ func TestTransportDiscardsUnneededConns(t *testing.T) {
|
|||
}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
slurp, err := ioutil.ReadAll(resp.Body)
|
||||
slurp, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -1064,7 +1063,7 @@ func testTransportGCRequest(t *testing.T, h2, body bool) {
|
|||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
ioutil.ReadAll(r.Body)
|
||||
io.ReadAll(r.Body)
|
||||
if body {
|
||||
io.WriteString(w, "Hello.")
|
||||
}
|
||||
|
|
@ -1080,7 +1079,7 @@ func testTransportGCRequest(t *testing.T, h2, body bool) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ioutil.ReadAll(res.Body); err != nil {
|
||||
if _, err := io.ReadAll(res.Body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := res.Body.Close(); err != nil {
|
||||
|
|
@ -1141,7 +1140,7 @@ func testTransportRejectsInvalidHeaders(t *testing.T, h2 bool) {
|
|||
res, err := cst.c.Do(req)
|
||||
var body []byte
|
||||
if err == nil {
|
||||
body, _ = ioutil.ReadAll(res.Body)
|
||||
body, _ = io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
}
|
||||
var dialed bool
|
||||
|
|
@ -1198,7 +1197,7 @@ func testInterruptWithPanic(t *testing.T, h2 bool, panicValue interface{}) {
|
|||
}
|
||||
gotHeaders <- true
|
||||
defer res.Body.Close()
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
if string(slurp) != msg {
|
||||
t.Errorf("client read %q; want %q", slurp, msg)
|
||||
}
|
||||
|
|
@ -1363,7 +1362,7 @@ func testServerUndeclaredTrailers(t *testing.T, h2 bool) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
|
||||
if _, err := io.Copy(io.Discard, res.Body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res.Body.Close()
|
||||
|
|
@ -1381,7 +1380,7 @@ func testServerUndeclaredTrailers(t *testing.T, h2 bool) {
|
|||
func TestBadResponseAfterReadingBody(t *testing.T) {
|
||||
defer afterTest(t)
|
||||
cst := newClientServerTest(t, false, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
_, err := io.Copy(ioutil.Discard, r.Body)
|
||||
_, err := io.Copy(io.Discard, r.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -1474,7 +1473,7 @@ func testWriteHeaderAfterWrite(t *testing.T, h2, hijack bool) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ The client must close the response body when finished with it:
|
|||
// handle error
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
// ...
|
||||
|
||||
For control over HTTP client headers, redirect policy, and other
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -46,7 +45,7 @@ func ExampleGet() {
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
robots, err := ioutil.ReadAll(res.Body)
|
||||
robots, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
|
|
@ -186,7 +185,7 @@ func (c *child) serve() {
|
|||
|
||||
var errCloseConn = errors.New("fcgi: connection should be closed")
|
||||
|
||||
var emptyBody = ioutil.NopCloser(strings.NewReader(""))
|
||||
var emptyBody = io.NopCloser(strings.NewReader(""))
|
||||
|
||||
// ErrRequestAborted is returned by Read when a handler attempts to read the
|
||||
// body of a request that has been aborted by the web server.
|
||||
|
|
@ -325,7 +324,7 @@ func (c *child) serveRequest(req *request, body io.ReadCloser) {
|
|||
// some sort of abort request to the host, so the host
|
||||
// can properly cut off the client sending all the data.
|
||||
// For now just bound it a little and
|
||||
io.CopyN(ioutil.Discard, body, 100<<20)
|
||||
io.CopyN(io.Discard, body, 100<<20)
|
||||
body.Close()
|
||||
|
||||
if !req.keepConn {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -243,7 +242,7 @@ func TestChildServeCleansUp(t *testing.T) {
|
|||
r *http.Request,
|
||||
) {
|
||||
// block on reading body of request
|
||||
_, err := io.Copy(ioutil.Discard, r.Body)
|
||||
_, err := io.Copy(io.Discard, r.Body)
|
||||
if err != tt.err {
|
||||
t.Errorf("Expected %#v, got %#v", tt.err, err)
|
||||
}
|
||||
|
|
@ -275,7 +274,7 @@ func TestMalformedParams(t *testing.T) {
|
|||
// end of params
|
||||
1, 4, 0, 1, 0, 0, 0, 0,
|
||||
}
|
||||
rw := rwNopCloser{bytes.NewReader(input), ioutil.Discard}
|
||||
rw := rwNopCloser{bytes.NewReader(input), io.Discard}
|
||||
c := newChild(rw, http.DefaultServeMux)
|
||||
c.serve()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -48,7 +49,7 @@ func TestFileTransport(t *testing.T) {
|
|||
if res.Body == nil {
|
||||
t.Fatalf("for %s, nil Body", urlstr)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
check("ReadAll "+urlstr, err)
|
||||
if string(slurp) != "Bar" {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ Cases:
|
|||
if g, w := part.Header.Get("Content-Range"), wantContentRange; g != w {
|
||||
t.Errorf("range=%q: part Content-Range = %q; want %q", rt.r, g, w)
|
||||
}
|
||||
body, err := ioutil.ReadAll(part)
|
||||
body, err := io.ReadAll(part)
|
||||
if err != nil {
|
||||
t.Errorf("range=%q, reading part index %d body: %v", rt.r, ri, err)
|
||||
continue Cases
|
||||
|
|
@ -312,7 +312,7 @@ func TestFileServerEscapesNames(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("test %q: Get: %v", test.name, err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("test %q: read Body: %v", test.name, err)
|
||||
}
|
||||
|
|
@ -360,7 +360,7 @@ func TestFileServerSortsNames(t *testing.T) {
|
|||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read Body: %v", err)
|
||||
}
|
||||
|
|
@ -394,7 +394,7 @@ func TestFileServerImplicitLeadingSlash(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Get %s: %v", suffix, err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll %s: %v", suffix, err)
|
||||
}
|
||||
|
|
@ -617,7 +617,7 @@ func TestServeIndexHtmlFS(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal("reading Body:", err)
|
||||
}
|
||||
|
|
@ -745,7 +745,7 @@ func TestDirectoryIfNotModified(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(res.Body)
|
||||
b, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -1082,7 +1082,7 @@ func TestServeContent(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
io.Copy(ioutil.Discard, res.Body)
|
||||
io.Copy(io.Discard, res.Body)
|
||||
res.Body.Close()
|
||||
if res.StatusCode != tt.wantStatus {
|
||||
t.Errorf("test %q using %q: got status = %d; want %d", testName, method, res.StatusCode, tt.wantStatus)
|
||||
|
|
@ -1196,7 +1196,7 @@ func TestLinuxSendfile(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("http client error: %v", err)
|
||||
}
|
||||
_, err = io.Copy(ioutil.Discard, res.Body)
|
||||
_, err = io.Copy(io.Discard, res.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("client body read error: %v", err)
|
||||
}
|
||||
|
|
@ -1218,7 +1218,7 @@ func getBody(t *testing.T, testName string, req Request, client *Client) (*Respo
|
|||
if err != nil {
|
||||
t.Fatalf("%s: for URL %q, send error: %v", testName, req.URL.String(), err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
b, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: for URL %q, reading body: %v", testName, req.URL.String(), err)
|
||||
}
|
||||
|
|
@ -1401,7 +1401,7 @@ func testServeFileRejectsInvalidSuffixLengths(t *testing.T, h2 bool) {
|
|||
if g, w := res.StatusCode, tt.wantCode; g != w {
|
||||
t.Errorf("StatusCode mismatch: got %d want %d", g, w)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -35,7 +34,7 @@ func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error) {
|
|||
if err = b.Close(); err != nil {
|
||||
return nil, b, err
|
||||
}
|
||||
return ioutil.NopCloser(&buf), ioutil.NopCloser(bytes.NewReader(buf.Bytes())), nil
|
||||
return io.NopCloser(&buf), io.NopCloser(bytes.NewReader(buf.Bytes())), nil
|
||||
}
|
||||
|
||||
// dumpConn is a net.Conn which writes to Writer and reads from Reader
|
||||
|
|
@ -81,7 +80,7 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
|
|||
if !body {
|
||||
contentLength := outgoingLength(req)
|
||||
if contentLength != 0 {
|
||||
req.Body = ioutil.NopCloser(io.LimitReader(neverEnding('x'), contentLength))
|
||||
req.Body = io.NopCloser(io.LimitReader(neverEnding('x'), contentLength))
|
||||
dummyBody = true
|
||||
}
|
||||
} else {
|
||||
|
|
@ -133,7 +132,7 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
|
|||
if err == nil {
|
||||
// Ensure all the body is read; otherwise
|
||||
// we'll get a partial dump.
|
||||
io.Copy(ioutil.Discard, req.Body)
|
||||
io.Copy(io.Discard, req.Body)
|
||||
req.Body.Close()
|
||||
}
|
||||
select {
|
||||
|
|
@ -296,7 +295,7 @@ func (failureToReadBody) Read([]byte) (int, error) { return 0, errNoBody }
|
|||
func (failureToReadBody) Close() error { return nil }
|
||||
|
||||
// emptyBody is an instance of empty reader.
|
||||
var emptyBody = ioutil.NopCloser(strings.NewReader(""))
|
||||
var emptyBody = io.NopCloser(strings.NewReader(""))
|
||||
|
||||
// DumpResponse is like DumpRequest but dumps a response.
|
||||
func DumpResponse(resp *http.Response, body bool) ([]byte, error) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime"
|
||||
|
|
@ -268,7 +267,7 @@ func TestDumpRequest(t *testing.T) {
|
|||
}
|
||||
switch b := ti.Body.(type) {
|
||||
case []byte:
|
||||
req.Body = ioutil.NopCloser(bytes.NewReader(b))
|
||||
req.Body = io.NopCloser(bytes.NewReader(b))
|
||||
case func() io.ReadCloser:
|
||||
req.Body = b()
|
||||
default:
|
||||
|
|
@ -363,7 +362,7 @@ var dumpResTests = []struct {
|
|||
Header: http.Header{
|
||||
"Foo": []string{"Bar"},
|
||||
},
|
||||
Body: ioutil.NopCloser(strings.NewReader("foo")), // shouldn't be used
|
||||
Body: io.NopCloser(strings.NewReader("foo")), // shouldn't be used
|
||||
},
|
||||
body: false, // to verify we see 50, not empty or 3.
|
||||
want: `HTTP/1.1 200 OK
|
||||
|
|
@ -379,7 +378,7 @@ Foo: Bar`,
|
|||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
ContentLength: 3,
|
||||
Body: ioutil.NopCloser(strings.NewReader("foo")),
|
||||
Body: io.NopCloser(strings.NewReader("foo")),
|
||||
},
|
||||
body: true,
|
||||
want: `HTTP/1.1 200 OK
|
||||
|
|
@ -396,7 +395,7 @@ foo`,
|
|||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
ContentLength: -1,
|
||||
Body: ioutil.NopCloser(strings.NewReader("foo")),
|
||||
Body: io.NopCloser(strings.NewReader("foo")),
|
||||
TransferEncoding: []string{"chunked"},
|
||||
},
|
||||
body: true,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package httputil_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -39,7 +39,7 @@ func ExampleDumpRequest() {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ func ExampleReverseProxy() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -84,7 +83,7 @@ func TestReverseProxy(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
proxyHandler := NewSingleHostReverseProxy(backendURL)
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
frontend := httptest.NewServer(proxyHandler)
|
||||
defer frontend.Close()
|
||||
frontendClient := frontend.Client()
|
||||
|
|
@ -124,7 +123,7 @@ func TestReverseProxy(t *testing.T) {
|
|||
if cookie := res.Cookies()[0]; cookie.Name != "flavor" {
|
||||
t.Errorf("unexpected cookie %q", cookie.Name)
|
||||
}
|
||||
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
||||
bodyBytes, _ := io.ReadAll(res.Body)
|
||||
if g, e := string(bodyBytes), backendResponse; g != e {
|
||||
t.Errorf("got body %q; expected %q", g, e)
|
||||
}
|
||||
|
|
@ -218,7 +217,7 @@ func TestReverseProxyStripHeadersPresentInConnection(t *testing.T) {
|
|||
t.Fatalf("Get: %v", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
bodyBytes, err := ioutil.ReadAll(res.Body)
|
||||
bodyBytes, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("reading body: %v", err)
|
||||
}
|
||||
|
|
@ -271,7 +270,7 @@ func TestXForwardedFor(t *testing.T) {
|
|||
if g, e := res.StatusCode, backendStatus; g != e {
|
||||
t.Errorf("got res.StatusCode %d; expected %d", g, e)
|
||||
}
|
||||
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
||||
bodyBytes, _ := io.ReadAll(res.Body)
|
||||
if g, e := string(bodyBytes), backendResponse; g != e {
|
||||
t.Errorf("got body %q; expected %q", g, e)
|
||||
}
|
||||
|
|
@ -373,7 +372,7 @@ func TestReverseProxyFlushInterval(t *testing.T) {
|
|||
t.Fatalf("Get: %v", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if bodyBytes, _ := ioutil.ReadAll(res.Body); string(bodyBytes) != expected {
|
||||
if bodyBytes, _ := io.ReadAll(res.Body); string(bodyBytes) != expected {
|
||||
t.Errorf("got body %q; expected %q", bodyBytes, expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -441,7 +440,7 @@ func TestReverseProxyCancellation(t *testing.T) {
|
|||
|
||||
defer backend.Close()
|
||||
|
||||
backend.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
|
||||
backend.Config.ErrorLog = log.New(io.Discard, "", 0)
|
||||
|
||||
backendURL, err := url.Parse(backend.URL)
|
||||
if err != nil {
|
||||
|
|
@ -452,7 +451,7 @@ func TestReverseProxyCancellation(t *testing.T) {
|
|||
|
||||
// Discards errors of the form:
|
||||
// http: proxy error: read tcp 127.0.0.1:44643: use of closed network connection
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0)
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0)
|
||||
|
||||
frontend := httptest.NewServer(proxyHandler)
|
||||
defer frontend.Close()
|
||||
|
|
@ -504,7 +503,7 @@ func TestNilBody(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -533,7 +532,7 @@ func TestUserAgentHeader(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
proxyHandler := NewSingleHostReverseProxy(backendURL)
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
frontend := httptest.NewServer(proxyHandler)
|
||||
defer frontend.Close()
|
||||
frontendClient := frontend.Client()
|
||||
|
|
@ -606,7 +605,7 @@ func TestReverseProxyGetPutBuffer(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Get: %v", err)
|
||||
}
|
||||
slurp, err := ioutil.ReadAll(res.Body)
|
||||
slurp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("reading body: %v", err)
|
||||
|
|
@ -627,7 +626,7 @@ func TestReverseProxy_Post(t *testing.T) {
|
|||
const backendStatus = 200
|
||||
var requestBody = bytes.Repeat([]byte("a"), 1<<20)
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
slurp, err := ioutil.ReadAll(r.Body)
|
||||
slurp, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Errorf("Backend body read = %v", err)
|
||||
}
|
||||
|
|
@ -656,7 +655,7 @@ func TestReverseProxy_Post(t *testing.T) {
|
|||
if g, e := res.StatusCode, backendStatus; g != e {
|
||||
t.Errorf("got res.StatusCode %d; expected %d", g, e)
|
||||
}
|
||||
bodyBytes, _ := ioutil.ReadAll(res.Body)
|
||||
bodyBytes, _ := io.ReadAll(res.Body)
|
||||
if g, e := string(bodyBytes), backendResponse; g != e {
|
||||
t.Errorf("got body %q; expected %q", g, e)
|
||||
}
|
||||
|
|
@ -672,7 +671,7 @@ func (fn RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)
|
|||
func TestReverseProxy_NilBody(t *testing.T) {
|
||||
backendURL, _ := url.Parse("http://fake.tld/")
|
||||
proxyHandler := NewSingleHostReverseProxy(backendURL)
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.Transport = RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if req.Body != nil {
|
||||
t.Error("Body != nil; want a nil Body")
|
||||
|
|
@ -695,8 +694,8 @@ func TestReverseProxy_NilBody(t *testing.T) {
|
|||
// Issue 33142: always allocate the request headers
|
||||
func TestReverseProxy_AllocatedHeader(t *testing.T) {
|
||||
proxyHandler := new(ReverseProxy)
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.Director = func(*http.Request) {} // noop
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.Director = func(*http.Request) {} // noop
|
||||
proxyHandler.Transport = RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
|
||||
if req.Header == nil {
|
||||
t.Error("Header == nil; want a non-nil Header")
|
||||
|
|
@ -722,7 +721,7 @@ func TestReverseProxyModifyResponse(t *testing.T) {
|
|||
|
||||
rpURL, _ := url.Parse(backendServer.URL)
|
||||
rproxy := NewSingleHostReverseProxy(rpURL)
|
||||
rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
rproxy.ModifyResponse = func(resp *http.Response) error {
|
||||
if resp.Header.Get("X-Hit-Mod") != "true" {
|
||||
return fmt.Errorf("tried to by-pass proxy")
|
||||
|
|
@ -821,7 +820,7 @@ func TestReverseProxyErrorHandler(t *testing.T) {
|
|||
if rproxy.Transport == nil {
|
||||
rproxy.Transport = failingRoundTripper{}
|
||||
}
|
||||
rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
if tt.errorHandler != nil {
|
||||
rproxy.ErrorHandler = tt.errorHandler
|
||||
}
|
||||
|
|
@ -896,7 +895,7 @@ func (t *staticTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
func BenchmarkServeHTTP(b *testing.B) {
|
||||
res := &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(strings.NewReader("")),
|
||||
Body: io.NopCloser(strings.NewReader("")),
|
||||
}
|
||||
proxy := &ReverseProxy{
|
||||
Director: func(*http.Request) {},
|
||||
|
|
@ -953,7 +952,7 @@ func TestServeHTTPDeepCopy(t *testing.T) {
|
|||
// Issue 18327: verify we always do a deep copy of the Request.Header map
|
||||
// before any mutations.
|
||||
func TestClonesRequestHeaders(t *testing.T) {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
log.SetOutput(io.Discard)
|
||||
defer log.SetOutput(os.Stderr)
|
||||
req, _ := http.NewRequest("GET", "http://foo.tld/", nil)
|
||||
req.RemoteAddr = "1.2.3.4:56789"
|
||||
|
|
@ -1031,7 +1030,7 @@ func (cc *checkCloser) Read(b []byte) (int, error) {
|
|||
|
||||
// Issue 23643: panic on body copy error
|
||||
func TestReverseProxy_PanicBodyError(t *testing.T) {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
log.SetOutput(io.Discard)
|
||||
defer log.SetOutput(os.Stderr)
|
||||
backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
out := "this call was relayed by the reverse proxy"
|
||||
|
|
@ -1148,7 +1147,7 @@ func TestReverseProxyWebSocket(t *testing.T) {
|
|||
|
||||
backURL, _ := url.Parse(backendServer.URL)
|
||||
rproxy := NewSingleHostReverseProxy(backURL)
|
||||
rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
rproxy.ModifyResponse = func(res *http.Response) error {
|
||||
res.Header.Add("X-Modified", "true")
|
||||
return nil
|
||||
|
|
@ -1265,7 +1264,7 @@ func TestReverseProxyWebSocketCancelation(t *testing.T) {
|
|||
|
||||
backendURL, _ := url.Parse(cst.URL)
|
||||
rproxy := NewSingleHostReverseProxy(backendURL)
|
||||
rproxy.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
rproxy.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
rproxy.ModifyResponse = func(res *http.Response) error {
|
||||
res.Header.Add("X-Modified", "true")
|
||||
return nil
|
||||
|
|
@ -1352,7 +1351,7 @@ func TestUnannouncedTrailer(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
proxyHandler := NewSingleHostReverseProxy(backendURL)
|
||||
proxyHandler.ErrorLog = log.New(ioutil.Discard, "", 0) // quiet for tests
|
||||
proxyHandler.ErrorLog = log.New(io.Discard, "", 0) // quiet for tests
|
||||
frontend := httptest.NewServer(proxyHandler)
|
||||
defer frontend.Close()
|
||||
frontendClient := frontend.Client()
|
||||
|
|
@ -1362,7 +1361,7 @@ func TestUnannouncedTrailer(t *testing.T) {
|
|||
t.Fatalf("Get: %v", err)
|
||||
}
|
||||
|
||||
ioutil.ReadAll(res.Body)
|
||||
io.ReadAll(res.Body)
|
||||
|
||||
if g, w := res.Trailer.Get("X-Unannounced-Trailer"), "unannounced_trailer_value"; g != w {
|
||||
t.Errorf("Trailer(X-Unannounced-Trailer) = %q; want %q", g, w)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -29,7 +28,7 @@ func TestChunk(t *testing.T) {
|
|||
}
|
||||
|
||||
r := NewChunkedReader(&b)
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Logf(`data: "%s"`, data)
|
||||
t.Fatalf("ReadAll from reader: %v", err)
|
||||
|
|
@ -177,7 +176,7 @@ func TestChunkReadingIgnoresExtensions(t *testing.T) {
|
|||
"17;someext\r\n" + // token without value
|
||||
"world! 0123456789abcdef\r\n" +
|
||||
"0;someextension=sometoken\r\n" // token=token
|
||||
data, err := ioutil.ReadAll(NewChunkedReader(strings.NewReader(in)))
|
||||
data, err := io.ReadAll(NewChunkedReader(strings.NewReader(in)))
|
||||
if err != nil {
|
||||
t.Fatalf("ReadAll = %q, %v", data, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package http_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var quietLog = log.New(ioutil.Discard, "", 0)
|
||||
var quietLog = log.New(io.Discard, "", 0)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
v := m.Run()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"internal/profile"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"runtime"
|
||||
|
|
@ -63,7 +63,7 @@ func TestHandlers(t *testing.T) {
|
|||
t.Errorf("status code: got %d; want %d", got, want)
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("when reading response body, expected non-nil err; got %v", err)
|
||||
}
|
||||
|
|
@ -227,7 +227,7 @@ func query(endpoint string) (*profile.Profile, error) {
|
|||
return nil, fmt.Errorf("failed to fetch %q: %v", url, r.Status)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
b, err := io.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read and parse the result from %q: %v", url, err)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue