ConnectionRemoveWorkflowTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.ConnectionTests;
  4. [Collection("Yaml CLI tests")]
  5. public class ConnectionRemoveWorkflowTests(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 connections_remove_cli_workflow_test(string aType, string bType)
  24. {
  25. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  26. // Create resources
  27. await ExecuteAsync(aType, "add", "node-a");
  28. await ExecuteAsync(bType, "add", "node-b");
  29. // Add ports
  30. await ExecuteAsync(
  31. aType, "port", "add", "node-a",
  32. "--type", "RJ45",
  33. "--speed", "1",
  34. "--count", "2"
  35. );
  36. await ExecuteAsync(
  37. bType, "port", "add", "node-b",
  38. "--type", "RJ45",
  39. "--speed", "1",
  40. "--count", "2"
  41. );
  42. // Create connection
  43. await ExecuteAsync(
  44. "connections", "add",
  45. "node-a", "0", "0",
  46. "node-b", "0", "0"
  47. );
  48. // Remove connection
  49. (var output, var yaml) = await ExecuteAsync(
  50. "connections", "remove",
  51. "node-a", "0", "0"
  52. );
  53. Assert.Contains("Connection removed", output);
  54. // YAML should no longer contain connection
  55. outputHelper.WriteLine(yaml);
  56. Assert.Contains("connections: []", yaml);
  57. }
  58. [Fact]
  59. public async Task removing_connection_from_other_endpoint_works()
  60. {
  61. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  62. await ExecuteAsync("servers", "add", "srv01");
  63. await ExecuteAsync("servers", "add", "srv02");
  64. await ExecuteAsync(
  65. "servers", "nic", "add", "srv01",
  66. "--type", "RJ45",
  67. "--speed", "1",
  68. "--ports", "1"
  69. );
  70. await ExecuteAsync(
  71. "servers", "nic", "add", "srv02",
  72. "--type", "RJ45",
  73. "--speed", "1",
  74. "--ports", "1"
  75. );
  76. await ExecuteAsync(
  77. "connections", "add",
  78. "srv01", "0", "0",
  79. "srv02", "0", "0"
  80. );
  81. // Remove using other side
  82. (var output, var yaml) = await ExecuteAsync(
  83. "connections", "remove",
  84. "srv02", "0", "0"
  85. );
  86. Assert.Contains("Connection removed", output);
  87. outputHelper.WriteLine(yaml);
  88. Assert.Contains("connections: []", yaml);
  89. }
  90. [Fact]
  91. public async Task removing_nonexistent_connection_is_safe()
  92. {
  93. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  94. await ExecuteAsync("switches", "add", "sw01");
  95. await ExecuteAsync(
  96. "switches", "port", "add", "sw01",
  97. "--type", "RJ45",
  98. "--speed", "1",
  99. "--count", "2"
  100. );
  101. (var output, _) = await ExecuteAsync(
  102. "connections", "remove",
  103. "sw01", "0", "0"
  104. );
  105. Assert.Contains("Connection removed", output);
  106. }
  107. }