File indexing completed on 2024-12-01 04:35:28

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "serverinfotest.h"
0008 #include "ruqola_autotest_helper.h"
0009 #include "serverinfo.h"
0010 
0011 QTEST_GUILESS_MAIN(ServerInfoTest)
0012 
0013 ServerInfoTest::ServerInfoTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void ServerInfoTest::shouldHaveDefaultValues()
0019 {
0020     ServerInfo w;
0021     QVERIFY(w.arch().isEmpty());
0022     QVERIFY(w.commitAuthor().isEmpty());
0023     QVERIFY(w.platform().isEmpty());
0024     QVERIFY(w.version().isEmpty());
0025     QCOMPARE(w.numberOfCpu(), -1);
0026 
0027     QVERIFY(w.commitAuthor().isEmpty());
0028     QVERIFY(w.commitBranch().isEmpty());
0029     QVERIFY(w.commitTag().isEmpty());
0030     QVERIFY(w.commitSubject().isEmpty());
0031     QVERIFY(w.commitHash().isEmpty());
0032 
0033     QVERIFY(w.osRelease().isEmpty());
0034     QVERIFY(w.nodeVersion().isEmpty());
0035     // TODO
0036 }
0037 
0038 void ServerInfoTest::shouldLoadServerInfo_data()
0039 {
0040     QTest::addColumn<QString>("fileName");
0041     QTest::addColumn<ServerInfo>("serverInfo");
0042     {
0043         ServerInfo info;
0044         info.setNumberOfCpu(2);
0045         info.setArch(QStringLiteral("x64"));
0046         info.setPlatform(QStringLiteral("linux"));
0047         info.setVersion(QStringLiteral("3.10.0"));
0048         info.setCommitAuthor(QStringLiteral("Diego Sampaio"));
0049         info.setCommitBranch(QStringLiteral("HEAD"));
0050         info.setCommitTag(QStringLiteral("3.10.0"));
0051         info.setCommitSubject(QStringLiteral("Merge pull request #19982 from RocketChat/release-3.10.0"));
0052         info.setCommitHash(QStringLiteral("3a13cead22bfc1100c5b89069498919473c84195"));
0053         info.setOsRelease(QStringLiteral("5.4.0-1032-azure"));
0054         info.setNodeVersion(QStringLiteral("v12.18.4"));
0055 
0056         QTest::addRow("default") << QStringLiteral("serverinfo") << info;
0057     }
0058 }
0059 
0060 void ServerInfoTest::shouldLoadServerInfo()
0061 {
0062     QFETCH(QString, fileName);
0063     QFETCH(ServerInfo, serverInfo);
0064     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/serverinfo/") + fileName + QLatin1String(".json");
0065     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0066 
0067     ServerInfo r;
0068     r.parseServerInfo(obj);
0069     const bool result = (r == serverInfo);
0070     if (!result) {
0071         qDebug() << "result " << r;
0072         qDebug() << "expected " << serverInfo;
0073     }
0074     QVERIFY(result);
0075 }
0076 
0077 #include "moc_serverinfotest.cpp"