Files
ClaudeDo/tests/ClaudeDo.Worker.Tests/Runner/GitServiceMergeTests.cs
2026-04-22 09:23:35 +02:00

53 lines
1.5 KiB
C#

using ClaudeDo.Data.Git;
using ClaudeDo.Worker.Tests.Infrastructure;
namespace ClaudeDo.Worker.Tests.Runner;
public class GitServiceMergeTests : IDisposable
{
private readonly List<GitRepoFixture> _repos = new();
private GitRepoFixture NewRepo()
{
var r = new GitRepoFixture();
_repos.Add(r);
return r;
}
public void Dispose()
{
foreach (var r in _repos) try { r.Dispose(); } catch { }
}
[Fact]
public async Task GetCurrentBranchAsync_FreshRepo_ReturnsDefaultBranch()
{
if (!GitRepoFixture.IsGitAvailable()) return;
var repo = NewRepo();
var git = new GitService();
var branch = await git.GetCurrentBranchAsync(repo.RepoDir);
Assert.False(string.IsNullOrWhiteSpace(branch));
// Default branch is either "main" or "master" depending on git config.
Assert.True(branch == "main" || branch == "master",
$"Expected main or master, got '{branch}'");
}
[Fact]
public async Task ListLocalBranchesAsync_AfterCreatingSecondBranch_ReturnsBoth()
{
if (!GitRepoFixture.IsGitAvailable()) return;
var repo = NewRepo();
GitRepoFixture.RunGit(repo.RepoDir, "branch", "feature/x");
var git = new GitService();
var branches = await git.ListLocalBranchesAsync(repo.RepoDir);
Assert.Contains("feature/x", branches);
Assert.True(branches.Any(b => b == "main" || b == "master"));
}
}