mirror of
https://github.com/actions/runner.git
synced 2025-12-11 12:57:05 +00:00
Add a simple BrokerMessageListener L0 test (just to get that ball rolling)
This commit is contained in:
72
src/Test/L0/Listener/BrokerMessageListenerL0.cs
Normal file
72
src/Test/L0/Listener/BrokerMessageListenerL0.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GitHub.DistributedTask.WebApi;
|
||||
using GitHub.Runner.Listener;
|
||||
using GitHub.Runner.Listener.Configuration;
|
||||
using GitHub.Services.Common;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace GitHub.Runner.Common.Tests.Listener
|
||||
{
|
||||
public sealed class BrokerMessageListenerL0
|
||||
{
|
||||
private readonly RunnerSettings _settings;
|
||||
private readonly Mock<IConfigurationManager> _config;
|
||||
private readonly Mock<IBrokerServer> _brokerServer;
|
||||
private readonly Mock<ICredentialManager> _credMgr;
|
||||
|
||||
public BrokerMessageListenerL0()
|
||||
{
|
||||
_settings = new RunnerSettings { AgentId = 1, AgentName = "myagent", PoolId = 123, PoolName = "default", ServerUrlV2 = "http://myserver", WorkFolder = "_work" };
|
||||
_config = new Mock<IConfigurationManager>();
|
||||
_config.Setup(x => x.LoadSettings()).Returns(_settings);
|
||||
_brokerServer = new Mock<IBrokerServer>();
|
||||
_credMgr = new Mock<ICredentialManager>();
|
||||
_credMgr.Setup(x => x.LoadCredentials()).Returns(new VssCredentials());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Level", "L0")]
|
||||
[Trait("Category", "Runner")]
|
||||
public async void CreatesSession()
|
||||
{
|
||||
using TestHostContext tc = CreateTestContext();
|
||||
using var tokenSource = new CancellationTokenSource();
|
||||
var guid = new Guid();
|
||||
|
||||
// Arrange
|
||||
_brokerServer
|
||||
.Setup(
|
||||
x => x.ConnectAsync(
|
||||
new Uri(_settings.ServerUrlV2),
|
||||
It.Is<VssCredentials>(y => y != null)
|
||||
)
|
||||
)
|
||||
.Returns(
|
||||
Task.FromResult(
|
||||
new TaskAgentSession { SessionId = guid }
|
||||
)
|
||||
);
|
||||
BrokerMessageListener listener = new();
|
||||
listener.Initialize(tc);
|
||||
|
||||
// Act
|
||||
var result = await listener.CreateSessionAsync(tokenSource.Token);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
private TestHostContext CreateTestContext([CallerMemberName] String testName = "")
|
||||
{
|
||||
TestHostContext tc = new(this, testName);
|
||||
tc.SetSingleton<IConfigurationManager>(_config.Object);
|
||||
tc.SetSingleton<IBrokerServer>(_brokerServer.Object);
|
||||
tc.SetSingleton<ICredentialManager>(_credMgr.Object);
|
||||
return tc;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user