Git: Add tests for GitRemote

Change-Id: Ia5e0c482afa7847f5ae8dae1b15d1dabfc908e32
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2018-09-23 11:21:01 +02:00
committed by André Hartmann
parent bba2a2521b
commit 0dfb2938ed
2 changed files with 103 additions and 0 deletions

View File

@@ -1552,6 +1552,107 @@ void GitPlugin::testLogResolving()
"50a6b54c - Merge branch 'for-junio' of git://bogomips.org/git-svn",
"3587b513 - Update draft release notes to 1.8.2");
}
class RemoteTest {
public:
RemoteTest() = default;
explicit RemoteTest(const QString &url): m_url(url) {}
inline RemoteTest &protocol(const QString &p) { m_protocol = p; return *this; }
inline RemoteTest &userName(const QString &u) { m_userName = u; return *this; }
inline RemoteTest &host(const QString &h) { m_host = h; return *this; }
inline RemoteTest &port(quint16 p) { m_port = p; return *this; }
inline RemoteTest &path(const QString &p) { m_path = p; return *this; }
inline RemoteTest &isLocal(bool l) { m_isLocal = l; return *this; }
inline RemoteTest &isValid(bool v) { m_isValid = v; return *this; }
const QString m_url;
QString m_protocol;
QString m_userName;
QString m_host;
QString m_path;
quint16 m_port = 0;
bool m_isLocal = false;
bool m_isValid = true;
};
} // namespace Internal
} // namespace Git
Q_DECLARE_METATYPE(Git::Internal::RemoteTest)
namespace Git {
namespace Internal {
void GitPlugin::testGitRemote_data()
{
QTest::addColumn<RemoteTest>("rt");
QTest::newRow("http-no-user")
<< RemoteTest("http://code.qt.io/qt-creator/qt-creator.git")
.protocol("http")
.host("code.qt.io")
.path("/qt-creator/qt-creator.git");
QTest::newRow("https-with-port")
<< RemoteTest("https://code.qt.io:80/qt-creator/qt-creator.git")
.protocol("https")
.host("code.qt.io")
.port(80)
.path("/qt-creator/qt-creator.git");
QTest::newRow("ssh-user-foo")
<< RemoteTest("ssh://foo@codereview.qt-project.org:29418/qt-creator/qt-creator.git")
.protocol("ssh")
.userName("foo")
.host("codereview.qt-project.org")
.port(29418)
.path("/qt-creator/qt-creator.git");
QTest::newRow("local-file-protocol")
<< RemoteTest("file:///tmp/myrepo.git")
.protocol("file")
.path("/tmp/myrepo.git")
.isLocal(true);
QTest::newRow("local-absolute-path-unix")
<< RemoteTest("/tmp/myrepo.git")
.protocol("file")
.path("/tmp/myrepo.git")
.isLocal(true);
if (Utils::HostOsInfo::isWindowsHost()) {
QTest::newRow("local-absolute-path-unix")
<< RemoteTest("c:/git/myrepo.git")
.protocol("file")
.path("c:/git/myrepo.git")
.isLocal(true);
}
QTest::newRow("local-relative-path-children")
<< RemoteTest("./git/myrepo.git")
.protocol("file")
.path("./git/myrepo.git")
.isLocal(true);
QTest::newRow("local-relative-path-parent")
<< RemoteTest("../myrepo.git")
.protocol("file")
.path("../myrepo.git")
.isLocal(true);
}
void GitPlugin::testGitRemote()
{
QFETCH(RemoteTest, rt);
const GitRemote remote = GitRemote(rt.m_url);
if (!rt.m_isLocal) {
// local repositories must exist to be valid, so skip the test
QCOMPARE(remote.isValid, rt.m_isValid);
}
QCOMPARE(remote.protocol, rt.m_protocol);
QCOMPARE(remote.userName, rt.m_userName);
QCOMPARE(remote.host, rt.m_host);
QCOMPARE(remote.port, rt.m_port);
QCOMPARE(remote.path, rt.m_path);
}
#endif
} // namespace Internal

View File

@@ -106,6 +106,8 @@ private slots:
void testDiffFileResolving_data();
void testDiffFileResolving();
void testLogResolving();
void testGitRemote_data();
void testGitRemote();
#endif
private: