Last active
August 29, 2015 14:02
-
-
Save aybabtme/f5460165788de480350a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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