Skip to content

Commit

Permalink
(cake-buildGH-2474) Refactor TeamCityProvider.BuildProblem method for…
Browse files Browse the repository at this point in the history
… API consistency

This change will suppress the "identity" token if the value provided is null or empty.
This directory resolves the issue of the provider attempting to sanitize a null reference
on a value that, per Jetbrains documentation, is not required for the buildProblem
service message
  • Loading branch information
kcamp committed Feb 15, 2019
1 parent 9419aa4 commit 91aed07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/Cake.Common.Tests/Unit/Build/TeamCity/TeamCityProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,26 @@ public void SetParameter_Should_Write_To_The_Log_Correctly()
fixture.Log.AggregateLogMessages());
}
}

public sealed class TheBuildProblemMethod
{
[Theory]
[InlineData("A build problem", "identity_id", "description='A build problem' identity='identity_id'")]
[InlineData("A build problem", "", "description='A build problem'")]
[InlineData("A build problem", null, "description='A build problem'")]
public void BuildProblem_Should_Write_To_The_Log_Correctly(string description, string identity, string expected)
{
// Given
var fixture = new TeamCityFixture();
var teamCity = fixture.CreateTeamCityService();

// When
teamCity.BuildProblem(description, identity);

// Then
Assert.Equal($"##teamcity[buildProblem {expected}]" + Environment.NewLine,
fixture.Log.AggregateLogMessages());
}
}
}
}
10 changes: 6 additions & 4 deletions src/Cake.Common/Build/TeamCity/TeamCityProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ public void ImportDotCoverCoverage(FilePath snapshotFile, DirectoryPath dotCover
/// <param name="identity">Build identity.</param>
public void BuildProblem(string description, string identity)
{
WriteServiceMessage("buildProblem", new Dictionary<string, string>
var tokens = new Dictionary<string, string> { { "description", description } };
if (!string.IsNullOrEmpty(identity))
{
{ "description", description },
{ "identity", identity }
});
tokens.Add("identity", identity);
}

WriteServiceMessage("buildProblem", tokens);
}

/// <summary>
Expand Down

0 comments on commit 91aed07

Please sign in to comment.