-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/csmacnz.Coveralls.Tests/GitDataResolvers/TeamCityGitDataResolverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.GitDataResolvers; | ||
using csmacnz.Coveralls.Ports; | ||
using csmacnz.Coveralls.Tests.TestAdapters; | ||
using Xunit; | ||
|
||
namespace csmacnz.Coveralls.Tests.GitDataResolvers | ||
{ | ||
public class TeamCityGitDataResolverTests | ||
{ | ||
[Fact] | ||
public void CanProvideDataNoEnvironmentVariablesSetReturnsFalse() | ||
{ | ||
var sut = new TeamCityGitDataResolver(new TestEnvironmentVariables(), new TestConsole()); | ||
|
||
var canProvideData = sut.CanProvideData(); | ||
|
||
Assert.False(canProvideData); | ||
} | ||
|
||
[Fact] | ||
public void CanProvideDataTeamCityEnvironmentVariableSetReturnsTrue() | ||
{ | ||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" } | ||
}); | ||
|
||
var sut = new TeamCityGitDataResolver(variables, new TestConsole()); | ||
|
||
var canProvideData = sut.CanProvideData(); | ||
|
||
Assert.True(canProvideData); | ||
} | ||
|
||
[Fact] | ||
public void GenerateDataNoCustomEnviromentDataReturnsCommitSha() | ||
{ | ||
string sha = "46d8bffca535dd350b0167d0eb58a22d4bf4ea6e"; | ||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" }, | ||
{ "BUILD_VCS_NUMBER", sha } | ||
}); | ||
|
||
var sut = new TeamCityGitDataResolver(variables, new TestConsole()); | ||
|
||
var gitData = sut.GenerateData(); | ||
|
||
Assert.True(gitData.HasValue); | ||
Assert.True(gitData.IsItem2); | ||
Assert.Equal(sha, gitData.Item2.Value); | ||
} | ||
|
||
[Fact] | ||
public void GenerateDataCustomEnviromentDataReturnsGitData() | ||
{ | ||
string sha = "46d8bffca535dd350b0167d0eb58a22d4bf4ea6e"; | ||
string branch = "master"; | ||
|
||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" }, | ||
{ "TEAMCITY_BUILD_BRANCH", branch }, | ||
{ "TEAMCITY_BUILD_COMMIT", sha } | ||
}); | ||
|
||
var sut = new TeamCityGitDataResolver(variables, new TestConsole()); | ||
|
||
var gitData = sut.GenerateData(); | ||
|
||
Assert.True(gitData.HasValue); | ||
Assert.True(gitData.IsItem1); | ||
Assert.Equal(branch, gitData.Item1.Branch); | ||
Assert.NotNull(gitData.Item1.Head); | ||
Assert.Equal(sha, gitData.Item1.Head.Id); | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/csmacnz.Coveralls.Tests/MetaDataResolvers/TeamCityMetaDataResolverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.MetaDataResolvers; | ||
using csmacnz.Coveralls.Ports; | ||
using csmacnz.Coveralls.Tests.TestAdapters; | ||
using Xunit; | ||
|
||
namespace csmacnz.Coveralls.Tests.MetaDataResolvers | ||
{ | ||
public class TeamCityMetaDataResolverTests | ||
{ | ||
[Fact] | ||
public void CanProvideDataNoEnvironmentVariablesSetReturnsFalse() | ||
{ | ||
var sut = new TeamCityMetaDataResolver(new TestEnvironmentVariables()); | ||
|
||
var canProvideData = sut.IsActive(); | ||
|
||
Assert.False(canProvideData); | ||
} | ||
|
||
[Fact] | ||
public void CanProvideDataTeamCityEnvironmentVariableSetReturnsTrue() | ||
{ | ||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" } | ||
}); | ||
|
||
var sut = new TeamCityMetaDataResolver(variables); | ||
|
||
var canProvideData = sut.IsActive(); | ||
|
||
Assert.True(canProvideData); | ||
} | ||
|
||
[Fact] | ||
public void TeamcityNoCustomEnvironmentVariableSetReturnsCorrectResults() | ||
{ | ||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" } | ||
}); | ||
|
||
var sut = new TeamCityMetaDataResolver(variables); | ||
|
||
var canProvideData = sut.IsActive(); | ||
|
||
Assert.True(canProvideData); | ||
var serviceNameResult = sut.ResolveServiceName(); | ||
Assert.True(serviceNameResult.HasValue); | ||
Assert.Equal("teamcity", serviceNameResult.ValueOrDefault()); | ||
Assert.False(sut.ResolvePullRequestId().HasValue); | ||
Assert.False(sut.ResolveServiceBuildNumber().HasValue); | ||
Assert.False(sut.ResolveServiceJobId().HasValue); | ||
} | ||
|
||
public class GenerateData | ||
{ | ||
private readonly string _expectedPullRequestId; | ||
private readonly string _expectedBuildNumber; | ||
private readonly string _expectedServiceName; | ||
private readonly TeamCityMetaDataResolver _sut; | ||
|
||
public GenerateData() | ||
{ | ||
_expectedPullRequestId = "42"; | ||
_expectedBuildNumber = "12"; | ||
_expectedServiceName = "teamcity"; | ||
|
||
IEnvironmentVariables variables = new TestEnvironmentVariables(new Dictionary<string, string> | ||
{ | ||
{ "TEAMCITY_VERSION", "10.4.5-monsoon" }, | ||
{ "TEAMCITY_BUILD_NUMBER", _expectedBuildNumber }, | ||
{ "TEAMCITY_PULL_REQUEST", _expectedPullRequestId } | ||
}); | ||
|
||
_sut = new TeamCityMetaDataResolver(variables); | ||
} | ||
|
||
[Fact] | ||
public void PullRequestIdSetCorrectly() | ||
{ | ||
var result = _sut.ResolvePullRequestId(); | ||
Assert.True(result.HasValue); | ||
Assert.Equal(_expectedPullRequestId, result.ValueOrDefault()); | ||
} | ||
|
||
[Fact] | ||
public void ServiceBuildNumberResolvesCorrectly() | ||
{ | ||
var result = _sut.ResolveServiceBuildNumber(); | ||
Assert.True(result.HasValue); | ||
Assert.Equal(_expectedBuildNumber, result.ValueOrDefault()); | ||
} | ||
|
||
[Fact] | ||
public void ServiceJobIdResolvesCorrectly() | ||
{ | ||
var result = _sut.ResolveServiceJobId(); | ||
Assert.False(result.HasValue); | ||
} | ||
|
||
[Fact] | ||
public void ServiceNameResolvesCorrectly() | ||
{ | ||
var result = _sut.ResolveServiceName(); | ||
Assert.True(result.HasValue); | ||
Assert.Equal(_expectedServiceName, result.ValueOrDefault()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters