Skip to content

Commit 3e53f79

Browse files
test en cake fixes
1 parent 2fe5c44 commit 3e53f79

File tree

3 files changed

+98
-19
lines changed

3 files changed

+98
-19
lines changed

Aikido.Zen.Test/AgentInfoHelperTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class AgentInfoHelperTests
1010
private string _originalAzureValue;
1111

1212
[SetUp]
13-
public void Setup()
13+
public void Setup ()
1414
{
1515
// Store original environment variables
1616
_originalBlockingValue = Environment.GetEnvironmentVariable("AIKIDO_BLOCK");
@@ -19,7 +19,7 @@ public void Setup()
1919
}
2020

2121
[TearDown]
22-
public void Cleanup()
22+
public void Cleanup ()
2323
{
2424
// Restore original environment variables
2525
SetEnvironmentVariable("AIKIDO_BLOCK", _originalBlockingValue);
@@ -28,7 +28,7 @@ public void Cleanup()
2828
}
2929

3030
[Test]
31-
public void GetInfo_ShouldReturnValidAgentInfo()
31+
public void GetInfo_ShouldReturnValidAgentInfo ()
3232
{
3333
// Act
3434
var agentInfo = AgentInfoHelper.GetInfo();
@@ -39,7 +39,7 @@ public void GetInfo_ShouldReturnValidAgentInfo()
3939
// Basic properties
4040
Assert.That(agentInfo.Hostname, Is.EqualTo(Environment.MachineName));
4141
Assert.That(agentInfo.Library, Is.EqualTo("firewall-dotnet"));
42-
Assert.That(agentInfo.Version, Is.EqualTo(typeof(AgentInfoHelper).Assembly.GetName().Version!.ToString()));
42+
Assert.That(agentInfo.Version, Is.EqualTo(AgentInfoHelper.CleanVersion(typeof(AgentInfoHelper).Assembly.GetName().Version!.ToString())));
4343
Assert.That(agentInfo.IpAddress, Is.Not.Null);
4444

4545
// OS Info
@@ -53,7 +53,7 @@ public void GetInfo_ShouldReturnValidAgentInfo()
5353
}
5454

5555
[Test]
56-
public void GetInfo_ServerlessDetection_AWS()
56+
public void GetInfo_ServerlessDetection_AWS ()
5757
{
5858
// Arrange
5959
SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", "test-function");
@@ -66,7 +66,7 @@ public void GetInfo_ServerlessDetection_AWS()
6666
}
6767

6868
[Test]
69-
public void GetInfo_ServerlessDetection_Azure()
69+
public void GetInfo_ServerlessDetection_Azure ()
7070
{
7171
// Arrange
7272
SetEnvironmentVariable("WEBSITE_INSTANCE_ID", "test-instance");
@@ -79,7 +79,7 @@ public void GetInfo_ServerlessDetection_Azure()
7979
}
8080

8181
[Test]
82-
public void GetInfo_NotServerless_WhenNoServerlessEnvironmentVariables()
82+
public void GetInfo_NotServerless_WhenNoServerlessEnvironmentVariables ()
8383
{
8484
// Arrange
8585
SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", null);
@@ -93,7 +93,7 @@ public void GetInfo_NotServerless_WhenNoServerlessEnvironmentVariables()
9393
}
9494

9595
[Test]
96-
public void GetInfo_PlatformArchitecture_Core()
96+
public void GetInfo_PlatformArchitecture_Core ()
9797
{
9898
// This test is environment-dependent
9999
if (Environment.Version.Major >= 5)
@@ -107,7 +107,7 @@ public void GetInfo_PlatformArchitecture_Core()
107107
}
108108

109109
[Test]
110-
public void GetInfo_PlatformArchitecture_Framework()
110+
public void GetInfo_PlatformArchitecture_Framework ()
111111
{
112112
// This test is environment-dependent
113113
if (Environment.Version.Major < 5)
@@ -120,7 +120,7 @@ public void GetInfo_PlatformArchitecture_Framework()
120120
}
121121
}
122122

123-
private void SetEnvironmentVariable(string variable, string value)
123+
private void SetEnvironmentVariable (string variable, string value)
124124
{
125125
if (value == null)
126126
{
@@ -133,7 +133,7 @@ private void SetEnvironmentVariable(string variable, string value)
133133
}
134134

135135
[Test]
136-
public void CleanVersion_ShouldRemoveBuildNumber()
136+
public void CleanVersion_ShouldRemoveBuildNumber ()
137137
{
138138
var version = "1.2.3+4";
139139
var otherVersion = "1.2.3.0";
@@ -144,15 +144,15 @@ public void CleanVersion_ShouldRemoveBuildNumber()
144144
}
145145

146146
[Test]
147-
public void CleanVersion_ShouldRemovePrereleaseVersion()
147+
public void CleanVersion_ShouldRemovePrereleaseVersion ()
148148
{
149149
var version = "1.2.3-alpha";
150150
var cleanedVersion = AgentInfoHelper.CleanVersion(version);
151151
Assert.That(cleanedVersion, Is.EqualTo("1.2.3"));
152152
}
153153

154154
[Test]
155-
public void CleanVersion_ShouldRemoveBuildNumberAndPrereleaseVersion()
155+
public void CleanVersion_ShouldRemoveBuildNumberAndPrereleaseVersion ()
156156
{
157157
var version = "1.2.3+4-alpha";
158158
var cleanedVersion = AgentInfoHelper.CleanVersion(version);

build.cake

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
var target = Argument("target", "Default");
77
var configuration = Argument("configuration", "Release");
88
var framework = Argument("framework", "");
9+
var sdkVersion = "";
10+
if (!string.IsNullOrEmpty(framework))
11+
{
12+
var parts = framework.Split('.');
13+
if (parts.Length >= 2)
14+
{
15+
sdkVersion = $"{parts[0]}.{parts[1]}";
16+
}
17+
}
918
var solution = "./Aikido.Zen.sln";
1019
var projectName = "Aikido.Zen.Core";
1120
var zenInternalsVersion = "0.1.37";
@@ -130,7 +139,6 @@ Task("Test")
130139
// skip tests for the wrong framework
131140
Information($"Running tests for {project.FullPath} on .NET Framework {framework}");
132141
if (framework.StartsWith("4.") && project.FullPath.Contains("DotNetCore"))
133-
134142
{
135143
Information($"Skipping test project {project.FullPath} for .NET Framework {framework}");
136144
continue;
@@ -142,8 +150,17 @@ Task("Test")
142150
}
143151

144152
var logFilePath = $"{coverageDir.FullPath}/test-results-{project.GetFilenameWithoutExtension()}.trx";
153+
var outputLogPath = $"{coverageDir.FullPath}/test-output-{project.GetFilenameWithoutExtension()}.log";
154+
var errorLogPath = $"{coverageDir.FullPath}/test-error-{project.GetFilenameWithoutExtension()}.log";
145155

146-
DotNetTest(project.FullPath, new DotNetTestSettings
156+
// Create or clear the log files
157+
System.IO.File.WriteAllText(outputLogPath, "");
158+
System.IO.File.WriteAllText(errorLogPath, "");
159+
160+
var stdOutput = new List<string>();
161+
var stdError = new List<string>();
162+
163+
var settings = new DotNetTestSettings
147164
{
148165
SetupProcessSettings = processSettings =>
149166
{
@@ -166,11 +183,74 @@ Task("Test")
166183
.Append("/p:Exclude=[Aikido.Zen.Test]*");
167184
}
168185
// Increase verbosity to diagnostic for more information
169-
return args
170-
.Append("--verbosity diagnostic")
186+
args = args
187+
.Append("--verbosity detailed")
171188
.Append($"--logger trx;LogFileName={logFilePath}");
189+
190+
// If SDK version was extracted from framework argument, use it
191+
if (!string.IsNullOrEmpty(sdkVersion))
192+
{
193+
args = args.Append($"--sdk-version {sdkVersion}");
194+
}
195+
196+
return args;
172197
}
173-
});
198+
};
199+
200+
try
201+
{
202+
var process = StartAndReturnProcess(
203+
"dotnet",
204+
new ProcessSettings
205+
{
206+
Arguments = $"test {project.FullPath} --configuration {configuration} --no-build --no-restore --verbosity detailed --logger trx;LogFileName={logFilePath}",
207+
RedirectStandardOutput = true,
208+
RedirectStandardError = true,
209+
Silent = true
210+
}
211+
);
212+
213+
process.GetStandardOutput().ToList().ForEach(line =>
214+
{
215+
stdOutput.Add(line);
216+
System.IO.File.AppendAllText(outputLogPath, line + Environment.NewLine);
217+
});
218+
219+
process.GetStandardError().ToList().ForEach(line =>
220+
{
221+
stdError.Add(line);
222+
System.IO.File.AppendAllText(errorLogPath, line + Environment.NewLine);
223+
});
224+
225+
process.WaitForExit();
226+
227+
if (process.GetExitCode() != 0)
228+
{
229+
throw new Exception($"Test failed for {project.GetFilename()}. Exit code: {process.GetExitCode()}");
230+
}
231+
}
232+
catch (Exception ex)
233+
{
234+
Error($"Test failed for {project.GetFilename()}: {ex.Message}");
235+
236+
// Print the captured output
237+
Information("=== Test Standard Output ===");
238+
foreach (var line in stdOutput)
239+
{
240+
Information(line);
241+
}
242+
243+
Information("=== Test Standard Error ===");
244+
foreach (var line in stdError)
245+
{
246+
Error(line);
247+
}
248+
249+
Information($"Full test output log: {outputLogPath}");
250+
Information($"Full test error log: {errorLogPath}");
251+
252+
throw;
253+
}
174254
}
175255
Information($"Test task completed successfully. Coverage report at: {coverageDir.FullPath}");
176256

coreclr

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)