Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(25)

Unified Diff: src/pkg/encoding/base64/base64_test.go

Issue 6137054: code review 6137054: encoding/base64: don't ignore underlying souce read err... (Closed)
Patch Set: diff -r 15260ef90c98 https://go.googlecode.com/hg/ Created 12 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/encoding/base64/base64.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/encoding/base64/base64_test.go
===================================================================
--- a/src/pkg/encoding/base64/base64_test.go
+++ b/src/pkg/encoding/base64/base64_test.go
@@ -6,9 +6,11 @@
import (
"bytes"
+ "errors"
"io"
"io/ioutil"
"testing"
+ "time"
)
type testpair struct {
@@ -226,3 +228,50 @@
}
}
}
+
+type nextRead struct {
+ n int // bytes to return
+ err error // error to return
+}
+
+// faultInjectReader returns data from source, rate-limited
+// and with the errors as written to nextc.
+type faultInjectReader struct {
+ source string
+ nextc <-chan nextRead
+}
+
+func (r *faultInjectReader) Read(p []byte) (int, error) {
+ nr := <-r.nextc
+ if len(p) > nr.n {
+ p = p[:nr.n]
+ }
+ n := copy(p, r.source)
+ r.source = r.source[n:]
+ return n, nr.err
+}
+
+// tests that we don't ignore errors from our underlying reader
+func TestDecoderIssue3577(t *testing.T) {
+ next := make(chan nextRead, 10)
+ wantErr := errors.New("my error")
+ next <- nextRead{5, nil}
+ next <- nextRead{10, wantErr}
+ d := NewDecoder(StdEncoding, &faultInjectReader{
+ source: "VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==", // twas brillig...
+ nextc: next,
+ })
+ errc := make(chan error)
+ go func() {
+ _, err := ioutil.ReadAll(d)
+ errc <- err
+ }()
+ select {
+ case err := <-errc:
+ if err != wantErr {
+ t.Errorf("got error %v; want %v", err, wantErr)
+ }
+ case <-time.After(5 * time.Second):
+ t.Errorf("timeout; Decoder blocked without returning an error")
+ }
+}
« no previous file with comments | « src/pkg/encoding/base64/base64.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b