File indexing completed on 2025-01-19 04:22:42

0001 /*
0002 SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "clonecommandtest.h"
0008 #include "commands/commandclone.h"
0009 #include <QTest>
0010 QTEST_MAIN(CloneCommandTest)
0011 CloneCommandTest::CloneCommandTest(QObject *parent)
0012     : QObject(parent)
0013 {
0014 }
0015 
0016 void CloneCommandTest::shouldHaveDefaultValues()
0017 {
0018     Git::CloneCommand command;
0019     QVERIFY(command.repoUrl().isEmpty());
0020     QVERIFY(command.origin().isEmpty());
0021     QVERIFY(command.localPath().isEmpty());
0022     QVERIFY(command.branch().isEmpty());
0023     QCOMPARE(command.depth(), -1);
0024     QVERIFY(!command.recursive());
0025 }
0026 
0027 void CloneCommandTest::shouldGenerateCommand_data()
0028 {
0029     QTest::addColumn<QString>("newRepoUrl");
0030     QTest::addColumn<QString>("newLocalPath");
0031     QTest::addColumn<QString>("newBranch");
0032     QTest::addColumn<QString>("newOrigin");
0033     QTest::addColumn<int>("newDepth");
0034     QTest::addColumn<bool>("newRecursive");
0035     QTest::addColumn<QStringList>("result");
0036     {
0037         const QStringList lst{QStringLiteral("clone"), QStringLiteral("--progress"), QString(), QString()};
0038         QTest::addRow("empty") << QString() << QString() << QString() << QString() << -1 << false << lst;
0039     }
0040     {
0041         const QString newRepoUrl = QStringLiteral("bla");
0042         const QStringList lst{QStringLiteral("clone"), QStringLiteral("--progress"), newRepoUrl, QString()};
0043         QTest::addRow("newRepo") << newRepoUrl << QString() << QString() << QString() << -1 << false << lst;
0044     }
0045     {
0046         const QString newRepoUrl = QStringLiteral("bla");
0047         const int depth = 5;
0048         const QStringList lst{QStringLiteral("clone"), QStringLiteral("--progress"), newRepoUrl, QString(), QStringLiteral("--depth"), QString::number(depth)};
0049         QTest::addRow("depth") << newRepoUrl << QString() << QString() << QString() << depth << false << lst;
0050     }
0051     {
0052         const QString newRepoUrl = QStringLiteral("bla");
0053         const QString newLocalPath = QStringLiteral("blo");
0054         const int depth = 5;
0055         const QStringList lst{QStringLiteral("clone"),
0056                               QStringLiteral("--progress"),
0057                               newRepoUrl,
0058                               newLocalPath,
0059                               QStringLiteral("--depth"),
0060                               QString::number(depth)};
0061         QTest::addRow("depth") << newRepoUrl << newLocalPath << QString() << QString() << depth << false << lst;
0062     }
0063 }
0064 
0065 void CloneCommandTest::shouldGenerateCommand()
0066 {
0067     QFETCH(QString, newRepoUrl);
0068     QFETCH(QString, newLocalPath);
0069     QFETCH(QString, newBranch);
0070     QFETCH(QString, newOrigin);
0071     QFETCH(int, newDepth);
0072     QFETCH(bool, newRecursive);
0073     QFETCH(QStringList, result);
0074     Git::CloneCommand command;
0075     command.setRepoUrl(newRepoUrl);
0076     command.setLocalPath(newLocalPath);
0077     command.setBranch(newBranch);
0078     command.setDepth(newDepth);
0079     command.setOrigin(newOrigin);
0080     command.setRecursive(newRecursive);
0081     QCOMPARE(command.generateArgs(), result);
0082 }