Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Atlasssian Bamboo Build Server #577

Merged
merged 1 commit into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Cake.Common.Tests/Cake.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<ItemGroup>
<Compile Include="Fixtures\Build\AppVeyorFixture.cs" />
<Compile Include="Fixtures\Build\AppVeyorInfoFixture.cs" />
<Compile Include="Fixtures\Build\BambooFixture.cs" />
<Compile Include="Fixtures\Build\BambooInfoFixture.cs" />
<Compile Include="Fixtures\AssemblyInfoFixture.cs" />
<Compile Include="Fixtures\AssemblyInfoParserFixture.cs" />
<Compile Include="Fixtures\Tools\CakeRunnerFixture.cs" />
Expand Down Expand Up @@ -158,6 +160,10 @@
<Compile Include="Unit\Build\BuildSystemAliasesTests.cs" />
<Compile Include="Unit\Build\BuildSystemTests.cs" />
<Compile Include="Unit\Build\TeamCity\TeamCityProviderTests.cs" />
<Compile Include="Unit\Build\Bamboo\BambooProviderTests.cs" />
<Compile Include="Unit\Build\Bamboo\Data\BambooBuildInfoTests.cs" />
<Compile Include="Unit\Build\Bamboo\Data\BambooCommitInfoTests.cs" />
<Compile Include="Unit\Build\Bamboo\Data\BambooRepositoryInfoTests.cs" />
<Compile Include="Unit\IO\Paths\ConvertableDirectoryPathTests.cs" />
<Compile Include="Unit\IO\Paths\ConvertableFilePathTests.cs" />
<Compile Include="Unit\Security\FileHashCalculatorTests.cs" />
Expand Down Expand Up @@ -247,6 +253,7 @@
</Compile>
<Compile Include="Unit\XML\XmlPokeTests.cs" />
<Compile Include="Unit\XML\XmlTransformationTests.cs" />
<Compile Include="Unit\Build\Bamboo\Data\BambooPlanInfoTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cake.Common\Cake.Common.csproj">
Expand Down
29 changes: 29 additions & 0 deletions src/Cake.Common.Tests/Fixtures/Build/BambooFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Cake.Common.Build.Bamboo;
using Cake.Core;
using Cake.Core.IO;
using NSubstitute;

namespace Cake.Common.Tests.Fixtures.Build
{
internal sealed class BambooFixture
{
public ICakeEnvironment Environment { get; set; }

public BambooFixture()
{
Environment = Substitute.For<ICakeEnvironment>();
Environment.WorkingDirectory.Returns("C:\\build\\CAKE-CAKE-JOB1");
Environment.GetEnvironmentVariable("bamboo_buildNumber").Returns((string)null);
}

public void IsRunningOnBamboo()
{
Environment.GetEnvironmentVariable("bamboo_buildNumber").Returns("28");
}

public BambooProvider CreateBambooService()
{
return new BambooProvider(Environment);
}
}
}
73 changes: 73 additions & 0 deletions src/Cake.Common.Tests/Fixtures/Build/BambooInfoFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Cake.Common.Build.Bamboo.Data;
using Cake.Core;
using NSubstitute;

namespace Cake.Common.Tests.Fixtures.Build
{
internal sealed class BambooInfoFixture
{
public ICakeEnvironment Environment { get; set; }

public BambooInfoFixture()
{
Environment = Substitute.For<ICakeEnvironment>();

//BambooBuildInfo
Environment.GetEnvironmentVariable("bamboo_build_working_directory").Returns("C:\\build\\CAKE-CAKE-JOB1");
Environment.GetEnvironmentVariable("bamboo_buildNumber").Returns("28");
Environment.GetEnvironmentVariable("bamboo_buildKey").Returns("CAKE-CAKE-JOB1");
Environment.GetEnvironmentVariable("bamboo_buildResultKey").Returns("CAKE-CAKE-JOB1-28");
Environment.GetEnvironmentVariable("bamboo_buildResultsUrl").Returns("https://cakebuild.atlassian.net/builds/browse/CAKE-CAKE-JOB1-28");
Environment.GetEnvironmentVariable("bamboo_buildTimeStamp").Returns("2015-12-15T22:53:37.847+01:00");

//BambooCustomBuildInfo
Environment.GetEnvironmentVariable("bamboo_customRevision").Returns("Cake with Iceing");

//BambooCommitInfo
Environment.GetEnvironmentVariable("bamboo_planRepository_revision").Returns("d4a3a4cb304548450e3cab2ff735f778ffe58d03");

//BambooPlanInfo
Environment.GetEnvironmentVariable("bamboo_planKey").Returns("CAKE-CAKE");
Environment.GetEnvironmentVariable ("bamboo_planName").Returns ("cake-bamboo - dev");
Environment.GetEnvironmentVariable("bamboo_shortJobKey").Returns("JOB1");
Environment.GetEnvironmentVariable("bamboo_shortJobName").Returns("Build Cake");
Environment.GetEnvironmentVariable("bamboo_shortPlanKey").Returns("CAKE");
Environment.GetEnvironmentVariable("bamboo_shortPlanName").Returns("Cake");

//BambooRepositoryInfo
Environment.GetEnvironmentVariable("bamboo_planRepository_type").Returns("git");
Environment.GetEnvironmentVariable("bamboo_repository_name").Returns("Cake/Develop");
Environment.GetEnvironmentVariable("bamboo_planRepository_branch").Returns("develop");
}

public BambooBuildInfo CreateBuildInfo()
{
return new BambooBuildInfo(Environment);
}

public BambooPlanInfo CreatePlanInfo()
{
return new BambooPlanInfo(Environment);
}

public BambooCommitInfo CreateCommitInfo()
{
return new BambooCommitInfo(Environment);
}

public BambooRepositoryInfo CreateRepositoryInfo()
{
return new BambooRepositoryInfo(Environment);
}

public BambooCustomBuildInfo CreateCustomBuildInfo()
{
return new BambooCustomBuildInfo(Environment);
}

public BambooEnvironmentInfo CreateEnvironmentInfo()
{
return new BambooEnvironmentInfo(Environment);
}
}
}
74 changes: 74 additions & 0 deletions src/Cake.Common.Tests/Unit/Build/Bamboo/BambooProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Cake.Common.Build.Bamboo;
using Cake.Common.Tests.Fixtures.Build;
using Cake.Core;
using Cake.Core.IO;
using NSubstitute;
using Xunit;

namespace Cake.Common.Tests.Unit.Build.Bamboo
{
public sealed class BambooProviderTests
{
public sealed class TheConstructor
{
[Fact]
public void Should_Throw_If_Environment_Is_Null()
{
// Given, When
var result = Record.Exception(() => new BambooProvider(null));

// Then
Assert.IsArgumentNullException(result, "environment");
}
}

public sealed class TheIsRunningOnBambooProperty
{
[Fact]
public void Should_Return_True_If_Running_On_Bamboo()
{
// Given
var fixture = new BambooFixture();
fixture.IsRunningOnBamboo();
var Bamboo = fixture.CreateBambooService();

// When
var result = Bamboo.IsRunningOnBamboo;

// Then
Assert.True(result);
}

[Fact]
public void Should_Return_False_If_Not_Running_On_Bamboo()
{
// Given
var fixture = new BambooFixture();
var Bamboo = fixture.CreateBambooService();

// When
var result = Bamboo.IsRunningOnBamboo;

// Then
Assert.False(result);
}
}

public sealed class TheEnvironmentProperty
{
[Fact]
public void Should_Return_Non_Null_Reference()
{
// Given
var fixture = new BambooFixture();
var Bamboo = fixture.CreateBambooService();

// When
var result = Bamboo.Environment;

// Then
Assert.NotNull(result);
}
}
}
}
104 changes: 104 additions & 0 deletions src/Cake.Common.Tests/Unit/Build/Bamboo/Data/BambooBuildInfoTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Cake.Common.Tests.Fixtures.Build;
using Xunit;

namespace Cake.Common.Tests.Unit.Build.Bamboo.Data
{
public sealed class BambooBuildInfoTests
{
public sealed class TheFolderProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.Folder;

// Then
Assert.Equal(@"C:\build\CAKE-CAKE-JOB1", result);
}
}

public sealed class TheNumberProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.Number;

// Then
Assert.Equal(28, result);
}
}

public sealed class TheBuildKeyProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.BuildKey;

// Then
Assert.Equal("CAKE-CAKE-JOB1", result);
}
}

public sealed class TheResultKeyProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.ResultKey;

// Then
Assert.Equal("CAKE-CAKE-JOB1-28", result);
}
}

public sealed class TheResultUrlProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.ResultsUrl;

// Then
Assert.Equal("https://cakebuild.atlassian.net/builds/browse/CAKE-CAKE-JOB1-28", result);
}
}

public sealed class TheBuildTimestampProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateBuildInfo();

// When
var result = info.BuildTimestamp;

// Then
Assert.Equal("2015-12-15T22:53:37.847+01:00", result);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Cake.Common.Tests.Fixtures.Build;
using Xunit;

namespace Cake.Common.Tests.Unit.Build.Bamboo.Data
{
public sealed class BambooCommitInfoTests
{
public sealed class TheRepositoryRevisionProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateCommitInfo();

// When
var result = info.RepositoryRevision;

// Then
Assert.Equal("d4a3a4cb304548450e3cab2ff735f778ffe58d03", result);

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Cake.Common.Tests.Fixtures.Build;
using Xunit;

namespace Cake.Common.Tests.Unit.Build.Bamboo.Data
{
public sealed class BambooCustomBuildInfoTests
{

public sealed class TheIsCustomBuildProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateCustomBuildInfo();

// When
var result = info.IsCustomBuild;

// Then
Assert.Equal(true, result);
}
}

public sealed class TheRevisonNameProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new BambooInfoFixture().CreateCustomBuildInfo();

// When
var result = info.RevisonName;

// Then
Assert.Equal("Cake with Iceing", result);
}
}
}
}
Loading