ConnectionCasingTests.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.ConnectionTests;
  4. // Reproduces https://github.com/Timmoth/RackPeek/issues/333 (CLI side):
  5. // `rpk connections add` stores the endpoint names as typed. ValidatePortReference
  6. // looks the resource up case-insensitively but never keeps its canonical Name,
  7. // so `connections add srv01 ...` against a resource named `Srv01` persists
  8. // `resource: srv01`. The Web UI then compares endpoints case-sensitively and
  9. // treats the port as unconnected.
  10. [Collection("Yaml CLI tests")]
  11. public class ConnectionCasingTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  12. : IClassFixture<TempYamlCliFixture> {
  13. private async Task<(string output, string yaml)> ExecuteAsync(params string[] args) {
  14. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  15. var output = await YamlCliTestHost.RunAsync(
  16. args,
  17. fs.Root,
  18. outputHelper,
  19. "config.yaml");
  20. outputHelper.WriteLine(output);
  21. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  22. return (output, yaml);
  23. }
  24. [Fact]
  25. public async Task connection_endpoints_are_stored_with_the_canonical_resource_casing() {
  26. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  27. await ExecuteAsync("switches", "add", "Core-SW-A");
  28. await ExecuteAsync("switches", "add", "Core-SW-B");
  29. await ExecuteAsync(
  30. "switches", "port", "add", "Core-SW-A",
  31. "--type", "rj45", "--speed", "1", "--count", "2");
  32. await ExecuteAsync(
  33. "switches", "port", "add", "Core-SW-B",
  34. "--type", "rj45", "--speed", "1", "--count", "2");
  35. // Endpoints typed in a different case from the stored names.
  36. (var output, var yaml) = await ExecuteAsync(
  37. "connections", "add",
  38. "core-sw-a", "0", "0",
  39. "core-sw-b", "0", "0",
  40. "--label", "probe-link");
  41. Assert.Contains("Connection created", output);
  42. // The stored endpoint must carry the canonical resource name, or every
  43. // case-sensitive consumer (PortLayout, PortGroupVisualizer, the
  44. // connection modal) treats the port as free.
  45. Assert.Contains("resource: Core-SW-A", yaml);
  46. Assert.Contains("resource: Core-SW-B", yaml);
  47. Assert.DoesNotContain("resource: core-sw-a", yaml);
  48. Assert.DoesNotContain("resource: core-sw-b", yaml);
  49. }
  50. }