Skip to content

Commit

Permalink
More git test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Sep 21, 2024
1 parent 2756185 commit 538fcbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Synthesis.Bethesda.Execution.Settings;
using Synthesis.Bethesda.Execution.Versioning;
using Synthesis.Bethesda.UnitTests.AutoData;
using Xunit;
using ILogger = Serilog.ILogger;

namespace Synthesis.Bethesda.UnitTests.Execution.Patchers.Git.PrepareRunner;
Expand Down Expand Up @@ -65,10 +64,10 @@ public Commit AddACommit(string path)
}

[DebuggerStepThrough]
public GitPatcherVersioning TypicalPatcherVersioning() =>
public GitPatcherVersioning TypicalPatcherVersioning(string defaultBranchName) =>
new(
PatcherVersioningEnum.Branch,
DefaultBranch);
defaultBranchName);

[DebuggerStepThrough]
public NugetsVersioningTarget TypicalNugetVersioning() =>
Expand All @@ -95,11 +94,12 @@ public async Task CreatesRunnerBranch()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var resp = await Get(local).Checkout(
new CheckoutInput(
ProjPath,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
using var repo = new Repository(local);
Expand All @@ -111,11 +111,12 @@ public async Task NonExistentProjPath()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var resp = await Get(local).Checkout(
new CheckoutInput(
string.Empty,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.IsHaltingError.Should().BeTrue();
Expand All @@ -129,11 +130,12 @@ public async Task NonExistentSlnPath()
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local,
out var defaultBranchName,
createPatcherFiles: false);
var resp = await Get(local).Checkout(
new CheckoutInput(
ProjPath,
TypicalPatcherVersioning(),
TypicalPatcherVersioning(defaultBranchName),
TypicalNugetVersioning()),
cancel: CancellationToken.None);
resp.IsHaltingError.Should().BeTrue();
Expand All @@ -146,7 +148,8 @@ public async Task UnknownSha()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Commit, "46c207318c1531de7dc2f8e8c2a91aced183bc30");
var resp = await Get(local).Checkout(
new CheckoutInput(
Expand All @@ -164,7 +167,8 @@ public async Task MalformedSha()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Commit, "derp");
var resp = await Get(local).Checkout(
new CheckoutInput(
Expand All @@ -182,7 +186,8 @@ public async Task TagTarget()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tagStr = "1.3.4";
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
Expand All @@ -206,7 +211,8 @@ public async Task TagTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tagStr = "1.3.4";
string tipSha;
{
Expand Down Expand Up @@ -241,7 +247,8 @@ public async Task TagTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var tag = "1.3.4";
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
Expand Down Expand Up @@ -269,7 +276,8 @@ public async Task TagTargetNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
using var clone = new Repository(Repository.Clone(remote, clonePath));
Expand Down Expand Up @@ -303,7 +311,8 @@ public async Task CommitTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;

Expand All @@ -329,7 +338,8 @@ public async Task CommitTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
string tipSha;
{
using var repo = new Repository(local);
Expand Down Expand Up @@ -361,7 +371,8 @@ public async Task CommitTargetNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
using var clone = new Repository(Repository.Clone(remote, clonePath));
Expand Down Expand Up @@ -394,7 +405,8 @@ public async Task BranchTargetJumpback()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
using var repo = new Repository(local);
var tipSha = repo.Head.Tip.Sha;
var jbName = "Jumpback";
Expand All @@ -421,15 +433,16 @@ public async Task BranchTargetJumpback()
repo.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
repo.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
repo.Branches[jbName].Tip.Sha.Should().BeEquivalentTo(tipSha);
repo.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(commit.Sha);
repo.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(commit.Sha);
}

[Fact]
public async Task BranchTargetNoLocal()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
var jbName = "Jumpback";
string tipSha;
string commitSha;
Expand All @@ -446,7 +459,7 @@ public async Task BranchTargetNoLocal()
repo.Branches.Remove(jbName);
commitSha = AddACommit(local).Sha;
repo.Head.Tip.Sha.Should().NotBeEquivalentTo(tipSha);
repo.Network.Push(repo.Branches[DefaultBranch]);
repo.Network.Push(repo.Branches[defaultBranchName]);
}

var clonePath = Path.Combine(repoPath.Dir.Path, "Clone");
Expand All @@ -465,15 +478,16 @@ public async Task BranchTargetNoLocal()
clone.Head.Tip.Sha.Should().BeEquivalentTo(tipSha);
clone.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
clone.Branches[jbName].Should().BeNull();
clone.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(commitSha);
clone.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(commitSha);
}

[Fact]
public async Task BranchNewContent()
{
using var repoPath = GetRepository(
nameof(PrepareRunnerRepositoryIntegrationTests),
out var remote, out var local);
out var remote, out var local,
out var defaultBranchName);
string tipSha;
string commitSha;

Expand All @@ -484,10 +498,10 @@ public async Task BranchNewContent()
tipSha = repo.Head.Tip.Sha;
commitSha = AddACommit(local).Sha;
repo.Head.Tip.Sha.Should().NotBeEquivalentTo(tipSha);
repo.Network.Push(repo.Branches[DefaultBranch]);
repo.Network.Push(repo.Branches[defaultBranchName]);
}

var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Branch, $"origin/{DefaultBranch}");
var versioning = new GitPatcherVersioning(PatcherVersioningEnum.Branch, $"origin/{defaultBranchName}");
var resp = await Get(clonePath).Checkout(
new CheckoutInput(
ProjPath,
Expand All @@ -499,7 +513,7 @@ public async Task BranchNewContent()
resp.RunnableState.Succeeded.Should().BeTrue();
clone.Head.Tip.Sha.Should().BeEquivalentTo(commitSha);
clone.Head.FriendlyName.Should().BeEquivalentTo(CheckoutRunnerBranch.RunnerBranch);
clone.Branches[DefaultBranch].Tip.Sha.Should().BeEquivalentTo(tipSha);
clone.Branches[defaultBranchName].Tip.Sha.Should().BeEquivalentTo(tipSha);
}
#endregion
}
10 changes: 2 additions & 8 deletions Synthesis.Bethesda.UnitTests/RepoTestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Synthesis.Bethesda.UnitTests;

public class RepoTestUtility
{
public string DefaultBranch => "dev";
public string AFile => "Somefile.txt";
public string SlnPath => "Solution.sln";
public string ProjPath => "MyProj/MyProj.csproj";
Expand All @@ -20,6 +19,7 @@ public TempFolder GetRepository(
string folderName,
out DirectoryPath remote,
out DirectoryPath local,
out string defaultBranchName,
bool createPatcherFiles = true,
[CallerMemberName] string? testName = null)
{
Expand All @@ -38,13 +38,7 @@ public TempFolder GetRepository(
var sig = Signature;
localRepo.Commit("Initial commit", sig, sig);
var defaultBranch = localRepo.Branches.First();
if (defaultBranch.FriendlyName != DefaultBranch)
{
var dev = localRepo.Branches.Add(DefaultBranch, localRepo.Head.Tip);
LibGit2Sharp.Commands.Checkout(localRepo, dev);
localRepo.Branches.Remove(defaultBranch);
defaultBranch = dev;
}
defaultBranchName = defaultBranch.FriendlyName;

if (createPatcherFiles)
{
Expand Down

0 comments on commit 538fcbe

Please sign in to comment.