PortConnectionWorkflowTests.cs 5.2 KB

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