DockerUtils.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Xunit;
  4. namespace OhmGraphite.Test
  5. {
  6. public static class DockerUtils
  7. {
  8. public static string DockerEndpoint()
  9. {
  10. var host = Environment.GetEnvironmentVariable("DOCKER_HOST");
  11. if (host != null)
  12. {
  13. return host;
  14. }
  15. // https://github.com/HofmeisterAn/dotnet-testcontainers/tree/aa3d573129045a26de08e1fe57ccc180b1e04108/src/DotNet.Testcontainers/Services
  16. return RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
  17. ? "unix:/var/run/docker.sock"
  18. : "npipe://./pipe/docker_engine";
  19. }
  20. }
  21. public sealed class IgnoreOnRemoteDockerFactAttribute : FactAttribute
  22. {
  23. public IgnoreOnRemoteDockerFactAttribute()
  24. {
  25. if (Environment.GetEnvironmentVariable("DOCKER_HOST") != null)
  26. {
  27. Skip = "Ignore when executing against a remote docker instance";
  28. }
  29. }
  30. }
  31. }