Skip to content

Commit 835f0ba

Browse files
add test output helper injection for transferring output to custom logging (#238)
* add logging * apply updates * update azure config * update image * return missed param * update image * change ubuntu image version * update image version * undo image changes
1 parent f65a24d commit 835f0ba

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ stages:
172172
pool:
173173
${{ if eq(variables._RunAsPublic, True) }}:
174174
name: NetCore1ESPool-Public
175-
demands: ImageOverride -equals Build.Ubuntu.1604.Amd64.Open
175+
demands: ImageOverride -equals Build.Ubuntu.1804.Amd64.Open
176176
${{ if eq(variables._RunAsInternal, True) }}:
177177
name: NetCore1ESPool-Internal
178-
demands: ImageOverride -equals Build.Ubuntu.1604.Amd64
178+
demands: ImageOverride -equals Build.Ubuntu.1804.Amd64
179179
steps:
180180
- checkout: self
181181
displayName: Checkout Self

tests/Install-Scripts.Test/AkaMsLinksTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ public void NoFallbackIfQualityIsGiven(string channel, string runtime, string qu
391391

392392
commandResult.Should().Fail();
393393
commandResult.Should().HaveStdErrContaining("Failed to locate the latest version in the channel");
394-
395394
}
396395

397396
[Fact]

tests/Install-Scripts.Test/GivenThatIWantToInstallDotnetFromAScript.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
using System.Text.RegularExpressions;
1313
using System.Linq;
1414
using Install_Scripts.Test.Utils;
15+
using Xunit.Abstractions;
1516

1617
namespace Microsoft.DotNet.InstallationScript.Tests
1718
{
1819
public class GivenThatIWantToInstallDotnetFromAScript : IDisposable
1920
{
21+
2022
/// <summary>
2123
/// All the channels that will be tested.
2224
/// </summary>
@@ -142,12 +144,16 @@ public static IEnumerable<object?[]> InstallRuntimeFromChannelTestCases
142144
/// </summary>
143145
private readonly string _sdkInstallationDirectory;
144146

147+
private readonly ITestOutputHelper outputHelper;
148+
145149
/// <summary>
146150
/// Instantiates a GivenThatIWantToInstallTheSdkFromAScript instance.
147151
/// </summary>
148152
/// <remarks>This constructor is called once for each of the tests to run.</remarks>
149-
public GivenThatIWantToInstallDotnetFromAScript()
153+
public GivenThatIWantToInstallDotnetFromAScript(ITestOutputHelper testOutputHelper)
150154
{
155+
outputHelper = testOutputHelper;
156+
151157
_sdkInstallationDirectory = Path.Combine(
152158
Path.GetTempPath(),
153159
"InstallScript-Tests",
@@ -184,6 +190,7 @@ public void Dispose()
184190
}
185191

186192
[Theory]
193+
[Trait("MonitoringTest", "true")]
187194
[MemberData(nameof(InstallSdkFromChannelTestCases))]
188195
public void WhenInstallingTheSdk(string channel, string? quality, string versionRegex)
189196
{
@@ -210,9 +217,12 @@ public void WhenInstallingTheSdk(string channel, string? quality, string version
210217
string regex = Regex.Escape(" ") + versionRegex + Regex.Escape(" ") + installPathRegex;
211218
dotnetCommandResult.Should().HaveStdOutMatching(regex);
212219
commandResult.Should().NotHaveStdErr();
220+
221+
TestOutputHelper.PopulateTestLoggerOutput(outputHelper, commandResult);
213222
}
214223

215224
[Theory]
225+
[Trait("MonitoringTest", "true")]
216226
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
217227
public void WhenInstallingDotnetRuntime(string channel, string? quality, string versionRegex)
218228
{
@@ -239,9 +249,12 @@ public void WhenInstallingDotnetRuntime(string channel, string? quality, string
239249
string regex = lineStartRegex + versionRegex + lineEndRegex;
240250
dotnetCommandResult.Should().HaveStdOutMatching(regex);
241251
commandResult.Should().NotHaveStdErr();
252+
253+
TestOutputHelper.PopulateTestLoggerOutput(outputHelper, commandResult);
242254
}
243255

244256
[Theory]
257+
[Trait("MonitoringTest", "true")]
245258
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
246259
public void WhenInstallingAspNetCoreRuntime(string channel, string? quality, string versionRegex)
247260
{
@@ -275,9 +288,12 @@ public void WhenInstallingAspNetCoreRuntime(string channel, string? quality, str
275288
string regex = lineStartRegex + versionRegex + lineEndRegex;
276289
dotnetCommandResult.Should().HaveStdOutMatching(regex);
277290
commandResult.Should().NotHaveStdErr();
291+
292+
TestOutputHelper.PopulateTestLoggerOutput(outputHelper, commandResult);
278293
}
279294

280295
[Theory]
296+
[Trait("MonitoringTest", "true")]
281297
[MemberData(nameof(InstallRuntimeFromChannelTestCases))]
282298
public void WhenInstallingWindowsdesktopRuntime(string channel, string? quality, string versionRegex)
283299
{
@@ -313,6 +329,8 @@ public void WhenInstallingWindowsdesktopRuntime(string channel, string? quality,
313329
commandResult.Should().NotHaveStdErr();
314330
commandResult.Should().HaveStdOutContaining("Installation finished");
315331

332+
TestOutputHelper.PopulateTestLoggerOutput(outputHelper, commandResult);
333+
316334
// Dotnet CLI is not included in the windowsdesktop runtime. Therefore, version validation cannot be tested.
317335
// Add the validation once the becomes available in the artifacts.
318336
}

tests/Install-Scripts.Test/Utils/CommandResultExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Taken from https://github.com/dotnet/sdk/
33

44
using Microsoft.DotNet.Cli.Utils;
5-
using Xunit.Abstractions;
65

76
namespace Microsoft.NET.TestFramework.Assertions
87
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.DotNet.Cli.Utils;
2+
using Xunit.Abstractions;
3+
4+
namespace Install_Scripts.Test.Utils
5+
{
6+
internal class TestOutputHelper
7+
{
8+
private const string TraceLogMarker = "#ISCO-TRACE";
9+
private const string ErrorLogMarker = "#ISCO-ERROR";
10+
private const string LogMarkerDelimiter = "!!";
11+
12+
// Transfers information to custom test adapter. E.g. install-scripts-monitoring -> TestLogger
13+
public static void PopulateTestLoggerOutput(ITestOutputHelper outputHelper, CommandResult commandResult)
14+
{
15+
if (!string.IsNullOrEmpty(commandResult.StdOut))
16+
{
17+
outputHelper.WriteLine(GetFormattedLogOutput(TraceLogMarker, commandResult.StdOut));
18+
}
19+
20+
if (!string.IsNullOrEmpty(commandResult.StdErr))
21+
{
22+
outputHelper.WriteLine(GetFormattedLogOutput(ErrorLogMarker, commandResult.StdErr));
23+
}
24+
}
25+
26+
private static string GetFormattedLogOutput(string logMarker, string message) =>
27+
$"{logMarker}-START{LogMarkerDelimiter}:{message}{logMarker}-END-{LogMarkerDelimiter}";
28+
}
29+
}

0 commit comments

Comments
 (0)