Skip to content

Instantly share code, notes, and snippets.

@aybabtme
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aybabtme/f5460165788de480350a to your computer and use it in GitHub Desktop.
Save aybabtme/f5460165788de480350a to your computer and use it in GitHub Desktop.
// Example usage:
// Triggers an io.ErrUnexpectedEOF on the last read
func TestCanDiffWhenOldlistIsCorrupted(t *testing.T) {
log.SetOutput(testwriter(t)) // log to testing.Log
oldKeys := []s3.Key{{ETag: "1"}, {ETag: "3"}}
newKeys := []s3.Key{{ETag: "1"}, {ETag: "2"}, {ETag: "3"}}
want := []s3.Key{{ETag: "2"}}
oldList := encodeKeys(oldKeys)
newList := encodeKeys(newKeys)
errOldList := lastErrReader(oldList, io.ErrUnexpectedEOF)
testDiffReaders(t, errOldList, newList, want)
}
// io.Reader implementer
type reader func(p []byte) (int, error)
func (r reader) Read(p []byte) (int, error) { return r(p) }
func lastErrReader(r io.Reader, lastReadErr error) io.Reader {
return reader(func(p []byte) (int, error) {
n, err := r.Read(p)
if err == io.EOF {
return n, lastReadErr
}
return n, err
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment