From a5b5ef99a0eb05a95d17c5a7501316a822f174e8 Mon Sep 17 00:00:00 2001 From: Andrey Kostov Date: Mon, 26 Jan 2015 13:38:51 -0800 Subject: [PATCH] Make TestContinueStreamAppend check if WriteStream can overwrite Also split the test into a small and large version. --- storagedriver/testsuites/testsuites.go | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/storagedriver/testsuites/testsuites.go b/storagedriver/testsuites/testsuites.go index c3229fcc..8002114c 100644 --- a/storagedriver/testsuites/testsuites.go +++ b/storagedriver/testsuites/testsuites.go @@ -357,14 +357,22 @@ func (suite *DriverSuite) TestReadStreamWithOffset(c *check.C) { c.Assert(err, check.Equals, io.EOF) } -// TestContinueStreamAppend tests that a stream write can be appended to without -// corrupting the data. -func (suite *DriverSuite) TestContinueStreamAppend(c *check.C) { +// TestContinueStreamAppendLarge tests that a stream write can be appended to without +// corrupting the data with a large chunk size. +func (suite *DriverSuite) TestContinueStreamAppendLarge(c *check.C) { + suite.testContinueStreamAppend(c, int64(10*1024*1024)) +} + +// TestContinueStreamAppendSmall is the same as TestContinueStreamAppendLarge, but only +// with a tiny chunk size in order to test corner cases for some cloud storage drivers. +func (suite *DriverSuite) TestContinueStreamAppendSmall(c *check.C) { + suite.testContinueStreamAppend(c, int64(32)) +} + +func (suite *DriverSuite) testContinueStreamAppend(c *check.C, chunkSize int64) { filename := randomPath(32) defer suite.StorageDriver.Delete(firstPart(filename)) - chunkSize := int64(5 * 1024 * 1024) - contentsChunk1 := randomContents(chunkSize) contentsChunk2 := randomContents(chunkSize) contentsChunk3 := randomContents(chunkSize) @@ -382,9 +390,6 @@ func (suite *DriverSuite) TestContinueStreamAppend(c *check.C) { c.Assert(fi, check.NotNil) c.Assert(fi.Size(), check.Equals, int64(len(contentsChunk1))) - if fi.Size() > chunkSize { - c.Errorf("Offset too large, %d > %d", fi.Size(), chunkSize) - } nn, err = suite.StorageDriver.WriteStream(filename, fi.Size(), bytes.NewReader(contentsChunk2)) c.Assert(err, check.IsNil) c.Assert(nn, check.Equals, int64(len(contentsChunk2))) @@ -394,9 +399,15 @@ func (suite *DriverSuite) TestContinueStreamAppend(c *check.C) { c.Assert(fi, check.NotNil) c.Assert(fi.Size(), check.Equals, 2*chunkSize) - if fi.Size() > 2*chunkSize { - c.Errorf("Offset too large, %d > %d", fi.Size(), 2*chunkSize) - } + // Test re-writing the last chunk + nn, err = suite.StorageDriver.WriteStream(filename, fi.Size()-chunkSize, bytes.NewReader(contentsChunk2)) + c.Assert(err, check.IsNil) + c.Assert(nn, check.Equals, int64(len(contentsChunk2))) + + fi, err = suite.StorageDriver.Stat(filename) + c.Assert(err, check.IsNil) + c.Assert(fi, check.NotNil) + c.Assert(fi.Size(), check.Equals, 2*chunkSize) nn, err = suite.StorageDriver.WriteStream(filename, fi.Size(), bytes.NewReader(fullContents[fi.Size():])) c.Assert(err, check.IsNil)