-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGitRepositoryIssuesProviderTests.cs
More file actions
114 lines (102 loc) · 4.55 KB
/
GitRepositoryIssuesProviderTests.cs
File metadata and controls
114 lines (102 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
namespace Cake.Issues.GitRepository.Tests;
public sealed class GitRepositoryIssuesProviderTests
{
public sealed class TheSparseCheckoutFiltering
{
[Fact]
public void Should_Filter_Out_Skip_Worktree_Files()
{
// Given - Simulate git ls-files -t -z output with sparse checkout
var gitOutput = new[]
{
"H file1.txt",
"S file2.txt", // Skip-worktree file (should be filtered out)
"H subdir/file3.txt",
"S subdir/file4.txt", // Skip-worktree file (should be filtered out)
""
};
// When - Apply the same filtering logic as GetAllFilesFromRepository
var result = gitOutput
.Where(x => !string.IsNullOrEmpty(x))
.Where(x => !x.StartsWith("S ")) // Exclude skip-worktree files (sparse checkout)
.Select(x => x.Length > 2 ? x[2..] : x) // Remove status prefix (e.g., "H ")
.ToList();
// Then - Only non-skip-worktree files should remain
result.Count.ShouldBe(2);
result.ShouldContain("file1.txt");
result.ShouldContain("subdir/file3.txt");
result.ShouldNotContain("file2.txt");
result.ShouldNotContain("subdir/file4.txt");
}
[Fact]
public void Should_Handle_Empty_Output()
{
// Given - Empty git output
var gitOutput = new[] { "" };
// When - Apply the same filtering logic as GetAllFilesFromRepository
var result = gitOutput
.Where(x => !string.IsNullOrEmpty(x))
.Where(x => !x.StartsWith("S "))
.Select(x => x.Length > 2 ? x[2..] : x)
.ToList();
// Then - Result should be empty
result.ShouldNotBeNull().Count.ShouldBe(0);
}
[Fact]
public void Should_Handle_Various_Git_Status_Codes()
{
// Given - Various git status codes
var gitOutput = new[]
{
"H cached_file.txt", // Cached (should be included)
"S skip_worktree.txt", // Skip-worktree (should be excluded)
"M modified_file.txt", // Modified (should be included)
"R renamed_file.txt", // Renamed (should be included)
"C copied_file.txt", // Copied (should be included)
"K to_be_killed.txt", // To be killed (should be included)
""
};
// When - Apply the filtering logic
var result = gitOutput
.Where(x => !string.IsNullOrEmpty(x))
.Where(x => !x.StartsWith("S "))
.Select(x => x.Length > 2 ? x[2..] : x)
.ToList();
// Then - Only skip-worktree files should be filtered out
result.Count.ShouldBe(5);
result.ShouldContain("cached_file.txt");
result.ShouldContain("modified_file.txt");
result.ShouldContain("renamed_file.txt");
result.ShouldContain("copied_file.txt");
result.ShouldContain("to_be_killed.txt");
result.ShouldNotContain("skip_worktree.txt");
}
[Fact]
public void Should_Handle_Edge_Cases_In_Status_Parsing()
{
// Given - Edge cases that might occur
var gitOutput = new[]
{
"H normal_file.txt",
"S", // Just "S" without filename (malformed)
"Sfile_without_space.txt", // "S" without space (should not be filtered)
"H ", // Just status with space but no filename
"X unknown_status.txt", // Unknown status (should be included)
""
};
// When - Apply the filtering logic
var result = gitOutput
.Where(x => !string.IsNullOrEmpty(x))
.Where(x => !x.StartsWith("S "))
.Select(x => x.Length > 2 ? x[2..] : x)
.ToList();
// Then
result.Count.ShouldBe(5);
result.ShouldContain("normal_file.txt");
result.ShouldContain("S"); // Just "S" - malformed but not filtered
result.ShouldContain("ile_without_space.txt"); // "Sfile_without_space.txt" with first 2 chars removed
result.ShouldContain("H "); // "H " - length is 2, so not transformed
result.ShouldContain("unknown_status.txt");
}
}
}