PortConnectionWorkflowTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.ConnectionTests;
  4. [Collection("Yaml CLI tests")]
  5. public class PortConnectionWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture>
  7. {
  8. private async Task<(string output, string yaml)> ExecuteAsync(params string[] args)
  9. {
  10. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  11. var output = await YamlCliTestHost.RunAsync(
  12. args,
  13. fs.Root,
  14. outputHelper,
  15. "config.yaml");
  16. outputHelper.WriteLine(output);
  17. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  18. return (output, yaml);
  19. }
  20. [Theory]
  21. [InlineData("switches", "routers")]
  22. [InlineData("firewalls", "routers")]
  23. public async Task removing_port_removes_connections(string aType, string bType)
  24. {
  25. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  26. await ExecuteAsync(aType, "add", "node-a");
  27. await ExecuteAsync(bType, "add", "node-b");
  28. await ExecuteAsync(aType, "port", "add", "node-a",
  29. "--type", "RJ45",
  30. "--speed", "1",
  31. "--count", "2");
  32. await ExecuteAsync(bType, "port", "add", "node-b",
  33. "--type", "RJ45",
  34. "--speed", "1",
  35. "--count", "2");
  36. await ExecuteAsync("connections", "add",
  37. "node-a", "0", "0",
  38. "node-b", "0", "0");
  39. (var output, var yaml) = await ExecuteAsync(
  40. aType, "port", "del", "node-a",
  41. "--index", "0");
  42. Assert.Contains("Port 0 removed", output);
  43. Assert.Contains("connections: []", yaml);
  44. }
  45. [Theory]
  46. [InlineData("switches", "routers")]
  47. [InlineData("firewalls", "routers")]
  48. public async Task removing_port_shifts_connection_groups(string aType, string bType)
  49. {
  50. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  51. await ExecuteAsync(aType, "add", "node-a");
  52. await ExecuteAsync(bType, "add", "node-b");
  53. await ExecuteAsync(aType, "port", "add", "node-a",
  54. "--type", "RJ45",
  55. "--speed", "1",
  56. "--count", "1");
  57. await ExecuteAsync(aType, "port", "add", "node-a",
  58. "--type", "RJ45",
  59. "--speed", "1",
  60. "--count", "1");
  61. await ExecuteAsync(bType, "port", "add", "node-b",
  62. "--type", "RJ45",
  63. "--speed", "1",
  64. "--count", "1");
  65. await ExecuteAsync("connections", "add",
  66. "node-a", "1", "0",
  67. "node-b", "0", "0");
  68. await ExecuteAsync(
  69. aType, "port", "del", "node-a",
  70. "--index", "0");
  71. (string output, string yaml) executeAsync = await ExecuteAsync(
  72. "connections", "add",
  73. "node-a", "0", "0",
  74. "node-b", "0", "0");
  75. Assert.Contains("node-a", executeAsync.yaml);
  76. Assert.Contains("node-b", executeAsync.yaml);
  77. }
  78. [Theory]
  79. [InlineData("switches", "routers")]
  80. [InlineData("firewalls", "routers")]
  81. public async Task shrinking_port_count_removes_connections(string aType, string bType)
  82. {
  83. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  84. await ExecuteAsync(aType, "add", "node-a");
  85. await ExecuteAsync(bType, "add", "node-b");
  86. await ExecuteAsync(aType, "port", "add", "node-a",
  87. "--type", "RJ45",
  88. "--speed", "1",
  89. "--count", "3");
  90. await ExecuteAsync(bType, "port", "add", "node-b",
  91. "--type", "RJ45",
  92. "--speed", "1",
  93. "--count", "3");
  94. await ExecuteAsync("connections", "add",
  95. "node-a", "0", "2",
  96. "node-b", "0", "0");
  97. await ExecuteAsync(
  98. aType, "port", "set", "node-a",
  99. "--index", "0",
  100. "--count", "1");
  101. (string output, string yaml) executeAsync = await ExecuteAsync(
  102. "connections", "add",
  103. "node-a", "0", "0",
  104. "node-b", "0", "1");
  105. Assert.Contains("node-a", executeAsync.yaml);
  106. }
  107. [Theory]
  108. [InlineData("switches", "routers")]
  109. [InlineData("firewalls", "routers")]
  110. public async Task shrinking_port_count_preserves_valid_connections(string aType, string bType)
  111. {
  112. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  113. await ExecuteAsync(aType, "add", "node-a");
  114. await ExecuteAsync(bType, "add", "node-b");
  115. await ExecuteAsync(aType, "port", "add", "node-a",
  116. "--type", "RJ45",
  117. "--speed", "1",
  118. "--count", "3");
  119. await ExecuteAsync(bType, "port", "add", "node-b",
  120. "--type", "RJ45",
  121. "--speed", "1",
  122. "--count", "3");
  123. await ExecuteAsync("connections", "add",
  124. "node-a", "0", "0",
  125. "node-b", "0", "0");
  126. await ExecuteAsync(
  127. aType, "port", "set", "node-a",
  128. "--index", "0",
  129. "--count", "2");
  130. (string output, string yaml) executeAsync = await ExecuteAsync(
  131. "connections", "add",
  132. "node-a", "0", "1",
  133. "node-b", "0", "1");
  134. Assert.Contains("node-a", executeAsync.yaml);
  135. }
  136. }