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.
13 func TestBodyReadBadTrailer(t
*testing
.T
) {
15 src
: strings
.NewReader("foobar"),
16 hdr
: true, // force reading the trailer
17 r
: bufio
.NewReader(strings
.NewReader("")),
19 buf
:= make([]byte, 7)
20 n
, err
:= b
.Read(buf
[:3])
21 got
:= string(buf
[:n
])
22 if got
!= "foo" || err
!= nil {
23 t
.Fatalf(`first Read = %d (%q), %v; want 3 ("foo")`, n
, got
, err
)
26 n
, err
= b
.Read(buf
[:])
28 if got
!= "bar" || err
!= nil {
29 t
.Fatalf(`second Read = %d (%q), %v; want 3 ("bar")`, n
, got
, err
)
32 n
, err
= b
.Read(buf
[:])
35 t
.Errorf("final Read was successful (%q), expected error from trailer read", got
)