Add test for Chunk V2 restrictions in testchunkingng
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 28 Jul 2023 17:04:58 +0000 (01:04 +0800)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Thu, 31 Aug 2023 13:25:00 +0000 (15:25 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
test/testchunkingng.cpp

index f760051840e6d0eb1efb6d3c248fda2306d6ae73..913d9f12ef5d08fe73fdeb19f433e5bb6786e4fa 100644 (file)
@@ -5,8 +5,9 @@
  *
  */
 
-#include <QtTest>
 #include "syncenginetestutils.h"
+#include <QtTest>
+#include <owncloudpropagator.h>
 #include <syncengine.h>
 
 using namespace OCC;
@@ -54,8 +55,44 @@ class TestChunkingNG : public QObject
     Q_OBJECT
 
 private slots:
+    void testChunkV2Restrictions()
+    {
+        FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
+        fakeFolder.syncEngine().account()->setCapabilities({{"dav", QVariantMap{{"chunking", "1.0"}}}});
+
+        constexpr auto maxChunkSize = 5LL * 1000LL * 1000LL * 1000LL;
+        ::setChunkSize(fakeFolder.syncEngine(), 10LL * 1000LL * 1000LL * 1000LL);
+        QCOMPARE(fakeFolder.syncEngine().syncOptions().maxChunkSize(), maxChunkSize);
+
+        constexpr auto minChunkSize = 5 * 1000 * 1000;
+        ::setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000);
+        QCOMPARE(fakeFolder.syncEngine().syncOptions().minChunkSize(), minChunkSize);
+
+        auto hasDestinationHeader = false;
+        fakeFolder.setServerOverride(
+            [&hasDestinationHeader](const QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *const) -> QNetworkReply * {
+                if (op == QNetworkAccessManager::PutOperation) {
+                    qDebug() << "Request headers:" << request.rawHeaderList();
+                    hasDestinationHeader |= request.hasRawHeader("Destination");
+                }
+                return nullptr;
+            });
+
+        constexpr auto size = 1000 * 1000 * 1000; // 100 MB
+        ::partialUpload(fakeFolder, "A/a0", size);
 
-    void testFileUpload() {
+        QVERIFY(hasDestinationHeader);
+
+        QCOMPARE(fakeFolder.uploadState().children.count(), 1);
+        const auto chunkingId = fakeFolder.uploadState().children.first().name;
+        const auto chunkMap = fakeFolder.uploadState().children.first().children;
+        const auto firstChunkName = chunkMap.first().name;
+        const auto expectedChunkName = QString("%1").arg(1, 5, 10, QChar('0'));
+        QCOMPARE(firstChunkName, expectedChunkName);
+    }
+
+    void testFileUpload()
+    {
         FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
         fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"chunking", "1.0"} } } });
         setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000);