Repository navigation
Expand file tree
/
Copy pathProgramRunnerTests.FailOnDiff.cs
More file actions
157 lines (140 loc) · 6.07 KB
/
Copy pathProgramRunnerTests.FailOnDiff.cs
File metadata and controls
157 lines (140 loc) · 6.07 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// ProgramRunnerTests.FailOnDiff.cs — --fail-on-diff CLI gating integration tests
// ProgramRunnerTests.FailOnDiff.cs — --fail-on-diff CLI ゲートの統合テスト
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using FolderDiffIL4DotNet.Services;
using FolderDiffIL4DotNet.Tests.Helpers;
using Xunit;
namespace FolderDiffIL4DotNet.Tests
{
public sealed partial class ProgramRunnerTests
{
[Fact]
public async Task RunAsync_ReportableDifferencesWithoutFailOnDiff_ReturnsSuccess()
{
string tempRoot = CreateFailOnDiffTempRoot();
try
{
string oldDir = CreateDirectory(tempRoot, "old");
string newDir = CreateDirectory(tempRoot, "new");
File.WriteAllText(Path.Combine(newDir, "added.txt"), "added");
await WithConfigFileAsync("""{"SkipIL":true}""", async () =>
{
var result = await RunFailOnDiffComparisonAsync(tempRoot, oldDir, newDir, includeFailOnDiff: false);
Assert.Equal(0, result.ExitCode);
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, "diff_report.md")));
});
}
finally
{
TryDeleteDirectory(tempRoot);
}
}
[Fact]
public async Task RunAsync_FailOnDiffWithoutReportableDifferences_ReturnsSuccess()
{
string tempRoot = CreateFailOnDiffTempRoot();
try
{
string oldDir = CreateDirectory(tempRoot, "old");
string newDir = CreateDirectory(tempRoot, "new");
File.WriteAllText(Path.Combine(oldDir, "same.txt"), "same");
File.WriteAllText(Path.Combine(newDir, "same.txt"), "same");
await WithConfigFileAsync("""{"SkipIL":true}""", async () =>
{
var result = await RunFailOnDiffComparisonAsync(tempRoot, oldDir, newDir, includeFailOnDiff: true);
Assert.Equal(0, result.ExitCode);
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, "diff_report.md")));
});
}
finally
{
TryDeleteDirectory(tempRoot);
}
}
[Fact]
public async Task RunAsync_FailOnDiffWithFinalAddedRemovedAndModifiedEntries_ReturnsFiveAfterGeneratingArtifacts()
{
string tempRoot = CreateFailOnDiffTempRoot();
try
{
string oldDir = CreateDirectory(tempRoot, "old");
string newDir = CreateDirectory(tempRoot, "new");
File.WriteAllText(Path.Combine(oldDir, "removed.txt"), "removed");
File.WriteAllText(Path.Combine(newDir, "added.txt"), "added");
File.WriteAllText(Path.Combine(oldDir, "modified.txt"), "before");
File.WriteAllText(Path.Combine(newDir, "modified.txt"), "after");
await WithConfigFileAsync("""{"SkipIL":true}""", async () =>
{
var result = await RunFailOnDiffComparisonAsync(tempRoot, oldDir, newDir, includeFailOnDiff: true);
Assert.Equal(5, result.ExitCode);
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, "diff_report.md")));
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, "diff_report.html")));
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, AuditLogGenerateService.AUDIT_LOG_FILE_NAME)));
});
}
finally
{
TryDeleteDirectory(tempRoot);
}
}
[Fact]
public async Task RunAsync_FailOnDiffWithOnlyIgnoredExtensionDifference_ReturnsSuccess()
{
string tempRoot = CreateFailOnDiffTempRoot();
try
{
string oldDir = CreateDirectory(tempRoot, "old");
string newDir = CreateDirectory(tempRoot, "new");
File.WriteAllText(Path.Combine(newDir, "ignored.tmp"), "ignored");
await WithConfigFileAsync("""{"SkipIL":true,"IgnoredExtensions":[".tmp"]}""", async () =>
{
var result = await RunFailOnDiffComparisonAsync(tempRoot, oldDir, newDir, includeFailOnDiff: true);
Assert.Equal(0, result.ExitCode);
Assert.True(File.Exists(Path.Combine(result.ReportDirectory, "diff_report.md")));
});
}
finally
{
TryDeleteDirectory(tempRoot);
}
}
private static string CreateFailOnDiffTempRoot()
=> Path.Combine(Path.GetTempPath(), "fd-fail-on-diff-" + Guid.NewGuid().ToString("N"));
private static string CreateDirectory(string root, string name)
{
string path = Path.Combine(root, name);
Directory.CreateDirectory(path);
return path;
}
private static async Task<(int ExitCode, string ReportDirectory)> RunFailOnDiffComparisonAsync(
string tempRoot,
string oldDir,
string newDir,
bool includeFailOnDiff)
{
string reportsRoot = CreateDirectory(tempRoot, "reports");
string reportLabel = "report_" + Guid.NewGuid().ToString("N");
var args = new List<string>
{
oldDir,
newDir,
reportLabel,
"--skip-il",
"--no-pause",
"--no-banner",
"--output",
reportsRoot,
};
if (includeFailOnDiff)
{
args.Add("--fail-on-diff");
}
var runner = new ProgramRunner(new TestLogger(logFileAbsolutePath: "test.log"), new ConfigService());
int exitCode = await runner.RunAsync(args.ToArray());
return (exitCode, Path.Combine(reportsRoot, reportLabel));
}
}
}