AccessPointE2ETests.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd;
  4. [Collection("Yaml CLI tests")]
  5. public class AccessPointYamlE2ETests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture>
  7. {
  8. private async Task<(string, string)> ExecuteAsync(params string[] args)
  9. {
  10. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  11. var inputArgs = args.ToArray();
  12. var output = await YamlCliTestHost.RunAsync(
  13. inputArgs,
  14. fs.Root,
  15. outputHelper,
  16. "config.yaml");
  17. outputHelper.WriteLine(output);
  18. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  19. return (output, yaml);
  20. }
  21. [Fact]
  22. public async Task accesspoints_cli_workflow_test()
  23. {
  24. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  25. // Add AP
  26. var (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap01");
  27. Assert.Equal("Access Point 'ap01' added.\n", output);
  28. Assert.Contains("name: ap01", yaml);
  29. // Update AP
  30. (output, yaml) = await ExecuteAsync(
  31. "accesspoints", "set", "ap01",
  32. "--model", "Unifi-U6-Lite",
  33. "--speed", "1"
  34. );
  35. Assert.Equal("Access Point 'ap01' updated.\n", output);
  36. Assert.Equal("""
  37. resources:
  38. - kind: AccessPoint
  39. model: Unifi-U6-Lite
  40. speed: 1
  41. name: ap01
  42. tags:
  43. """, yaml);
  44. // Add second AP
  45. (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap02");
  46. Assert.Equal("Access Point 'ap02' added.\n", output);
  47. (output, yaml) = await ExecuteAsync(
  48. "accesspoints", "set", "ap02",
  49. "--model", "Aruba-AP-515",
  50. "--speed", "2.5"
  51. );
  52. Assert.Equal("Access Point 'ap02' updated.\n", output);
  53. Assert.Equal("""
  54. resources:
  55. - kind: AccessPoint
  56. model: Unifi-U6-Lite
  57. speed: 1
  58. name: ap01
  59. tags:
  60. - kind: AccessPoint
  61. model: Aruba-AP-515
  62. speed: 2.5
  63. name: ap02
  64. tags:
  65. """, yaml);
  66. // Get AP
  67. (output, yaml) = await ExecuteAsync("accesspoints", "get", "ap01");
  68. Assert.Equal("ap01 Model: Unifi-U6-Lite, Speed: 1Gbps\n", output);
  69. // List APs
  70. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  71. Assert.Equal("""
  72. ╭──────┬───────────────┬──────────────╮
  73. │ Name │ Model │ Speed (Gbps) │
  74. ├──────┼───────────────┼──────────────┤
  75. │ ap01 │ Unifi-U6-Lite │ 1 │
  76. │ ap02 │ Aruba-AP-515 │ 2.5 │
  77. ╰──────┴───────────────┴──────────────╯
  78. """, output);
  79. // Summary
  80. (output, yaml) = await ExecuteAsync("accesspoints", "summary");
  81. Assert.Equal("""
  82. ╭──────┬───────────────┬──────────────╮
  83. │ Name │ Model │ Speed (Gbps) │
  84. ├──────┼───────────────┼──────────────┤
  85. │ ap01 │ Unifi-U6-Lite │ 1 │
  86. │ ap02 │ Aruba-AP-515 │ 2.5 │
  87. ╰──────┴───────────────┴──────────────╯
  88. """, output);
  89. // Delete AP
  90. (output, yaml) = await ExecuteAsync("accesspoints", "del", "ap02");
  91. Assert.Equal("""
  92. Access Point 'ap02' deleted.
  93. """, output);
  94. // List again
  95. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  96. Assert.Equal("""
  97. ╭──────┬───────────────┬──────────────╮
  98. │ Name │ Model │ Speed (Gbps) │
  99. ├──────┼───────────────┼──────────────┤
  100. │ ap01 │ Unifi-U6-Lite │ 1 │
  101. ╰──────┴───────────────┴──────────────╯
  102. """, output);
  103. }
  104. }