From 0dfb2938edb1be3ef4ccea3e5ccc81c66190a247 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 23 Sep 2018 11:21:01 +0200 Subject: [PATCH] Git: Add tests for GitRemote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia5e0c482afa7847f5ae8dae1b15d1dabfc908e32 Reviewed-by: André Hartmann Reviewed-by: Orgad Shaneh --- src/plugins/git/gitplugin.cpp | 101 ++++++++++++++++++++++++++++++++++ src/plugins/git/gitplugin.h | 2 + 2 files changed, 103 insertions(+) diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 87aac67ef09..6d5001ece74 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -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("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 diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index 8722cc058d8..fd334ab89c3 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -106,6 +106,8 @@ private slots: void testDiffFileResolving_data(); void testDiffFileResolving(); void testLogResolving(); + void testGitRemote_data(); + void testGitRemote(); #endif private: