mirror of
https://github.com/actions/runner.git
synced 2025-12-10 04:06:57 +00:00
Compare commits
2 Commits
v2.323.0
...
fhammerl/s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
693e594e43 | ||
|
|
b7995ff076 |
@@ -19,6 +19,13 @@ namespace GitHub.Runner.Common
|
||||
{
|
||||
DefaultTraceLevel = TraceLevel.Verbose;
|
||||
}
|
||||
else if (int.TryParse(Environment.GetEnvironmentVariable("ACTIONS_RUNNER_TRACE_LEVEL"), out var traceLevel))
|
||||
{
|
||||
// force user's TraceLevel to comply with runner TraceLevel enums
|
||||
traceLevel = Math.Clamp(traceLevel, 0, 5);
|
||||
|
||||
DefaultTraceLevel = (TraceLevel)traceLevel;
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
|
||||
@@ -172,6 +172,43 @@ namespace GitHub.Runner.Common.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("randomString", "0", "VERB", "FALSELEVEL")]
|
||||
[InlineData("", "-1", "", "INFO")]
|
||||
[InlineData("", "6", "VERB", "FALSELEVEL")]
|
||||
[InlineData("", "99", "VERB", "FALSELEVEL")]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Common")]
|
||||
public void TraceLevel(string trace, string traceLevel, string mustContainTraceLevel, string mustNotContainTraceLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TRACE", trace);
|
||||
Environment.SetEnvironmentVariable("ACTIONS_RUNNER_TRACE_LEVEL", traceLevel);
|
||||
|
||||
// Arrange.
|
||||
Setup();
|
||||
_hc.SetDefaultCulture("hu-HU"); // logs [VERB] if traceLevel allows it
|
||||
|
||||
// Assert.
|
||||
var logFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"trace_{nameof(HostContextL0)}_{nameof(TraceLevel)}.log");
|
||||
var tempFile = Path.GetTempFileName();
|
||||
File.Delete(tempFile);
|
||||
File.Copy(logFile, tempFile);
|
||||
|
||||
var content = File.ReadAllText(tempFile);
|
||||
Assert.Contains($"{mustContainTraceLevel}", content);
|
||||
Assert.DoesNotContain($"{mustNotContainTraceLevel}", content);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_TRACE", null);
|
||||
Environment.SetEnvironmentVariable("ACTIONS_RUNNER_TRACE_LEVEL", null);
|
||||
// Cleanup.
|
||||
Teardown();
|
||||
}
|
||||
}
|
||||
|
||||
private void Setup([CallerMemberName] string testName = "")
|
||||
{
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
|
||||
Reference in New Issue
Block a user