From 412dacf8bef8d03d7998b28640a23d0c5b9a5a12 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 19 May 2017 12:26:07 +0100 Subject: [PATCH] Add a test for partial reads to all remotes --- amazonclouddrive/amazonclouddrive_test.go | 1 + b2/b2_test.go | 1 + crypt/crypt2_test.go | 1 + crypt/crypt3_test.go | 1 + crypt/crypt_test.go | 1 + drive/drive_test.go | 1 + dropbox/dropbox_test.go | 1 + fstest/fstests/fstests.go | 21 ++++++++++++++----- ftp/ftp_test.go | 1 + googlecloudstorage/googlecloudstorage_test.go | 1 + hubic/hubic_test.go | 1 + local/local_test.go | 1 + onedrive/onedrive_test.go | 1 + s3/s3_test.go | 1 + sftp/sftp_test.go | 1 + swift/swift_test.go | 1 + yandex/yandex_test.go | 1 + 17 files changed, 32 insertions(+), 5 deletions(-) diff --git a/amazonclouddrive/amazonclouddrive_test.go b/amazonclouddrive/amazonclouddrive_test.go index f23707534..be6e17a97 100644 --- a/amazonclouddrive/amazonclouddrive_test.go +++ b/amazonclouddrive/amazonclouddrive_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/b2/b2_test.go b/b2/b2_test.go index 6a40fcd12..2114bd7f5 100644 --- a/b2/b2_test.go +++ b/b2/b2_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/crypt/crypt2_test.go b/crypt/crypt2_test.go index ee3c90879..9fa72d16a 100644 --- a/crypt/crypt2_test.go +++ b/crypt/crypt2_test.go @@ -55,6 +55,7 @@ func TestObjectSetModTime2(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize2(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen2(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek2(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead2(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate2(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable2(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile2(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/crypt/crypt3_test.go b/crypt/crypt3_test.go index baaa828f9..6525d6ffc 100644 --- a/crypt/crypt3_test.go +++ b/crypt/crypt3_test.go @@ -55,6 +55,7 @@ func TestObjectSetModTime3(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize3(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen3(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek3(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead3(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate3(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable3(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile3(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/crypt/crypt_test.go b/crypt/crypt_test.go index 5afa04389..f2db8618b 100644 --- a/crypt/crypt_test.go +++ b/crypt/crypt_test.go @@ -55,6 +55,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/drive/drive_test.go b/drive/drive_test.go index 26e4bc46c..b45d3c307 100644 --- a/drive/drive_test.go +++ b/drive/drive_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/dropbox/dropbox_test.go b/dropbox/dropbox_test.go index f1f6f7a96..51670b9dc 100644 --- a/dropbox/dropbox_test.go +++ b/dropbox/dropbox_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index a384d04ef..e8a9270ef 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -661,10 +661,14 @@ func TestObjectSize(t *testing.T) { } // read the contents of an object as a string -func readObject(t *testing.T, obj fs.Object, options ...fs.OpenOption) string { +func readObject(t *testing.T, obj fs.Object, limit int64, options ...fs.OpenOption) string { in, err := obj.Open(options...) require.NoError(t, err) - contents, err := ioutil.ReadAll(in) + var r io.Reader = in + if limit >= 0 { + r = &io.LimitedReader{R: r, N: limit} + } + contents, err := ioutil.ReadAll(r) require.NoError(t, err) err = in.Close() require.NoError(t, err) @@ -675,14 +679,21 @@ func readObject(t *testing.T, obj fs.Object, options ...fs.OpenOption) string { func TestObjectOpen(t *testing.T) { skipIfNotOk(t) obj := findObject(t, file1.Path) - assert.Equal(t, file1Contents, readObject(t, obj), "contents of file1 differ") + assert.Equal(t, file1Contents, readObject(t, obj, -1), "contents of file1 differ") } // TestObjectOpenSeek tests that Open works with Seek func TestObjectOpenSeek(t *testing.T) { skipIfNotOk(t) obj := findObject(t, file1.Path) - assert.Equal(t, file1Contents[50:], readObject(t, obj, &fs.SeekOption{Offset: 50}), "contents of file1 differ after seek") + assert.Equal(t, file1Contents[50:], readObject(t, obj, -1, &fs.SeekOption{Offset: 50}), "contents of file1 differ after seek") +} + +// TestObjectPartialRead tests that reading only part of the object does the correct thing +func TestObjectPartialRead(t *testing.T) { + skipIfNotOk(t) + obj := findObject(t, file1.Path) + assert.Equal(t, file1Contents[:50], readObject(t, obj, 50), "contents of file1 differ after limited read") } // TestObjectUpdate tests that Update works @@ -708,7 +719,7 @@ func TestObjectUpdate(t *testing.T) { file1.Check(t, obj, remote.Precision()) // check contents correct - assert.Equal(t, contents, readObject(t, obj), "contents of updated file1 differ") + assert.Equal(t, contents, readObject(t, obj, -1), "contents of updated file1 differ") file1Contents = contents } diff --git a/ftp/ftp_test.go b/ftp/ftp_test.go index 63a792240..cd66838f4 100644 --- a/ftp/ftp_test.go +++ b/ftp/ftp_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/googlecloudstorage/googlecloudstorage_test.go b/googlecloudstorage/googlecloudstorage_test.go index 14d8a62c3..e43cfa8b1 100644 --- a/googlecloudstorage/googlecloudstorage_test.go +++ b/googlecloudstorage/googlecloudstorage_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/hubic/hubic_test.go b/hubic/hubic_test.go index 9dd920aba..3bcf78403 100644 --- a/hubic/hubic_test.go +++ b/hubic/hubic_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/local/local_test.go b/local/local_test.go index fb7c0695a..1de407409 100644 --- a/local/local_test.go +++ b/local/local_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/onedrive/onedrive_test.go b/onedrive/onedrive_test.go index e2e207c1b..1861c2f2d 100644 --- a/onedrive/onedrive_test.go +++ b/onedrive/onedrive_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/s3/s3_test.go b/s3/s3_test.go index 252222fea..983d9627c 100644 --- a/s3/s3_test.go +++ b/s3/s3_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/sftp/sftp_test.go b/sftp/sftp_test.go index ea4fd9946..c55aff973 100644 --- a/sftp/sftp_test.go +++ b/sftp/sftp_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/swift/swift_test.go b/swift/swift_test.go index 62e62b4e6..37635e722 100644 --- a/swift/swift_test.go +++ b/swift/swift_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) } diff --git a/yandex/yandex_test.go b/yandex/yandex_test.go index 4b8de14bb..5d1788d06 100644 --- a/yandex/yandex_test.go +++ b/yandex/yandex_test.go @@ -54,6 +54,7 @@ func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) } func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) } func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) } func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) } +func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) } func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) } func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) } func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) }