forked from dotnet/sourcelink
/
TranslateRepositoryUrlsTests.cs
51 lines (45 loc) · 2.38 KB
/
TranslateRepositoryUrlsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See
// License.txt in the project root for license information.
using System.Linq;
using TestUtilities;
using Xunit;
using static TestUtilities.KeyValuePairUtils;
namespace Microsoft.SourceLink.GitWeb.UnitTests
{
public class TranslateRepositoryUrlsTests
{
[Fact]
public void Translate()
{
var engine = new MockEngine();
var task = new TranslateRepositoryUrls()
{
BuildEngine = engine,
RepositoryUrl = "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git",
IsSingleProvider = true,
SourceRoots = new[]
{
new MockItem("/1/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git")),
new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git")),
new MockItem("/2/", KVP("SourceControl", "git"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git")),
new MockItem("/2/", KVP("SourceControl", "tfvc"), KVP("ScmRepositoryUrl", "ssh://git@src.intranet.company2.com/root_dir_name/sub_dirs/reponame.git")),
},
Hosts = new[]
{
new MockItem("src.intranet.company1.com")
}
};
bool result = task.Execute();
AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log);
AssertEx.AreEqual("ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git", task.TranslatedRepositoryUrl);
AssertEx.Equal(new[]
{
"ssh://git@src.intranet.company.com/root_dir_name/sub_dirs/reponame.git",
"ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git",
"ssh://git@src.intranet.company1.com/root_dir_name/sub_dirs/reponame.git",
"ssh://git@src.intranet.company2.com/root_dir_name/sub_dirs/reponame.git",
}, task.TranslatedSourceRoots.Select(r => r.GetMetadata("ScmRepositoryUrl")));
Assert.True(result);
}
}
}