Procházet zdrojové kódy

Use the http logger with the unittests

This allow better debugging of the tests

Signed-off-by: Matthieu Gallien <matthieu_gallien@yahoo.fr>
Hannah von Reth před 5 roky
rodič
revize
17a1a630a4

+ 1 - 1
src/libsync/accessmanager.cpp

@@ -49,7 +49,7 @@ AccessManager::AccessManager(QObject *parent)
     setCookieJar(new CookieJar);
 }
 
-static QByteArray generateRequestId()
+QByteArray AccessManager::generateRequestId()
 {
     // Use a UUID with the starting and ending curly brace removed.
     auto uuid = QUuid::createUuid().toByteArray();

+ 2 - 0
src/libsync/accessmanager.h

@@ -32,6 +32,8 @@ class OWNCLOUDSYNC_EXPORT AccessManager : public QNetworkAccessManager
     Q_OBJECT
 
 public:
+    static QByteArray generateRequestId();
+
     AccessManager(QObject *parent = nullptr);
 
 protected:

+ 12 - 7
test/syncenginetestutils.cpp

@@ -6,6 +6,8 @@
  */
 
 #include "syncenginetestutils.h"
+#include "httplogger.h"
+#include "accessmanager.h"
 
 
 #include <memory>
@@ -803,27 +805,30 @@ QNetworkReply *FakeQNAM::createRequest(QNetworkAccessManager::Operation op, cons
     bool isUpload = request.url().path().startsWith(sUploadUrl.path());
     FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo;
 
+    auto newRequest = request;
+    newRequest.setRawHeader("X-Request-ID", OCC::AccessManager::generateRequestId());
     auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute);
     FakeReply *reply = nullptr;
     if (verb == QLatin1String("PROPFIND"))
         // Ignore outgoingData always returning somethign good enough, works for now.
-        reply = new FakePropfindReply { info, op, request, this };
+        reply = new FakePropfindReply { info, op, newRequest, this };
     else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation)
-        reply = new FakeGetReply { info, op, request, this };
+        reply = new FakeGetReply { info, op, newRequest, this };
     else if (verb == QLatin1String("PUT") || op == QNetworkAccessManager::PutOperation)
-        reply = new FakePutReply { info, op, request, outgoingData->readAll(), this };
+        reply = new FakePutReply { info, op, newRequest, outgoingData->readAll(), this };
     else if (verb == QLatin1String("MKCOL"))
-        reply = new FakeMkcolReply { info, op, request, this };
+        reply = new FakeMkcolReply { info, op, newRequest, this };
     else if (verb == QLatin1String("DELETE") || op == QNetworkAccessManager::DeleteOperation)
-        reply = new FakeDeleteReply { info, op, request, this };
+        reply = new FakeDeleteReply { info, op, newRequest, this };
     else if (verb == QLatin1String("MOVE") && !isUpload)
-        reply = new FakeMoveReply { info, op, request, this };
+        reply = new FakeMoveReply { info, op, newRequest, this };
     else if (verb == QLatin1String("MOVE") && isUpload)
-        reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, request, this };
+        reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, newRequest, this };
     else {
         qDebug() << verb << outgoingData;
         Q_UNREACHABLE();
     }
+    OCC::HttpLogger::logRequest(reply, op, outgoingData);
     return reply;
 }