Skip to content

Commit 46f8cad

Browse files
dfev77RussKie
authored andcommitted
(split from main repo) Gerrit: fix server version parsing (#7559)
* Gerrit: add configuration for gerrit version Connecting to gerrit and retrieving configuration requires too many configurations to work properly due to possible configuration combinations (api port, http/https, etc.). Instead just allow the user to configure the desired Gerrit version. Extract code that is dependent on Gerrit version into separate classes (list of publish types and logic for composing command) in order to be able to test it. * Gerrit: Don't close window is unsuccessful So that user can change values and retry
0 parents  commit 46f8cad

File tree

5 files changed

+234
-0
lines changed

5 files changed

+234
-0
lines changed

GerritTests.csproj

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectGuid>{02A5CF27-302A-48FA-9FFD-E9A2C341FAE3}</ProjectGuid>
11+
<OutputType>Library</OutputType>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<RootNamespace>GerritTests</RootNamespace>
14+
<AssemblyName>GerritTests</AssemblyName>
15+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
16+
<RuntimeIdentifier>win</RuntimeIdentifier>
17+
<FileAlignment>512</FileAlignment>
18+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
19+
<TestProjectType>UnitTest</TestProjectType>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
<CodeAnalysisRuleSet>..\..\..\GitExtensionsTest.ruleset</CodeAnalysisRuleSet>
30+
<DocumentationFile>bin\Debug\GerritTests.xml</DocumentationFile>
31+
</PropertyGroup>
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
33+
<DebugType>pdbonly</DebugType>
34+
<Optimize>true</Optimize>
35+
<OutputPath>bin\Release\</OutputPath>
36+
<DefineConstants>TRACE</DefineConstants>
37+
<ErrorReport>prompt</ErrorReport>
38+
<WarningLevel>4</WarningLevel>
39+
<CodeAnalysisRuleSet>..\..\..\GitExtensionsTest.ruleset</CodeAnalysisRuleSet>
40+
<DocumentationFile>bin\Release\GerritTests.xml</DocumentationFile>
41+
</PropertyGroup>
42+
<ItemGroup>
43+
<Reference Include="System" />
44+
<Reference Include="System" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Server\CommandBuilderWithPrivateSupportTests.cs" />
50+
<Compile Include="Server\CommandBuilderWithDraftSupportTests.cs" />
51+
<Compile Include="Server\GerritCapabilityTests.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<None Include="Properties\AssemblyInfo.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<PackageReference Include="FluentAssertions">
58+
<Version>5.2.0</Version>
59+
</PackageReference>
60+
<PackageReference Include="NUnit">
61+
<Version>3.10.1</Version>
62+
</PackageReference>
63+
<PackageReference Include="NUnit3TestAdapter">
64+
<Version>3.10.0</Version>
65+
</PackageReference>
66+
</ItemGroup>
67+
<ItemGroup>
68+
<ProjectReference Include="..\..\..\Plugins\Gerrit\Gerrit.csproj">
69+
<Project>{ec6988f6-0e8e-42d2-8e41-e562c5fb65bc}</Project>
70+
<Name>Gerrit</Name>
71+
</ProjectReference>
72+
<ProjectReference Include="..\..\..\ResourceManager\ResourceManager.csproj">
73+
<Project>{D3440FD7-AFC5-4351-8741-6CDBF15CE944}</Project>
74+
<Name>ResourceManager</Name>
75+
</ProjectReference>
76+
</ItemGroup>
77+
<ItemGroup />
78+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
79+
</Project>

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("GerritTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("GerritTests")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("2f8f55f7-c82f-44fc-ab52-9d0c692996fc")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Gerrit.Server;
7+
using NUnit.Framework;
8+
9+
namespace GerritTests.Server
10+
{
11+
public static class CommandBuilderWithDraftSupportTests
12+
{
13+
[TestCase("a, b, c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
14+
[TestCase("a|b|c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
15+
[TestCase("a b c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
16+
[TestCase("a; b;c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
17+
[TestCase("q", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=q")]
18+
[TestCase("", "fix-7521", ExpectedResult = "refs/for/fix-7521")]
19+
[TestCase(null, "fix-7521", ExpectedResult = "refs/for/fix-7521")]
20+
public static string Build_WithReviewers_splits_reviewrs_and_builds_expected_command(string reviewer, string branch)
21+
{
22+
var sut = new CommandBuilderWithDraftSupport();
23+
return sut.WithReviewers(reviewer).Build(branch);
24+
}
25+
26+
[Test(ExpectedResult = "refs/drafts/master%r=a")]
27+
public static string Build_when_publishtype_is_drafts_builds_expected_command()
28+
{
29+
var sut = new CommandBuilderWithDraftSupport();
30+
return sut.WithReviewers("a").WithPublishType("drafts").Build("master");
31+
}
32+
33+
[Test(ExpectedResult = "refs/for/fix-7521")]
34+
public static string Build_with_all_values_on_default_builds_expected_command()
35+
{
36+
var sut = new CommandBuilderWithDraftSupport();
37+
return sut.WithReviewers(string.Empty)
38+
.WithCC(string.Empty)
39+
.WithTopic(string.Empty)
40+
.WithPublishType(string.Empty)
41+
.WithHashTag(string.Empty)
42+
.Build("fix-7521");
43+
}
44+
45+
[Test(ExpectedResult = "refs/for/fix-7521%r=mygroup,cc=team2,topic=ABC-123,hashtag=what")]
46+
public static string Build_with_values_for_all_options_builds_expected_command()
47+
{
48+
var sut = new CommandBuilderWithDraftSupport();
49+
return sut.WithReviewers("mygroup")
50+
.WithCC("team2")
51+
.WithTopic("ABC-123")
52+
.WithPublishType(string.Empty)
53+
.WithHashTag("what")
54+
.Build("fix-7521");
55+
}
56+
}
57+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Gerrit.Server;
7+
using NUnit.Framework;
8+
9+
namespace GerritTests.Server
10+
{
11+
public static class CommandBuilderWithPrivateSupportTests
12+
{
13+
[TestCase("", ExpectedResult = "refs/for/mybranch")]
14+
[TestCase("wip", ExpectedResult = "refs/for/mybranch%wip")]
15+
[TestCase("private", ExpectedResult = "refs/for/mybranch%private")]
16+
public static string Build_given_a_publishType_builds_expected_command(string publishType)
17+
{
18+
var sut = new CommandBuilderWithPrivateSupport();
19+
20+
return sut.WithPublishType(publishType).Build("mybranch");
21+
}
22+
23+
[Test]
24+
public static void Build_given_a_set_of_values_builds_expected_command()
25+
{
26+
var sut = new CommandBuilderWithPrivateSupport();
27+
28+
Assert.AreEqual("refs/for/master%r=myteam",
29+
sut.WithReviewers("myteam").WithPublishType(string.Empty).Build("master"));
30+
}
31+
}
32+
}

Server/GerritCapabilityTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Linq;
2+
using Gerrit.Server;
3+
using NUnit.Framework;
4+
5+
namespace GerritTests.Server
6+
{
7+
public static class GerritCapabilityTests
8+
{
9+
[Test]
10+
public static void PublishTypes_for_Version2_15_has_expected_list_of_values()
11+
{
12+
RunTest(GerritCapabilities.Version2_15, new[] { "", "wip", "private" });
13+
}
14+
15+
[Test]
16+
public static void PublishTypes_for_OlderVersion_has_expected_list_of_values()
17+
{
18+
RunTest(GerritCapabilities.OldestVersion, new[] { "", "drafts" });
19+
}
20+
21+
private static void RunTest(GerritCapabilities capability, string[] expectedValues)
22+
{
23+
var publishTypes = capability.PublishTypes
24+
.Select(x => x.Value)
25+
.ToArray();
26+
27+
Assert.That(publishTypes, Is.EqualTo(expectedValues));
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)