sdk/test/Microsoft.NET.Build.Contain.../DockerDaemonTests.cs

51 строка
1.6 KiB
C#
Исходник Обычный вид История

2023-02-13 17:35:40 +03:00
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.NET.Build.Containers.UnitTests;
2023-03-15 14:36:28 +03:00
[CollectionDefinition("Daemon Tests")]
public class DaemonTestsCollection
{
2023-03-15 14:36:28 +03:00
}
[Collection("Daemon Tests")]
public class DockerDaemonTests : IDisposable
2023-02-13 17:35:40 +03:00
{
private ITestOutputHelper _testOutput;
private readonly TestLoggerFactory _loggerFactory;
public DockerDaemonTests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
_loggerFactory = new TestLoggerFactory(testOutput);
}
public void Dispose()
{
_loggerFactory.Dispose();
}
[DockerAvailableFact(skipPodman: true)] // podman is a local cli not meant for connecting to remote Docker daemons.
public async Task Can_detect_when_no_daemon_is_running()
{
2023-02-13 17:35:40 +03:00
// mimic no daemon running by setting the DOCKER_HOST to a nonexistent socket
try
{
Environment.SetEnvironmentVariable("DOCKER_HOST", "tcp://123.123.123.123:12345");
var available = await new DockerCli(_loggerFactory).IsAvailableAsync(default).ConfigureAwait(false);
2023-02-13 17:35:40 +03:00
Assert.False(available, "No daemon should be listening at that port");
}
finally
{
Environment.SetEnvironmentVariable("DOCKER_HOST", null);
2023-02-13 17:35:40 +03:00
}
}
[DockerAvailableFact]
public async Task Can_detect_when_daemon_is_running()
{
var available = await new DockerCli(_loggerFactory).IsAvailableAsync(default).ConfigureAwait(false);
2023-02-13 17:35:40 +03:00
Assert.True(available, "Should have found a working daemon");
}
}