Adapt mocking to latest changes

* Cover all required requests so the connection can be
  established without errors
* Add more events to test error handling
* Fix definition of LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED
  after syncthingconnection.cpp split
This commit is contained in:
Martchus 2018-11-03 20:44:11 +01:00
parent 930691ebdc
commit dcbc19cf8c
10 changed files with 158 additions and 15 deletions

View File

@ -95,7 +95,8 @@ if(SYNCTHING_CONNECTION_MOCKED)
syncthingconnectionmockhelpers.cpp
)
set_property(
SOURCE syncthingconnection_requests.cpp
SOURCE syncthingconnection.cpp
syncthingconnection_requests.cpp
syncthingconnectionmockhelpers.h
syncthingconnectionmockhelpers.cpp
APPEND PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_CONNECTION_MOCKED

View File

@ -3,6 +3,10 @@
#include "./syncthingconnectionsettings.h"
#include "./utils.h"
#ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED
#include "./syncthingconnectionmockhelpers.h"
#endif
#include <c++utilities/conversion/stringconversion.h>
#include <QAuthenticator>
@ -103,6 +107,7 @@ SyncthingConnection::SyncthingConnection(const QString &syncthingUrl, const QByt
m_autoReconnectTimer.setTimerType(Qt::VeryCoarseTimer);
m_autoReconnectTimer.setInterval(SyncthingConnectionSettings::defaultReconnectInterval);
QObject::connect(&m_autoReconnectTimer, &QTimer::timeout, this, &SyncthingConnection::autoReconnect);
#ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED
setupTestData();
#endif

View File

@ -27,15 +27,8 @@ namespace Data {
*/
namespace TestData {
static bool initialized = false;
static string config;
static string status;
static string folderStats;
static string deviceStats;
static string errors;
static string folderStatus;
static string folderStatus2;
static string connections;
static string events[6];
static string config, status, folderStats, deviceStats, errors, folderStatus, folderStatus2, folderStatus3, pullErrors, connections, version, empty;
static string events[7];
} // namespace TestData
/*!
@ -71,10 +64,11 @@ void setupTestData()
const TestApplication testApp(0, nullptr);
// read mock files for REST-API
const char *const fileNames[]
= { "config", "status", "folderstats", "devicestats", "errors", "folderstatus-01", "folderstatus-02", "connections" };
const char *const fileNames[] = { "config", "status", "folderstats", "devicestats", "errors", "folderstatus-01", "folderstatus-02",
"folderstatus-03", "pullerrors-01", "connections", "version", "empty" };
const char *const *fileName = fileNames;
for (string *testDataVariable : { &config, &status, &folderStats, &deviceStats, &errors, &folderStatus, &folderStatus2, &connections }) {
for (string *testDataVariable : { &config, &status, &folderStats, &deviceStats, &errors, &folderStatus, &folderStatus2, &folderStatus3,
&pullErrors, &connections, &version, &empty }) {
*testDataVariable = readMockFile(testApp.testFilePath(argsToString("mocks/", *fileName, ".json")));
++fileName;
}
@ -177,25 +171,38 @@ MockedReply *MockedReply::forRequest(const QString &method, const QString &path,
buffer = &folderStatus;
} else if (folder == QLatin1String("zX8xfl3ygn-")) {
buffer = &folderStatus2;
} else if (folder == QLatin1String("forever-alone")) {
buffer = &folderStatus3;
}
} else if (path == QLatin1String("folder/pullerrors")) {
const QString folder(query.queryItemValue(QStringLiteral("folder")));
if (folder == QLatin1String("GXWxf-3zgnU")) {
buffer = &pullErrors;
}
} else if (path == QLatin1String("system/connections")) {
buffer = &connections;
} else if (path == QLatin1String("system/version")) {
buffer = &version;
} else if (path == QLatin1String("events")) {
buffer = &events[s_eventIndex];
cerr << "mocking: at event index " << s_eventIndex << endl;
// "emit" the first event almost immediately and further events each 2.5 seconds
switch (s_eventIndex) {
case 0:
delay = 200;
++s_eventIndex;
break;
case 5:
case 6:
// continue emitting the last event every 10 seconds
delay = 10000;
break;
default:
delay = 2500;
delay = 2000;
++s_eventIndex;
}
} else if (path == QLatin1String("events/disk")) {
buffer = &empty;
delay = 5000;
}
}
}

View File

@ -0,0 +1 @@
[]

View File

@ -70,6 +70,20 @@
}
}
},
{
"id": 3,
"type": "FolderErrors",
"time": "2000-06-26T13:39:24.697401384+02:00",
"data": {
"errors": [
{
"error": "should be ignored",
"path": "some path"
}
],
"folder": "GXWxf-3zgnU"
}
},
{
"id": 3,
"type": "FolderErrors",

View File

@ -1,6 +1,24 @@
[
{
"id": 8,
"type": "FolderErrors",
"time": "2018-12-13T00:34:12.9876937Z",
"data": {
"errors": [
{
"error": "some error",
"path": "some file"
},
{
"error": "another error",
"path": "another file"
}
],
"folder": "zX8xfl3ygn-"
}
},
{
"id": 9,
"type": "DownloadProgress",
"time": "2018-12-13T00:34:12.9876937Z",
"data": {

View File

@ -0,0 +1,67 @@
[
{
"id": 10,
"globalID": 8,
"type": "StateChanged",
"time": "2018-12-13T00:34:12.9876937Z",
"data": {
"folder": "zX8xfl3ygn-",
"from": "error",
"duration": 0.19782869900000002,
"to": "syncing"
}
},
{
"id": 10,
"globalID": 8,
"type": "FolderSummary",
"time": "2018-12-13T00:34:12.9876937Z",
"data": {
"folder": "zX8xfl3ygn-",
"globalBytes": 24525452,
"globalDeleted": 8,
"globalFiles": 543,
"globalFolders": 3,
"localBytes": 24525452,
"localDeleted": 8,
"localFiles": 343,
"localFolders": 4,
"inSyncBytes": 13173473780,
"inSyncFiles": 42106,
"needBytes": 0,
"needFiles": 0,
"ignorePatterns": true,
"invalid": "",
"state": "syncing",
"stateChanged": "2018-12-13T00:34:12.9876937Z",
"version": 71989,
"pullErrors": 25
}
},
{
"id": 11,
"type": "FolderSummary",
"time": "2018-12-13T00:34:12.9876937Z",
"data": {
"folder": "GXWxf-3zgnU",
"summary": {
"globalBytes": 23173473780,
"globalDeleted": 2847,
"globalFiles": 82106,
"localBytes": 23173471732,
"localDeleted": 2847,
"localFiles": 82081,
"inSyncBytes": 23173473780,
"inSyncFiles": 82081,
"needBytes": 2048,
"needFiles": 25,
"ignorePatterns": true,
"invalid": "",
"state": "error",
"stateChanged": "2016-03-16T21:47:28.750853241+01:00",
"version": 71989,
"pullErrors": 25
}
}
}
]

View File

@ -0,0 +1,15 @@
{
"globalBytes": 1,
"globalDeleted": 2,
"globalFiles": 3,
"globalFolders": 4,
"localBytes": 1,
"localDeleted": 2,
"localFiles": 3,
"localFolders": 4,
"ignorePatterns": true,
"invalid": "",
"state": "idle",
"stateChanged": "2018-03-16T21:47:28.750853241+01:00",
"version": 21
}

View File

@ -0,0 +1,9 @@
{
"folder": "GXWxf-3zgnU",
"errors": [
{
"error": "open /Users/jb/src/github.com/syncthing/syncthing/test/s2/h2j/.syncthing.aslkjd.tmp: permission denied",
"path": "h2j/aslkjd"
}
]
}

View File

@ -0,0 +1,6 @@
{
"arch": "amd64",
"longVersion": "syncthing v0.10.27+3-gea8c3de (go1.4 darwin-amd64 default) jb@syno 2015-03-16 11:01:29 UTC",
"os": "darwin",
"version": "v0.10.27+3-gea8c3de"
}