1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
24 type testError struct{ error }
26 type fileOps []any // []T where T is (string | int64)
28 // testFile is an io.ReadWriteSeeker where the IO operations performed
29 // on it must match the list of operations in ops.
30 type testFile struct {
35 func (f *testFile) Read(b []byte) (int, error) {
42 s, ok := f.ops[0].(string)
44 return 0, errors.New("unexpected Read operation")
53 f.pos += int64(len(b))
57 func (f *testFile) Write(b []byte) (int, error) {
62 return 0, errors.New("unexpected Write operation")
64 s, ok := f.ops[0].(string)
66 return 0, errors.New("unexpected Write operation")
69 if !strings.HasPrefix(s, string(b)) {
70 return 0, testError{fmt.Errorf("got Write(%q), want Write(%q)", b, s)}
77 f.pos += int64(len(b))
81 func (f *testFile) Seek(pos int64, whence int) (int64, error) {
82 if pos == 0 && whence == io.SeekCurrent {
86 return 0, errors.New("unexpected Seek operation")
88 s, ok := f.ops[0].(int64)
90 return 0, errors.New("unexpected Seek operation")
93 if s != pos || whence != io.SeekCurrent {
94 return 0, testError{fmt.Errorf("got Seek(%d, %d), want Seek(%d, %d)", pos, whence, s, io.SeekCurrent)}
101 func equalSparseEntries(x, y []sparseEntry) bool {
102 return (len(x) == 0 && len(y) == 0) || reflect.DeepEqual(x, y)
105 func TestSparseEntries(t *testing.T) {
106 vectors := []struct {
110 wantValid bool // Result of validateSparseEntries
111 wantAligned []sparseEntry // Result of alignSparseEntries
112 wantInverted []sparseEntry // Result of invertSparseEntries
114 in: []sparseEntry{}, size: 0,
116 wantInverted: []sparseEntry{{0, 0}},
118 in: []sparseEntry{}, size: 5000,
120 wantInverted: []sparseEntry{{0, 5000}},
122 in: []sparseEntry{{0, 5000}}, size: 5000,
124 wantAligned: []sparseEntry{{0, 5000}},
125 wantInverted: []sparseEntry{{5000, 0}},
127 in: []sparseEntry{{1000, 4000}}, size: 5000,
129 wantAligned: []sparseEntry{{1024, 3976}},
130 wantInverted: []sparseEntry{{0, 1000}, {5000, 0}},
132 in: []sparseEntry{{0, 3000}}, size: 5000,
134 wantAligned: []sparseEntry{{0, 2560}},
135 wantInverted: []sparseEntry{{3000, 2000}},
137 in: []sparseEntry{{3000, 2000}}, size: 5000,
139 wantAligned: []sparseEntry{{3072, 1928}},
140 wantInverted: []sparseEntry{{0, 3000}, {5000, 0}},
142 in: []sparseEntry{{2000, 2000}}, size: 5000,
144 wantAligned: []sparseEntry{{2048, 1536}},
145 wantInverted: []sparseEntry{{0, 2000}, {4000, 1000}},
147 in: []sparseEntry{{0, 2000}, {8000, 2000}}, size: 10000,
149 wantAligned: []sparseEntry{{0, 1536}, {8192, 1808}},
150 wantInverted: []sparseEntry{{2000, 6000}, {10000, 0}},
152 in: []sparseEntry{{0, 2000}, {2000, 2000}, {4000, 0}, {4000, 3000}, {7000, 1000}, {8000, 0}, {8000, 2000}}, size: 10000,
154 wantAligned: []sparseEntry{{0, 1536}, {2048, 1536}, {4096, 2560}, {7168, 512}, {8192, 1808}},
155 wantInverted: []sparseEntry{{10000, 0}},
157 in: []sparseEntry{{0, 0}, {1000, 0}, {2000, 0}, {3000, 0}, {4000, 0}, {5000, 0}}, size: 5000,
159 wantInverted: []sparseEntry{{0, 5000}},
161 in: []sparseEntry{{1, 0}}, size: 0,
164 in: []sparseEntry{{-1, 0}}, size: 100,
167 in: []sparseEntry{{0, -1}}, size: 100,
170 in: []sparseEntry{{0, 0}}, size: -100,
173 in: []sparseEntry{{math.MaxInt64, 3}, {6, -5}}, size: 35,
176 in: []sparseEntry{{1, 3}, {6, -5}}, size: 35,
179 in: []sparseEntry{{math.MaxInt64, math.MaxInt64}}, size: math.MaxInt64,
182 in: []sparseEntry{{3, 3}}, size: 5,
185 in: []sparseEntry{{2, 0}, {1, 0}, {0, 0}}, size: 3,
188 in: []sparseEntry{{1, 3}, {2, 2}}, size: 10,
192 for i, v := range vectors {
193 gotValid := validateSparseEntries(v.in, v.size)
194 if gotValid != v.wantValid {
195 t.Errorf("test %d, validateSparseEntries() = %v, want %v", i, gotValid, v.wantValid)
200 gotAligned := alignSparseEntries(append([]sparseEntry{}, v.in...), v.size)
201 if !equalSparseEntries(gotAligned, v.wantAligned) {
202 t.Errorf("test %d, alignSparseEntries():\ngot %v\nwant %v", i, gotAligned, v.wantAligned)
204 gotInverted := invertSparseEntries(append([]sparseEntry{}, v.in...), v.size)
205 if !equalSparseEntries(gotInverted, v.wantInverted) {
206 t.Errorf("test %d, inverseSparseEntries():\ngot %v\nwant %v", i, gotInverted, v.wantInverted)
211 func TestFileInfoHeader(t *testing.T) {
212 fi, err := os.Stat("testdata/small.txt")
216 h, err := FileInfoHeader(fi, "")
218 t.Fatalf("FileInfoHeader: %v", err)
220 if g, e := h.Name, "small.txt"; g != e {
221 t.Errorf("Name = %q; want %q", g, e)
223 if g, e := h.Mode, int64(fi.Mode().Perm()); g != e {
224 t.Errorf("Mode = %#o; want %#o", g, e)
226 if g, e := h.Size, int64(5); g != e {
227 t.Errorf("Size = %v; want %v", g, e)
229 if g, e := h.ModTime, fi.ModTime(); !g.Equal(e) {
230 t.Errorf("ModTime = %v; want %v", g, e)
232 // FileInfoHeader should error when passing nil FileInfo
233 if _, err := FileInfoHeader(nil, ""); err == nil {
234 t.Fatalf("Expected error when passing nil to FileInfoHeader")
238 func TestFileInfoHeaderDir(t *testing.T) {
239 fi, err := os.Stat("testdata")
243 h, err := FileInfoHeader(fi, "")
245 t.Fatalf("FileInfoHeader: %v", err)
247 if g, e := h.Name, "testdata/"; g != e {
248 t.Errorf("Name = %q; want %q", g, e)
250 // Ignoring c_ISGID for golang.org/issue/4867
251 if g, e := h.Mode&^c_ISGID, int64(fi.Mode().Perm()); g != e {
252 t.Errorf("Mode = %#o; want %#o", g, e)
254 if g, e := h.Size, int64(0); g != e {
255 t.Errorf("Size = %v; want %v", g, e)
257 if g, e := h.ModTime, fi.ModTime(); !g.Equal(e) {
258 t.Errorf("ModTime = %v; want %v", g, e)
262 func TestFileInfoHeaderSymlink(t *testing.T) {
263 testenv.MustHaveSymlink(t)
265 tmpdir := t.TempDir()
267 link := filepath.Join(tmpdir, "link")
269 if err := os.Symlink(target, link); err != nil {
272 fi, err := os.Lstat(link)
277 h, err := FileInfoHeader(fi, target)
281 if g, e := h.Name, fi.Name(); g != e {
282 t.Errorf("Name = %q; want %q", g, e)
284 if g, e := h.Linkname, target; g != e {
285 t.Errorf("Linkname = %q; want %q", g, e)
287 if g, e := h.Typeflag, byte(TypeSymlink); g != e {
288 t.Errorf("Typeflag = %v; want %v", g, e)
292 func TestRoundTrip(t *testing.T) {
293 data := []byte("some file contents")
299 Uid: 1 << 21, // Too big for 8 octal digits
300 Size: int64(len(data)),
301 ModTime: time.Now().Round(time.Second),
302 PAXRecords: map[string]string{"uid": "2097152"},
306 if err := tw.WriteHeader(hdr); err != nil {
307 t.Fatalf("tw.WriteHeader: %v", err)
309 if _, err := tw.Write(data); err != nil {
310 t.Fatalf("tw.Write: %v", err)
312 if err := tw.Close(); err != nil {
313 t.Fatalf("tw.Close: %v", err)
318 rHdr, err := tr.Next()
320 t.Fatalf("tr.Next: %v", err)
322 if !reflect.DeepEqual(rHdr, hdr) {
323 t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr)
325 rData, err := io.ReadAll(tr)
327 t.Fatalf("Read: %v", err)
329 if !bytes.Equal(rData, data) {
330 t.Errorf("Data mismatch.\n got %q\nwant %q", rData, data)
334 type headerRoundTripTest struct {
339 func TestHeaderRoundTrip(t *testing.T) {
340 vectors := []headerRoundTripTest{{
346 ModTime: time.Unix(1360600916, 0),
356 ModTime: time.Unix(1360600852, 0),
357 Typeflag: TypeSymlink,
359 fm: 0777 | fs.ModeSymlink,
361 // character device node.
366 ModTime: time.Unix(1360578951, 0),
369 fm: 0666 | fs.ModeDevice | fs.ModeCharDevice,
371 // block device node.
376 ModTime: time.Unix(1360578954, 0),
379 fm: 0660 | fs.ModeDevice,
386 ModTime: time.Unix(1360601116, 0),
389 fm: 0755 | fs.ModeDir,
396 ModTime: time.Unix(1360578949, 0),
399 fm: 0600 | fs.ModeNamedPipe,
404 Mode: 0755 | c_ISUID,
406 ModTime: time.Unix(1355405093, 0),
409 fm: 0755 | fs.ModeSetuid,
414 Mode: 0750 | c_ISGID,
416 ModTime: time.Unix(1360602346, 0),
419 fm: 0750 | fs.ModeSetgid,
424 Mode: 0600 | c_ISVTX,
426 ModTime: time.Unix(1360602540, 0),
429 fm: 0600 | fs.ModeSticky,
436 Linkname: "file.txt",
437 ModTime: time.Unix(1360600916, 0),
449 ModTime: time.Unix(1360602540, 0),
450 Uname: "slartibartfast",
457 for i, v := range vectors {
459 h2, err := FileInfoHeader(fi, "")
464 if strings.Contains(fi.Name(), "/") {
465 t.Errorf("FileInfo of %q contains slash: %q", v.h.Name, fi.Name())
467 name := path.Base(v.h.Name)
471 if got, want := h2.Name, name; got != want {
472 t.Errorf("i=%d: Name: got %v, want %v", i, got, want)
474 if got, want := h2.Size, v.h.Size; got != want {
475 t.Errorf("i=%d: Size: got %v, want %v", i, got, want)
477 if got, want := h2.Uid, v.h.Uid; got != want {
478 t.Errorf("i=%d: Uid: got %d, want %d", i, got, want)
480 if got, want := h2.Gid, v.h.Gid; got != want {
481 t.Errorf("i=%d: Gid: got %d, want %d", i, got, want)
483 if got, want := h2.Uname, v.h.Uname; got != want {
484 t.Errorf("i=%d: Uname: got %q, want %q", i, got, want)
486 if got, want := h2.Gname, v.h.Gname; got != want {
487 t.Errorf("i=%d: Gname: got %q, want %q", i, got, want)
489 if got, want := h2.Linkname, v.h.Linkname; got != want {
490 t.Errorf("i=%d: Linkname: got %v, want %v", i, got, want)
492 if got, want := h2.Typeflag, v.h.Typeflag; got != want {
493 t.Logf("%#v %#v", v.h, fi.Sys())
494 t.Errorf("i=%d: Typeflag: got %q, want %q", i, got, want)
496 if got, want := h2.Mode, v.h.Mode; got != want {
497 t.Errorf("i=%d: Mode: got %o, want %o", i, got, want)
499 if got, want := fi.Mode(), v.fm; got != want {
500 t.Errorf("i=%d: fi.Mode: got %o, want %o", i, got, want)
502 if got, want := h2.AccessTime, v.h.AccessTime; got != want {
503 t.Errorf("i=%d: AccessTime: got %v, want %v", i, got, want)
505 if got, want := h2.ChangeTime, v.h.ChangeTime; got != want {
506 t.Errorf("i=%d: ChangeTime: got %v, want %v", i, got, want)
508 if got, want := h2.ModTime, v.h.ModTime; got != want {
509 t.Errorf("i=%d: ModTime: got %v, want %v", i, got, want)
511 if sysh, ok := fi.Sys().(*Header); !ok || sysh != v.h {
512 t.Errorf("i=%d: Sys didn't return original *Header", i)
517 func TestHeaderAllowedFormats(t *testing.T) {
518 vectors := []struct {
519 header *Header // Input header
520 paxHdrs map[string]string // Expected PAX headers that may be needed
521 formats Format // Expected formats that can encode the header
524 formats: FormatUSTAR | FormatPAX | FormatGNU,
526 header: &Header{Size: 077777777777},
527 formats: FormatUSTAR | FormatPAX | FormatGNU,
529 header: &Header{Size: 077777777777, Format: FormatUSTAR},
530 formats: FormatUSTAR,
532 header: &Header{Size: 077777777777, Format: FormatPAX},
533 formats: FormatUSTAR | FormatPAX,
535 header: &Header{Size: 077777777777, Format: FormatGNU},
538 header: &Header{Size: 077777777777 + 1},
539 paxHdrs: map[string]string{paxSize: "8589934592"},
540 formats: FormatPAX | FormatGNU,
542 header: &Header{Size: 077777777777 + 1, Format: FormatPAX},
543 paxHdrs: map[string]string{paxSize: "8589934592"},
546 header: &Header{Size: 077777777777 + 1, Format: FormatGNU},
547 paxHdrs: map[string]string{paxSize: "8589934592"},
550 header: &Header{Mode: 07777777},
551 formats: FormatUSTAR | FormatPAX | FormatGNU,
553 header: &Header{Mode: 07777777 + 1},
556 header: &Header{Devmajor: -123},
559 header: &Header{Devmajor: 1<<56 - 1},
562 header: &Header{Devmajor: 1 << 56},
563 formats: FormatUnknown,
565 header: &Header{Devmajor: -1 << 56},
568 header: &Header{Devmajor: -1<<56 - 1},
569 formats: FormatUnknown,
571 header: &Header{Name: "用戶名", Devmajor: -1 << 56},
574 header: &Header{Size: math.MaxInt64},
575 paxHdrs: map[string]string{paxSize: "9223372036854775807"},
576 formats: FormatPAX | FormatGNU,
578 header: &Header{Size: math.MinInt64},
579 paxHdrs: map[string]string{paxSize: "-9223372036854775808"},
580 formats: FormatUnknown,
582 header: &Header{Uname: "0123456789abcdef0123456789abcdef"},
583 formats: FormatUSTAR | FormatPAX | FormatGNU,
585 header: &Header{Uname: "0123456789abcdef0123456789abcdefx"},
586 paxHdrs: map[string]string{paxUname: "0123456789abcdef0123456789abcdefx"},
589 header: &Header{Name: "foobar"},
590 formats: FormatUSTAR | FormatPAX | FormatGNU,
592 header: &Header{Name: strings.Repeat("a", nameSize)},
593 formats: FormatUSTAR | FormatPAX | FormatGNU,
595 header: &Header{Name: strings.Repeat("a", nameSize+1)},
596 paxHdrs: map[string]string{paxPath: strings.Repeat("a", nameSize+1)},
597 formats: FormatPAX | FormatGNU,
599 header: &Header{Linkname: "用戶名"},
600 paxHdrs: map[string]string{paxLinkpath: "用戶名"},
601 formats: FormatPAX | FormatGNU,
603 header: &Header{Linkname: strings.Repeat("用戶名\x00", nameSize)},
604 paxHdrs: map[string]string{paxLinkpath: strings.Repeat("用戶名\x00", nameSize)},
605 formats: FormatUnknown,
607 header: &Header{Linkname: "\x00hello"},
608 paxHdrs: map[string]string{paxLinkpath: "\x00hello"},
609 formats: FormatUnknown,
611 header: &Header{Uid: 07777777},
612 formats: FormatUSTAR | FormatPAX | FormatGNU,
614 header: &Header{Uid: 07777777 + 1},
615 paxHdrs: map[string]string{paxUid: "2097152"},
616 formats: FormatPAX | FormatGNU,
618 header: &Header{Xattrs: nil},
619 formats: FormatUSTAR | FormatPAX | FormatGNU,
621 header: &Header{Xattrs: map[string]string{"foo": "bar"}},
622 paxHdrs: map[string]string{paxSchilyXattr + "foo": "bar"},
625 header: &Header{Xattrs: map[string]string{"foo": "bar"}, Format: FormatGNU},
626 paxHdrs: map[string]string{paxSchilyXattr + "foo": "bar"},
627 formats: FormatUnknown,
629 header: &Header{Xattrs: map[string]string{"用戶名": "\x00hello"}},
630 paxHdrs: map[string]string{paxSchilyXattr + "用戶名": "\x00hello"},
633 header: &Header{Xattrs: map[string]string{"foo=bar": "baz"}},
634 formats: FormatUnknown,
636 header: &Header{Xattrs: map[string]string{"foo": ""}},
637 paxHdrs: map[string]string{paxSchilyXattr + "foo": ""},
640 header: &Header{ModTime: time.Unix(0, 0)},
641 formats: FormatUSTAR | FormatPAX | FormatGNU,
643 header: &Header{ModTime: time.Unix(077777777777, 0)},
644 formats: FormatUSTAR | FormatPAX | FormatGNU,
646 header: &Header{ModTime: time.Unix(077777777777+1, 0)},
647 paxHdrs: map[string]string{paxMtime: "8589934592"},
648 formats: FormatPAX | FormatGNU,
650 header: &Header{ModTime: time.Unix(math.MaxInt64, 0)},
651 paxHdrs: map[string]string{paxMtime: "9223372036854775807"},
652 formats: FormatPAX | FormatGNU,
654 header: &Header{ModTime: time.Unix(math.MaxInt64, 0), Format: FormatUSTAR},
655 paxHdrs: map[string]string{paxMtime: "9223372036854775807"},
656 formats: FormatUnknown,
658 header: &Header{ModTime: time.Unix(-1, 0)},
659 paxHdrs: map[string]string{paxMtime: "-1"},
660 formats: FormatPAX | FormatGNU,
662 header: &Header{ModTime: time.Unix(1, 500)},
663 paxHdrs: map[string]string{paxMtime: "1.0000005"},
664 formats: FormatUSTAR | FormatPAX | FormatGNU,
666 header: &Header{ModTime: time.Unix(1, 0)},
667 formats: FormatUSTAR | FormatPAX | FormatGNU,
669 header: &Header{ModTime: time.Unix(1, 0), Format: FormatPAX},
670 formats: FormatUSTAR | FormatPAX,
672 header: &Header{ModTime: time.Unix(1, 500), Format: FormatUSTAR},
673 paxHdrs: map[string]string{paxMtime: "1.0000005"},
674 formats: FormatUSTAR,
676 header: &Header{ModTime: time.Unix(1, 500), Format: FormatPAX},
677 paxHdrs: map[string]string{paxMtime: "1.0000005"},
680 header: &Header{ModTime: time.Unix(1, 500), Format: FormatGNU},
681 paxHdrs: map[string]string{paxMtime: "1.0000005"},
684 header: &Header{ModTime: time.Unix(-1, 500)},
685 paxHdrs: map[string]string{paxMtime: "-0.9999995"},
686 formats: FormatPAX | FormatGNU,
688 header: &Header{ModTime: time.Unix(-1, 500), Format: FormatGNU},
689 paxHdrs: map[string]string{paxMtime: "-0.9999995"},
692 header: &Header{AccessTime: time.Unix(0, 0)},
693 paxHdrs: map[string]string{paxAtime: "0"},
694 formats: FormatPAX | FormatGNU,
696 header: &Header{AccessTime: time.Unix(0, 0), Format: FormatUSTAR},
697 paxHdrs: map[string]string{paxAtime: "0"},
698 formats: FormatUnknown,
700 header: &Header{AccessTime: time.Unix(0, 0), Format: FormatPAX},
701 paxHdrs: map[string]string{paxAtime: "0"},
704 header: &Header{AccessTime: time.Unix(0, 0), Format: FormatGNU},
705 paxHdrs: map[string]string{paxAtime: "0"},
708 header: &Header{AccessTime: time.Unix(-123, 0)},
709 paxHdrs: map[string]string{paxAtime: "-123"},
710 formats: FormatPAX | FormatGNU,
712 header: &Header{AccessTime: time.Unix(-123, 0), Format: FormatPAX},
713 paxHdrs: map[string]string{paxAtime: "-123"},
716 header: &Header{ChangeTime: time.Unix(123, 456)},
717 paxHdrs: map[string]string{paxCtime: "123.000000456"},
718 formats: FormatPAX | FormatGNU,
720 header: &Header{ChangeTime: time.Unix(123, 456), Format: FormatUSTAR},
721 paxHdrs: map[string]string{paxCtime: "123.000000456"},
722 formats: FormatUnknown,
724 header: &Header{ChangeTime: time.Unix(123, 456), Format: FormatGNU},
725 paxHdrs: map[string]string{paxCtime: "123.000000456"},
728 header: &Header{ChangeTime: time.Unix(123, 456), Format: FormatPAX},
729 paxHdrs: map[string]string{paxCtime: "123.000000456"},
732 header: &Header{Name: "foo/", Typeflag: TypeDir},
733 formats: FormatUSTAR | FormatPAX | FormatGNU,
735 header: &Header{Name: "foo/", Typeflag: TypeReg},
736 formats: FormatUnknown,
738 header: &Header{Name: "foo/", Typeflag: TypeSymlink},
739 formats: FormatUSTAR | FormatPAX | FormatGNU,
742 for i, v := range vectors {
743 formats, paxHdrs, err := v.header.allowedFormats()
744 if formats != v.formats {
745 t.Errorf("test %d, allowedFormats(): got %v, want %v", i, formats, v.formats)
747 if formats&FormatPAX > 0 && !reflect.DeepEqual(paxHdrs, v.paxHdrs) && !(len(paxHdrs) == 0 && len(v.paxHdrs) == 0) {
748 t.Errorf("test %d, allowedFormats():\ngot %v\nwant %s", i, paxHdrs, v.paxHdrs)
750 if (formats != FormatUnknown) && (err != nil) {
751 t.Errorf("test %d, unexpected error: %v", i, err)
753 if (formats == FormatUnknown) && (err == nil) {
754 t.Errorf("test %d, got nil-error, want non-nil error", i)
759 func Benchmark(b *testing.B) {
765 vectors := []struct {
771 &Header{Name: "bar", Mode: 0640, Size: int64(3)},
774 &Header{Name: "world", Mode: 0640, Size: int64(5)},
780 &Header{Name: "bar", Mode: 0640, Size: int64(3), Devmajor: -1},
783 &Header{Name: "world", Mode: 0640, Size: int64(5), Devmajor: -1},
789 &Header{Name: "bar", Mode: 0640, Size: int64(3), Xattrs: map[string]string{"foo": "bar"}},
792 &Header{Name: "world", Mode: 0640, Size: int64(5), Xattrs: map[string]string{"foo": "bar"}},
797 b.Run("Writer", func(b *testing.B) {
798 for _, v := range vectors {
799 b.Run(v.label, func(b *testing.B) {
801 for i := 0; i < b.N; i++ {
802 // Writing to io.Discard because we want to
803 // test purely the writer code and not bring in disk performance into this.
804 tw := NewWriter(io.Discard)
805 for _, file := range v.files {
806 if err := tw.WriteHeader(file.hdr); err != nil {
807 b.Errorf("unexpected WriteHeader error: %v", err)
809 if _, err := tw.Write(file.body); err != nil {
810 b.Errorf("unexpected Write error: %v", err)
813 if err := tw.Close(); err != nil {
814 b.Errorf("unexpected Close error: %v", err)
821 b.Run("Reader", func(b *testing.B) {
822 for _, v := range vectors {
826 // Write the archive to a byte buffer.
827 tw := NewWriter(&buf)
828 for _, file := range v.files {
829 tw.WriteHeader(file.hdr)
833 b.Run(v.label, func(b *testing.B) {
835 // Read from the byte buffer.
836 for i := 0; i < b.N; i++ {
839 if _, err := tr.Next(); err != nil {
840 b.Errorf("unexpected Next error: %v", err)
842 if _, err := io.Copy(io.Discard, tr); err != nil {
843 b.Errorf("unexpected Copy error : %v", err)