Donut now tests amount written should match expected amount to write

This commit is contained in:
Frederick F. Kautz IV 2015-02-28 16:09:52 -08:00
parent d3d1205eb1
commit ddc7cf835e
2 changed files with 11 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package v1
import (
"bytes"
"encoding/binary"
"errors"
"io"
"github.com/minio-io/minio/pkg/utils/checksum/crc32c"
@ -101,10 +102,13 @@ func Write(target io.Writer, reader io.Reader, length uint64) error {
checksumChannel := make(chan checksumValue)
go generateChecksum(sumReader, checksumChannel)
teeReader := io.TeeReader(reader, sumWriter)
_, err = io.Copy(target, teeReader)
dataLength, err := io.Copy(target, teeReader)
if err != nil {
return err
}
if uint64(dataLength) != length {
return errors.New("Specified data length and amount written mismatched")
}
sumWriter.Close()
dataChecksum := <-checksumChannel
if dataChecksum.err != nil {

View File

@ -124,3 +124,9 @@ func (s *MySuite) TestSingleWrite(c *C) {
// ensure no extra data is in the file
c.Assert(testBuffer.Len(), Equals, 0)
}
func (s *MySuite) TestLengthMismatchInWrite(c *C) {
var testData bytes.Buffer
err := Write(&testData, bytes.NewBufferString("hello, world"), 5)
c.Assert(err, Not(IsNil))
}