Skip to content

Commit

Permalink
Include all TeamCity properties files
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Feb 15, 2021
1 parent 02239b0 commit 9237a25
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 70 deletions.
15 changes: 10 additions & 5 deletions src/Cake.Common.Tests/Fixtures/Build/TeamCityInfoFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ public TeamCityInfoFixture()
((FakeEnvironment)Environment).SetEnvironmentVariable("TEAMCITY_BUILDCONF_NAME", @"Cake Build");
((FakeEnvironment)Environment).SetEnvironmentVariable("BUILD_NUMBER", "10-Foo");
((FakeEnvironment)Environment).SetEnvironmentVariable("TEAMCITY_PROJECT_NAME", "Cake");
((FakeEnvironment)Environment).SetEnvironmentVariable("TEAMCITY_BUILD_PROPERTIES_FILE", "/Working/file.properties");
((FakeEnvironment)Environment).SetEnvironmentVariable("TEAMCITY_BUILD_PROPERTIES_FILE", "/Working/teamcity.build.properties");
((FakeEnvironment)Environment).SetEnvironmentVariable("Git_Branch", "refs/pull-requests/7/from");
((FakeEnvironment)Environment).SetEnvironmentVariable("BUILD_START_DATE", "20200822");
((FakeEnvironment)Environment).SetEnvironmentVariable("BUILD_START_TIME", "123456");
}

public void SetPropertiesFileContent(string xml)
public void SetBuildPropertiesContent(string xml)
{
((FakeFileSystem)FileSystem).GetFile("/Working/file.properties.xml").SetContent(xml);
((FakeFileSystem)FileSystem).GetFile("/Working/teamcity.build.properties.xml").SetContent(xml);
}

public void SetBuildConfigurationFileContent(string xml)
public void SetConfigPropertiesContent(string xml)
{
((FakeFileSystem)FileSystem).GetFile("/Working/file.build.configuration.xml").SetContent(xml);
((FakeFileSystem)FileSystem).GetFile("/Working/teamcity.config.configuration.xml").SetContent(xml);
}

public void SetRunnerPropertiesContent(string xml)
{
((FakeFileSystem)FileSystem).GetFile("/Working/teamcity.runner.configuration.xml").SetContent(xml);
}

public void SetGitBranch(string branch)
Expand Down
31 changes: 24 additions & 7 deletions src/Cake.Common.Tests/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions src/Cake.Common.Tests/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1328,23 +1328,34 @@ Line #3]]></releaseNotes>
</files>
&lt;/package&gt;</value>
</data>
<data name="TeamCity_Build_Configuration_Xml" xml:space="preserve">
<data name="TeamCity_Config_Properties_Xml" xml:space="preserve">
<value>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
&lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
&lt;properties&gt;
&lt;comment&gt;TeamCity configuration parameters for build with id 812869&lt;/comment&gt;
&lt;entry key="build.counter"&gt;414&lt;/entry&gt;
&lt;entry key="build.number"&gt;3246&lt;/entry&gt;
&lt;entry key="teamcity.build.branch"&gt;branchName&lt;/entry&gt;
&lt;entry key="teamcity.build.branch"&gt;pull/5&lt;/entry&gt;
&lt;entry key="teamcity.build.branch.is_default"&gt;true&lt;/entry&gt;
&lt;entry key="vcsroot.branch"&gt;refs/pull/5/merge&lt;/entry&gt;
&lt;/properties&gt;</value>
</data>
<data name="TeamCity_Properties_Xml" xml:space="preserve">
<data name="TeamCity_Build_Properties_Xml" xml:space="preserve">
<value>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
&lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
&lt;properties&gt;
&lt;comment&gt;TeamCity build properties without 'system.' prefix&lt;/comment&gt;
&lt;entry key="teamcity.configuration.properties.file"&gt;/Working/file.build.configuration&lt;/entry&gt;
&lt;entry key="teamcity.build.properties.file"&gt;/Working/teamcity.build.configuration&lt;/entry&gt;
&lt;entry key="teamcity.configuration.properties.file"&gt;/Working/teamcity.config.configuration&lt;/entry&gt;
&lt;entry key="teamcity.runner.properties.file"&gt;/Working/teamcity.runner.configuration&lt;/entry&gt;
&lt;/properties&gt;</value>
</data>
<data name="TeamCity_Runner_Properties_Xml" xml:space="preserve">
<value>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
&lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
&lt;properties&gt;
&lt;comment&gt;TeamCity configuration parameters for build with id 812869&lt;/comment&gt;
&lt;entry key="command.executable"&gt;run.cmd&lt;/entry&gt;
&lt;/properties&gt;</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Cake.Common.Tests.Fixtures.Build;
using System;
using System.Globalization;
using Cake.Common.Tests.Fixtures.Build;
using Xunit;

namespace Cake.Common.Tests.Unit.Build.TeamCity.Data
Expand Down Expand Up @@ -125,65 +125,142 @@ public void Should_Return_Value_From_Properties()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetPropertiesFileContent(Properties.Resources.TeamCity_Properties_Xml);
fixture.SetBuildConfigurationFileContent(Properties.Resources.TeamCity_Build_Configuration_Xml);
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
fixture.SetConfigPropertiesContent(Properties.Resources.TeamCity_Config_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var result = info.BranchName;

// Then
Assert.Equal("branchName", result);
Assert.Equal("pull/5", result);
}
}

public sealed class TheVcsBranchProperty
{
[Fact]
public void Should_Return_Empty_When_No_Properties()
{
// Given
var info = new TeamCityInfoFixture().CreateBuildInfo();

// When
var result = info.VcsBranchName;

// Then
Assert.Equal(string.Empty, result);
}

[Fact]
public void Should_Return_Value_From_Properties()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
fixture.SetConfigPropertiesContent(Properties.Resources.TeamCity_Config_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var result = info.VcsBranchName;

// Then
Assert.Equal("refs/pull/5/merge", result);
}
}

public sealed class ThePropertiesProperty
public sealed class ThePropertiesProperties
{
[Fact]
public void Should_Return_Empty_When_File_Not_Created()
public void Should_Return_Empty_ForAll_When_File_Not_Created()
{
// Given
var fixture = new TeamCityInfoFixture();
var info = fixture.CreateBuildInfo();

// When
var buildProperties = info.BuildProperties;
var configProperties = info.ConfigProperties;
var runnerProperties = info.RunnerProperties;

// Then
Assert.Empty(buildProperties);
Assert.Empty(configProperties);
Assert.Empty(runnerProperties);
}

[Fact]
public void Should_Return_Empty_When_Config_Properties_File_Not_Created()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var buildProperties = info.BuildProperties;
var configProperties = info.ConfigProperties;

// Then
Assert.NotEmpty(buildProperties);
Assert.Empty(configProperties);
}

[Fact]
public void Should_Return_Config_Values_When_Files_Exist()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
fixture.SetConfigPropertiesContent(Properties.Resources.TeamCity_Config_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var result = info.Properties;
var buildProperties = info.BuildProperties;
var configProperties = info.ConfigProperties;

// Then
Assert.Empty(result);
Assert.NotEmpty(buildProperties);
Assert.NotEmpty(configProperties);
Assert.Equal(5, configProperties.Count);
Assert.Equal("3246", configProperties["build.number"]);
}

[Fact]
public void Should_Return_Empty_When_Build_Properties_File_Not_Created()
public void Should_Return_Empty_When_Runner_Properties_File_Not_Created()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetPropertiesFileContent(Properties.Resources.TeamCity_Properties_Xml);
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var result = info.Properties;
var buildProperties = info.BuildProperties;
var runnerProperties = info.RunnerProperties;

// Then
Assert.Empty(result);
Assert.NotEmpty(buildProperties);
Assert.Empty(runnerProperties);
}

[Fact]
public void Should_Return_Values_When_Files_Exist()
public void Should_Return_Runner_Values_When_Files_Exist()
{
// Given
var fixture = new TeamCityInfoFixture();
fixture.SetPropertiesFileContent(Properties.Resources.TeamCity_Properties_Xml);
fixture.SetBuildConfigurationFileContent(Properties.Resources.TeamCity_Build_Configuration_Xml);
fixture.SetBuildPropertiesContent(Properties.Resources.TeamCity_Build_Properties_Xml);
fixture.SetRunnerPropertiesContent(Properties.Resources.TeamCity_Runner_Properties_Xml);
var info = fixture.CreateBuildInfo();

// When
var result = info.Properties;
var buildProperties = info.BuildProperties;
var runnerProperties = info.RunnerProperties;

// Then
Assert.NotEmpty(result);
Assert.Equal(4, result.Count);
Assert.Equal("3246", result["build.number"]);
Assert.NotEmpty(buildProperties);
Assert.NotEmpty(runnerProperties);
Assert.Single(runnerProperties);
Assert.Equal("run.cmd", runnerProperties["command.executable"]);
}
}
}
Expand Down
Loading

0 comments on commit 9237a25

Please sign in to comment.