mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Merge pull request #3460 from nextcloud/feature/unit-test-move-custom-root
Add unit test for move custom remote root
This commit is contained in:
commit
90244380aa
@ -1083,7 +1083,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
|
||||
} else {
|
||||
// We must query the server to know if the etag has not changed
|
||||
_pendingAsyncJobs++;
|
||||
QString serverOriginalPath = _discoveryData->_remoteFolder +_discoveryData->adjustRenamedPath(originalPath, SyncFileItem::Down);
|
||||
QString serverOriginalPath = _discoveryData->_remoteFolder + _discoveryData->adjustRenamedPath(originalPath, SyncFileItem::Down);
|
||||
if (base.isVirtualFile() && isVfsWithSuffix())
|
||||
chopVirtualFileSuffix(serverOriginalPath);
|
||||
auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this);
|
||||
|
||||
@ -288,7 +288,11 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces
|
||||
auto writeFileResponse = [&](const FileInfo &fileInfo) {
|
||||
xml.writeStartElement(davUri, QStringLiteral("response"));
|
||||
|
||||
xml.writeTextElement(davUri, QStringLiteral("href"), prefix + QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.path(), "/")));
|
||||
QString url = prefix + QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.path(), "/"));
|
||||
if (!url.endsWith(QChar('/'))) {
|
||||
url.append(QChar('/'));
|
||||
}
|
||||
xml.writeTextElement(davUri, QStringLiteral("href"), url);
|
||||
xml.writeStartElement(davUri, QStringLiteral("propstat"));
|
||||
xml.writeStartElement(davUri, QStringLiteral("prop"));
|
||||
|
||||
@ -832,7 +836,7 @@ QNetworkReply *FakeQNAM::createRequest(QNetworkAccessManager::Operation op, cons
|
||||
return reply;
|
||||
}
|
||||
|
||||
FakeFolder::FakeFolder(const FileInfo &fileTemplate)
|
||||
FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo, const QString &remotePath)
|
||||
: _localModifier(_tempDir.path())
|
||||
{
|
||||
// Needs to be done once
|
||||
@ -841,7 +845,11 @@ FakeFolder::FakeFolder(const FileInfo &fileTemplate)
|
||||
|
||||
QDir rootDir { _tempDir.path() };
|
||||
qDebug() << "FakeFolder operating on" << rootDir;
|
||||
toDisk(rootDir, fileTemplate);
|
||||
if (localFileInfo) {
|
||||
toDisk(rootDir, *localFileInfo);
|
||||
} else {
|
||||
toDisk(rootDir, fileTemplate);
|
||||
}
|
||||
|
||||
_fakeQnam = new FakeQNAM(fileTemplate);
|
||||
_account = OCC::Account::create();
|
||||
@ -851,7 +859,7 @@ FakeFolder::FakeFolder(const FileInfo &fileTemplate)
|
||||
_account->setServerVersion(QStringLiteral("10.0.0"));
|
||||
|
||||
_journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + QStringLiteral(".sync_test.db"));
|
||||
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), QString(), _journalDb.get());
|
||||
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), remotePath, _journalDb.get());
|
||||
// Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
|
||||
_syncEngine->excludedFiles().addManualExclude(QStringLiteral("]*.~*"));
|
||||
|
||||
@ -1034,5 +1042,4 @@ FakeReply::FakeReply(QObject *parent)
|
||||
setRawHeader(QByteArrayLiteral("Date"), QDateTime::currentDateTimeUtc().toString(Qt::RFC2822Date).toUtf8());
|
||||
}
|
||||
|
||||
FakeReply::~FakeReply()
|
||||
= default;
|
||||
FakeReply::~FakeReply() = default;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "account.h"
|
||||
#include "common/result.h"
|
||||
#include "creds/abstractcredentials.h"
|
||||
#include "logger.h"
|
||||
#include "filesystem.h"
|
||||
@ -435,7 +436,7 @@ class FakeFolder
|
||||
std::unique_ptr<OCC::SyncEngine> _syncEngine;
|
||||
|
||||
public:
|
||||
FakeFolder(const FileInfo &fileTemplate);
|
||||
FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInfo> &localFileInfo = {}, const QString &remotePath = {});
|
||||
|
||||
void switchToVfs(QSharedPointer<OCC::Vfs> vfs);
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
#include "common/result.h"
|
||||
#include "syncenginetestutils.h"
|
||||
#include <syncengine.h>
|
||||
|
||||
@ -83,6 +84,37 @@ class TestSyncMove : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testMoveCustomRemoteRoot()
|
||||
{
|
||||
FileInfo subFolder(QStringLiteral("AS"), { { QStringLiteral("f1"), 4 } });
|
||||
FileInfo folder(QStringLiteral("A"), { subFolder });
|
||||
FileInfo fileInfo({}, { folder });
|
||||
|
||||
FakeFolder fakeFolder(fileInfo, folder, QStringLiteral("/A"));
|
||||
auto &localModifier = fakeFolder.localModifier();
|
||||
|
||||
OperationCounter counter;
|
||||
fakeFolder.setServerOverride(counter.functor());
|
||||
|
||||
// Move file and then move it back again
|
||||
{
|
||||
counter.reset();
|
||||
localModifier.rename(QStringLiteral("AS/f1"), QStringLiteral("f1"));
|
||||
|
||||
ItemCompletedSpy completeSpy(fakeFolder);
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
|
||||
QCOMPARE(counter.nGET, 0);
|
||||
QCOMPARE(counter.nPUT, 0);
|
||||
QCOMPARE(counter.nMOVE, 1);
|
||||
QCOMPARE(counter.nDELETE, 0);
|
||||
|
||||
QVERIFY(itemSuccessful(completeSpy, "f1", CSYNC_INSTRUCTION_RENAME));
|
||||
QVERIFY(fakeFolder.currentRemoteState().find("A/f1"));
|
||||
QVERIFY(!fakeFolder.currentRemoteState().find("A/AS/f1"));
|
||||
}
|
||||
}
|
||||
|
||||
void testRemoteChangeInMovedFolder()
|
||||
{
|
||||
// issue #5192
|
||||
|
||||
Loading…
Reference in New Issue
Block a user