diff options
author | Christian Kamm <mail@ckamm.de> | 2017-06-14 13:03:40 +0300 |
---|---|---|
committer | Christian Kamm <mail@ckamm.de> | 2017-06-15 14:53:57 +0300 |
commit | d50d8b86cf135dff833679b073406e4bdd6deae6 (patch) | |
tree | 42c969a9ea26115febd1b509b1369f934b33f6fb | |
parent | b28e06608c0f6d9e82bc8b1418f2f516e7347692 (diff) |
SyncEngineTest: Add network override
This is useful for monitoring what kind of network requests are
sent to the fake server. Such as "did this sync cause an upload?"
and "was there a propfind for this path?". It can also inject
custom replies.
-rw-r--r-- | test/syncenginetestutils.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index fe4676821..ee15d8e33 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -706,10 +706,17 @@ public: class FakeQNAM : public QNetworkAccessManager { +public: + using Override = std::function<QNetworkReply *(Operation, const QNetworkRequest &)>; + +private: FileInfo _remoteRootFileInfo; FileInfo _uploadFileInfo; // maps a path to an HTTP error QHash<QString, int> _errorPaths; + // monitor requests and optionally provide custom replies + Override _override; + public: FakeQNAM(FileInfo initialRoot) : _remoteRootFileInfo{std::move(initialRoot)} { } FileInfo ¤tRemoteState() { return _remoteRootFileInfo; } @@ -717,6 +724,8 @@ public: QHash<QString, int> &errorPaths() { return _errorPaths; } + void setOverride(const Override &override) { _override = override; } + protected: QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) { @@ -728,8 +737,13 @@ protected: bool isUpload = request.url().path().startsWith(sUploadUrl.path()); FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo; + if (_override) { + if (auto reply = _override(op, request)) + return reply; + } + auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute); - if (verb == QLatin1String("PROPFIND")) + if (verb == "PROPFIND") // Ignore outgoingData always returning somethign good enough, works for now. return new FakePropfindReply{info, op, request, this}; else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation) @@ -825,6 +839,7 @@ public: void clear() { _qnam->errorPaths().clear(); } }; ErrorList serverErrorPaths() { return {_fakeQnam}; } + void setServerOverride(const FakeQNAM::Override &override) { _fakeQnam->setOverride(override); } QString localPath() const { // SyncEngine wants a trailing slash |