DiscoverDockerEndpointTests.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.DiscoveryTests;
  4. /// <summary>
  5. /// `rpk discover docker` against endpoints it cannot reach. Every case here fails
  6. /// before any container is listed, so these tests never talk to a daemon.
  7. /// </summary>
  8. [Collection("Yaml CLI tests")]
  9. public class DiscoverDockerEndpointTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  10. : IClassFixture<TempYamlCliFixture> {
  11. private async Task<string> ExecuteAsync(params string[] args) =>
  12. await YamlCliTestHost.RunAsync(args, fs.Root, outputHelper, "config.yaml");
  13. [Theory]
  14. [InlineData("ssh://user@nas")]
  15. [InlineData("npipe:////./pipe/docker_engine")]
  16. public async Task an_endpoint_that_cannot_be_dialled_says_so_instead_of_crashing(string endpoint) {
  17. // `docker context` sets ssh:// for a remote host and npipe:// is the Windows
  18. // default, so both are ordinary values to find in DOCKER_HOST. They used to
  19. // reach HttpClient, which accepts the URI and throws NotSupportedException on
  20. // the first request — past the command's catch list, so the user got
  21. // "Unexpected error occurred" and a stack trace.
  22. var output = await ExecuteAsync("discover", "docker", "--docker-host", endpoint);
  23. Assert.DoesNotContain("Unexpected error", output);
  24. Assert.DoesNotContain("at RackPeek.", output);
  25. // And the message says what to do about it.
  26. Assert.Contains("ssh -L", output);
  27. }
  28. }