mirror of
https://github.com/actions/runner.git
synced 2025-12-10 12:36:23 +00:00
121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Moq;
|
|
using Xunit;
|
|
using GitHub.Runner.Worker;
|
|
using GitHub.Runner.Worker.Handlers;
|
|
using GitHub.DistributedTask.Pipelines;
|
|
using GitHub.DistributedTask.WebApi;
|
|
|
|
namespace GitHub.Runner.Common.Tests.Worker
|
|
{
|
|
public sealed class HandlerFactoryL0
|
|
{
|
|
private Mock<IExecutionContext> _ec;
|
|
private TestHostContext CreateTestContext([CallerMemberName] string testName = "")
|
|
{
|
|
var hostContext = new TestHostContext(this, testName);
|
|
_ec = new Mock<IExecutionContext>();
|
|
_ec.SetupAllProperties();
|
|
_ec.Object.Initialize(hostContext);
|
|
var handler = new Mock<INodeScriptActionHandler>();
|
|
handler.SetupAllProperties();
|
|
hostContext.EnqueueInstance(handler.Object);
|
|
//hostContext.EnqueueInstance(new ActionCommandManager() as IActionCommandManager);
|
|
|
|
return hostContext;
|
|
}
|
|
|
|
[Theory]
|
|
[Trait("Level", "L0")]
|
|
[Trait("Category", "Worker")]
|
|
[InlineData("node12", "node20")]
|
|
[InlineData("node16", "node20")]
|
|
[InlineData("node20", "node20")]
|
|
[InlineData("node24", "node24")]
|
|
public void IsNodeVersionUpgraded(string inputVersion, string expectedVersion)
|
|
{
|
|
using (TestHostContext hc = CreateTestContext())
|
|
{
|
|
// Arrange.
|
|
var hf = new HandlerFactory();
|
|
hf.Initialize(hc);
|
|
|
|
// Setup variables
|
|
var variables = new Dictionary<string, VariableValue>();
|
|
Variables serverVariables = new(hc, variables);
|
|
|
|
// Workflow opt-out
|
|
var workflowVariables = new Dictionary<string, string>();
|
|
|
|
_ec.Setup(x => x.Global).Returns(new GlobalContext()
|
|
{
|
|
Variables = serverVariables,
|
|
EnvironmentVariables = workflowVariables
|
|
});
|
|
|
|
|
|
// Act.
|
|
var data = new NodeJSActionExecutionData();
|
|
data.NodeVersion = inputVersion;
|
|
var handler = hf.Create(
|
|
_ec.Object,
|
|
new ScriptReference(),
|
|
new Mock<IStepHost>().Object,
|
|
data,
|
|
new Dictionary<string, string>(),
|
|
new Dictionary<string, string>(),
|
|
new Variables(hc, new Dictionary<string, VariableValue>()), "", new List<JobExtensionRunner>()
|
|
) as INodeScriptActionHandler;
|
|
|
|
// Assert.
|
|
Assert.Equal(expectedVersion, handler.Data.NodeVersion);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
[Trait("Level", "L0")]
|
|
[Trait("Category", "Worker")]
|
|
public void Node24ExplicitlyRequested_HonoredByDefault()
|
|
{
|
|
using (TestHostContext hc = CreateTestContext())
|
|
{
|
|
// Arrange.
|
|
var hf = new HandlerFactory();
|
|
hf.Initialize(hc);
|
|
|
|
// Basic variables setup
|
|
var variables = new Dictionary<string, VariableValue>();
|
|
Variables serverVariables = new(hc, variables);
|
|
|
|
_ec.Setup(x => x.Global).Returns(new GlobalContext()
|
|
{
|
|
Variables = serverVariables,
|
|
EnvironmentVariables = new Dictionary<string, string>()
|
|
});
|
|
|
|
// Act - Node 24 explicitly requested in action.yml
|
|
var data = new NodeJSActionExecutionData();
|
|
data.NodeVersion = "node24";
|
|
var handler = hf.Create(
|
|
_ec.Object,
|
|
new ScriptReference(),
|
|
new Mock<IStepHost>().Object,
|
|
data,
|
|
new Dictionary<string, string>(),
|
|
new Dictionary<string, string>(),
|
|
new Variables(hc, new Dictionary<string, VariableValue>()),
|
|
"",
|
|
new List<JobExtensionRunner>()
|
|
) as INodeScriptActionHandler;
|
|
|
|
// Assert - should be node24 as requested
|
|
Assert.Equal("node24", handler.Data.NodeVersion);
|
|
}
|
|
}
|
|
}
|
|
}
|