This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-114) Implemented dynamic loading of ci server parsers
resolves #114
- Loading branch information
1 parent
7b649d1
commit a7ee280
Showing
2 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
258 changes: 258 additions & 0 deletions
258
Source/Codecov.Tests/Factories/ContinuousIntegrationServerFactoryTests.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,258 @@ | ||
using System; | ||
using Codecov.Factories; | ||
using Codecov.Services.ContinuousIntegrationServers; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Codecov.Tests.Factories | ||
{ | ||
public class ContinuousIntegrationServerFactoryTests | ||
{ | ||
public ContinuousIntegrationServerFactoryTests() | ||
{ | ||
var environmentVariables = new[] { | ||
"CI", | ||
"APPVEYOR", | ||
"TF_BUILD", | ||
"GITHUB_ACTIONS", | ||
"GITHUB_ACTION", | ||
"JENKINS_URL", | ||
"TEAMCITY_VERSION", | ||
"TRAVIS" | ||
}; | ||
|
||
foreach (var environmentVariable in environmentVariables) | ||
{ | ||
Environment.SetEnvironmentVariable(environmentVariable, null, EnvironmentVariableTarget.Process); | ||
} | ||
} | ||
|
||
#region AppVeyor Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAppVeyorWhenAppveyorIsNull() | ||
{ | ||
Environment.SetEnvironmentVariable("APPVEYOR", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AppVeyor>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAppVeyorWhenAppveyorIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("APPVEYOR", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AppVeyor>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAppVeyorWhenCiIsNull() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AppVeyor>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAppVeyorWhenCiIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AppVeyor>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectAppVeyorWhenCiAndAppVeyorIsTrue() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "True"); | ||
Environment.SetEnvironmentVariable("APPVEYOR", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<AppVeyor>(); | ||
} | ||
|
||
#endregion AppVeyor Detection | ||
|
||
#region Azure Pipelines Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAzurePipelinesWhenTfBuildIsNull() | ||
{ | ||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AzurePipelines>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectAzurePipelinesWhenTfBuildIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("TF_BUILD", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<AzurePipelines>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectAzurePipelinesWhenTfBuildIsTrue() | ||
{ | ||
Environment.SetEnvironmentVariable("TF_BUILD", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<AzurePipelines>(); | ||
} | ||
|
||
#endregion Azure Pipelines Detection | ||
|
||
#region GitHub Action Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectGitHubActionWhenGitHubActionsAndGitHubActionIsNull() | ||
{ | ||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<GitHubAction>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectGitHubActionWhenGitHubActionsIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<GitHubAction>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectGitHubActionWhenGitHubActionsIsTrue() | ||
{ | ||
Environment.SetEnvironmentVariable("GITHUB_ACTIONS", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<GitHubAction>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectGitHubActionWhenGitHubActionIsNotNull() | ||
{ | ||
Environment.SetEnvironmentVariable("GITHUB_ACTION", "Some-Kind-Of-Value"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<GitHubAction>(); | ||
} | ||
|
||
#endregion GitHub Action Detection | ||
|
||
#region Jenkins Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectJenkinsWhenJenkinsUrlIsNull() | ||
{ | ||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<Jenkins>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectJenkinsWhenJenkinsUrlIsNotNull() | ||
{ | ||
Environment.SetEnvironmentVariable("JENKINS_URL", "https://example.org"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<Jenkins>(); | ||
} | ||
|
||
#endregion Jenkins Detection | ||
|
||
#region TeamCity Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectTeamcityWhenTeamcityVersionIsNull() | ||
{ | ||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<TeamCity>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectTeamcityWhenTeamcityVersionIsNotNull() | ||
{ | ||
Environment.SetEnvironmentVariable("TEAMCITY_VERSION", "1.0.0"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<TeamCity>(); | ||
} | ||
|
||
#endregion TeamCity Detection | ||
|
||
#region Travis Detection | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectTravisWhenTravisIsNull() | ||
{ | ||
Environment.SetEnvironmentVariable("TRAVIS", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<Travis>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectTravisWhenTravisIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("TRAVIS", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<Travis>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectTravisWhenCiIsNull() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<Travis>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldNotDetectTravisWhenCiIsFalse() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "False"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().NotBeOfType<Travis>().And.BeOfType<ContinuousIntegrationServer>(); | ||
} | ||
|
||
[Fact] | ||
public void Create_ShouldDetectTravisWhenCiAndTravisIsTrue() | ||
{ | ||
Environment.SetEnvironmentVariable("CI", "True"); | ||
Environment.SetEnvironmentVariable("TRAVIS", "True"); | ||
|
||
var ci = ContinuousIntegrationServerFactory.Create(); | ||
|
||
ci.Should().BeOfType<Travis>(); | ||
} | ||
|
||
#endregion Travis Detection | ||
} | ||
} |
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