-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wip: Implement test for connection validator
- Loading branch information
1 parent
8d088ee
commit 4c90270
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"installed": true, | ||
"maintenance": @{maintenance}, | ||
"needsDbUpgrade": false, | ||
"version": "10.11.0.0", | ||
"versionstring": "10.11.0", | ||
"edition": "Community", | ||
"productname": "Infinite Scale", | ||
"product": "Infinite Scale", | ||
"productversion": "4.0.5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) by Hannah von Reth <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
*/ | ||
|
||
#include <QtTest> | ||
|
||
#include "gui/connectionvalidator.h" | ||
#include "libsync/abstractnetworkjob.h" | ||
|
||
#include "testutils/syncenginetestutils.h" | ||
#include "testutils/testutils.h" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
using namespace OCC; | ||
|
||
class TestConnectionValidator : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
// we can't use QMap direclty with QFETCH | ||
using Values = QMap<QString, QString>; | ||
auto getPayload(const QString &payloadName) | ||
{ | ||
QFile f(QStringLiteral(SOURCEDIR "/test/testconnectionvalidator/%1").arg(payloadName)); | ||
Q_ASSERT(f.open(QIODevice::ReadOnly)); | ||
return f.readAll(); | ||
} | ||
|
||
auto getPayloadTemplated(const QString &payloadName, const QMap<QString, QString> &values) | ||
{ | ||
return Utility::renderTemplate(QString::fromUtf8(getPayload(payloadName)), values).toUtf8(); | ||
} | ||
|
||
private Q_SLOTS: | ||
|
||
|
||
void initTestCase() { AbstractNetworkJob::httpTimeout = 1s; } | ||
|
||
void testStatusPhp_data() | ||
{ | ||
QTest::addColumn<Values>("values"); | ||
QTest::addColumn<ConnectionValidator::Status>("status"); | ||
QTest::addColumn<std::chrono::seconds>("delay"); | ||
|
||
QTest::newRow("success") << Values{{QStringLiteral("maintenance"), QStringLiteral("false")}} << ConnectionValidator::Connected << 0s; | ||
QTest::newRow("maintenance") << Values{{QStringLiteral("maintenance"), QStringLiteral("true")}} << ConnectionValidator::MaintenanceMode << 0s; | ||
QTest::newRow("timeout") << Values{{QStringLiteral("maintenance"), QStringLiteral("false")}} << ConnectionValidator::Timeout << 60s; | ||
} | ||
|
||
void testStatusPhp() | ||
{ | ||
QFETCH(Values, values); | ||
QFETCH(ConnectionValidator::Status, status); | ||
QFETCH(std::chrono::seconds, delay); | ||
|
||
FakeFolder fakeFolder({}); | ||
|
||
fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { | ||
const auto path = request.url().path(); | ||
if (op == QNetworkAccessManager::GetOperation) { | ||
if (path.endsWith(QLatin1String("status.php"))) { | ||
return new DelayedReply<FakePayloadReply>(delay, op, request, getPayloadTemplated(QStringLiteral("status.php.json.in"), values), this); | ||
} | ||
} | ||
return nullptr; | ||
}); | ||
|
||
ConnectionValidator val(fakeFolder.account()); | ||
val.checkServer(ConnectionValidator::ValidationMode::ValidateServer); | ||
|
||
QSignalSpy spy(&val, &ConnectionValidator::connectionResult); | ||
QVERIFY(spy.wait(60s)); | ||
QCOMPARE(spy.first().first().value<ConnectionValidator::Status>(), status); | ||
} | ||
}; | ||
|
||
QTEST_MAIN(TestConnectionValidator) | ||
#include "testconnectionvalidator.moc" |