Files
runner/src/Test/L0/Worker/ContainerOperationProviderL0.cs
T

73 lines
2.6 KiB
C#
Raw Normal View History

using GitHub.Runner.Worker;
using GitHub.Runner.Worker.Container;
using Xunit;
using Moq;
using GitHub.Runner.Worker.Container.ContainerHooks;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace GitHub.Runner.Common.Tests.Worker
{
public sealed class ContainerOperationProviderL0
{
private TestHostContext _hc;
private Mock<IExecutionContext> _ec;
private Mock<IDockerCommandManager> _dockerManager;
private Mock<IContainerHookManager> _containerHookManager;
private ContainerOperationProvider containerOperationProvider;
private Mock<IJobServerQueue> serverQueue;
private Mock<IPagingLogger> pagingLogger;
private List<string> healthyDockerStatus = new List<string> { "healthy" };
private List<string> dockerLogs = new List<string> { "log1", "log2", "log3" };
private ContainerInfo containerInfo;
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
public async void Healthchecktest_healthyDocker()
{
//Arrange
Setup();
_dockerManager.Setup(x => x.DockerInspect(_ec.Object, It.IsAny<string>(), It.IsAny<string>())).Returns(Task.FromResult(healthyDockerStatus));
//Act
var result = await containerOperationProvider.Healthcheck(_ec.Object, containerInfo);
//Assert
_dockerManager.Verify(dm => dm.DockerLogs(It.IsAny<IExecutionContext>(), It.IsAny<string>()), Times.Never());
}
private void Setup([CallerMemberName] string testName = "")
{
containerInfo = new ContainerInfo() { ContainerImage = "ubuntu:16.04" };
_hc = new TestHostContext(this, "name");
_ec = new Mock<IExecutionContext>();
serverQueue = new Mock<IJobServerQueue>();
pagingLogger = new Mock<IPagingLogger>();
_dockerManager = new Mock<IDockerCommandManager>();
_containerHookManager = new Mock<IContainerHookManager>();
containerOperationProvider = new ContainerOperationProvider();
_hc.SetSingleton<IDockerCommandManager>(_dockerManager.Object);
_hc.SetSingleton<IJobServerQueue>(serverQueue.Object);
_hc.SetSingleton<IPagingLogger>(pagingLogger.Object);
_hc.SetSingleton<IDockerCommandManager>(_dockerManager.Object);
_hc.SetSingleton<IContainerHookManager>(_containerHookManager.Object);
_ec.Setup(x => x.Global).Returns(new GlobalContext());
containerOperationProvider.Initialize(_hc);
}
}
}