Skip to content

Commit

Permalink
Added unit tests for GetPlinkCompaibleUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Noguai committed Jan 23, 2015
1 parent e8439f5 commit 1946de9
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions GitExtensionsTest/GitCommands/Git/GitCommandHelpersTest.cs
Expand Up @@ -108,5 +108,103 @@ public void GetFullBranchNameTest()
Assert.AreEqual("refs/heads/release/2.48", GitCommandHelpers.GetFullBranchName("refs/heads/release/2.48"));
Assert.AreEqual("refs/tags/my-tag", GitCommandHelpers.GetFullBranchName("refs/tags/my-tag"));
}

[TestMethod]
public void TestGetPlinkCompatibleUrl_Incompatible()
{
// Test urls that are incompatible and need to be changed
string inUrl, expectUrl, outUrl;

// ssh urls can cause problems
inUrl = "ssh://user@example.com/path/to/project.git";
expectUrl = "user@example.com:path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(expectUrl, outUrl);

// ssh, no user
inUrl = "ssh://example.com/path/to/project.git";
expectUrl = "example.com:path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(expectUrl, outUrl);
}

[TestMethod]
public void TestGetPlinkCompatibleUrl_Compatible()
{
// Test urls that are already compatible, these shouldn't be changed
string inUrl, outUrl;

// ssh in compatible form
inUrl = "git@github.com:gitextensions/gitextensions.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// ssh in compatible form, no user
inUrl = "example.org:some/path/to/repo.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);
}

[TestMethod]
public void TestGetPlinkCompatibleUrl_NoPlink()
{
// Test urls that are no valid uris, these should be ignored
string inUrl, outUrl;

// git protocol does not have authentication
inUrl = "git://server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// git protocol, different port
inUrl = "git://server:123/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// we don't need plink for http
inUrl = "http://user@server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// http, different port
inUrl = "http://user@server:123/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// http, no user
inUrl = "http://server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// we don't need plink for https
inUrl = "https://user@server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// https, different port
inUrl = "https://user@server:123/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

// https, no user
inUrl = "https://server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);
}

[TestMethod]
public void TestGetPlinkCompatibleUrl_Invalid()
{
// Test urls that are no valid uris, these should be ignored
string inUrl, outUrl;

inUrl = "foo://server/path/to/project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);

inUrl = @"ssh:\\server\path\to\project.git";
outUrl = GitCommandHelpers.GetPlinkCompatibleUrl(inUrl);
Assert.AreEqual(inUrl, outUrl);
}
}
}

0 comments on commit 1946de9

Please sign in to comment.