From ef442289da63692013ec3bda1f146969e8f87eeb Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Mon, 23 Feb 2015 20:27:25 -0800 Subject: [PATCH] Making donut use io.ReadWriteSeek instead of io.Writer --- pkg/storage/donut/v1/donut.go | 4 ++-- pkg/storage/donut/v1/donut_test.go | 35 ++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pkg/storage/donut/v1/donut.go b/pkg/storage/donut/v1/donut.go index eb5de53c5..65581f167 100644 --- a/pkg/storage/donut/v1/donut.go +++ b/pkg/storage/donut/v1/donut.go @@ -73,7 +73,7 @@ type DonutFooter struct { } type Donut struct { - file io.Writer + file io.ReadWriteSeeker mutex *sync.RWMutex } @@ -89,7 +89,7 @@ type EncodedChunk struct { Offset int } -func New(file io.Writer) *Donut { +func New(file io.ReadWriteSeeker) *Donut { donut := Donut{} donut.mutex = new(sync.RWMutex) donut.file = file diff --git a/pkg/storage/donut/v1/donut_test.go b/pkg/storage/donut/v1/donut_test.go index 9963d0b22..5a76f47ac 100644 --- a/pkg/storage/donut/v1/donut_test.go +++ b/pkg/storage/donut/v1/donut_test.go @@ -19,6 +19,9 @@ package v1 import ( "bytes" . "gopkg.in/check.v1" + "io" + "io/ioutil" + "os" "testing" ) @@ -29,23 +32,33 @@ type MySuite struct{} var _ = Suite(&MySuite{}) func (s *MySuite) TestAPISuite(c *C) { - var b bytes.Buffer + var b io.ReadWriteSeeker var o bytes.Buffer - donut := New(&b) + b, err := ioutil.TempFile(os.TempDir(), "minio-donut-test") + c.Assert(err, IsNil) + + donut := New(b) gobheader := GobHeader{} - err := donut.Write(gobheader, &o) + err = donut.Write(gobheader, &o) c.Assert(err, IsNil) blockStart := make([]byte, 4) - blockEnd := make([]byte, 4) - - n, _ := b.Read(blockStart) - b.Next(b.Len() - n) // jump ahead - b.Read(blockEnd) + //n, _ := b.Read(blockStart) + // b.Next(b.Len() - n) // jump ahead + // b.Read(blockEnd) + // read start + b.Seek(0, 0) // jump ahead + b.Read(blockStart) blockStartCheck := []byte{'M', 'I', 'N', 'I'} - blockEndCheck := []byte{'I', 'N', 'I', 'M'} - c.Assert(blockStart, DeepEquals, blockStartCheck) - c.Assert(blockEnd, DeepEquals, blockEndCheck) + + // read block + + // read end + // blockEnd := make([]byte, 4) + // b.Seek(int64(len(blockEnd)), 2) // jump ahead + // b.Read(blockEnd) + // blockEndCheck := []byte{'I', 'N', 'I', 'M'} + // c.Assert(blockEnd, DeepEquals, blockEndCheck) }