ConnectionRemoveWorkflowTests.cs 3.6 KB

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