Skip to content

Commit

Permalink
Simplify RepositoryBranch tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKotsenas committed Aug 29, 2024
1 parent e0ee68a commit 5230e33
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tests/DotNet.ReproducibleBuilds.Tests/SourceLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,22 @@ public void EmbedUntrackedSourcesIsSet(bool? embedUntrackedSources, bool expecte
public void RepositoryBranchIsSet(string ci, string original, string expected)
{
using EnvironmentVariableSuppressor hostSuppressor = new("BUILD_SOURCEBRANCH"); // Suppress our own CI provider variables (i.e. Azure DevOps)
using EnvironmentVariableSuppressor ciSuppressor = new(ci); // Suppress the mock CI provider (just in case).
using EnvironmentVariableSuppressor ciSuppressor = new(ci); // Suppress the mock CI provider (just in case)

// If RepositoryBranch is set, it should take precedence over the CI provider variables
ProjectCreator.Templates
ProjectCreator project = ProjectCreator.Templates
.ReproducibleBuildProject(GetRandomFile(".csproj"))
.PropertyGroup()
.Property("RepositoryBranch", "explicitly-set")
.Property(ci, original)
.Project
.GetPropertyValue("RepositoryBranch")
.Should().Be("explicitly-set", "because explicitly setting `RepositoryBranch` should always win.");
.Property(ci, original);

// If RepositoryBranch is not set, it should be set from the CI provider property
ProjectCreator.Templates
.ReproducibleBuildProject(GetRandomFile(".csproj"))
.PropertyGroup()
.Property(ci, original)
.Project
project.Project
.GetPropertyValue("RepositoryBranch")
.Should().Be(expected);

// If RepositoryBranch is set, it should take precedence over the CI provider variables
project.Property("RepositoryBranch", "explicitly-set")
.Project
.GetPropertyValue("RepositoryBranch")
.Should().Be("explicitly-set", "because explicitly setting `RepositoryBranch` should always win.");
}
}

0 comments on commit 5230e33

Please sign in to comment.