AccessPointWorkflowTests.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.AccessPointTests;
  4. [Collection("Yaml CLI tests")]
  5. public class AccessPointWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture> {
  7. private async Task<(string, string)> 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. [Fact]
  19. public async Task accesspoints_cli_workflow_test() {
  20. (var output, var yaml) = await ExecuteAsync("accesspoints", "add", "ap01");
  21. Assert.Equal("Access Point 'ap01' added.\n", output);
  22. Assert.Contains("name: ap01", yaml);
  23. (output, yaml) = await ExecuteAsync(
  24. "accesspoints", "set", "ap01",
  25. "--model", "Unifi-U6-Lite",
  26. "--speed", "1"
  27. );
  28. Assert.Equal("Access Point 'ap01' updated.\n", output);
  29. Assert.Equal("""
  30. version: 2
  31. resources:
  32. - kind: AccessPoint
  33. model: Unifi-U6-Lite
  34. speed: 1
  35. name: ap01
  36. """, yaml);
  37. (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap02");
  38. Assert.Equal("Access Point 'ap02' added.\n", output);
  39. (output, yaml) = await ExecuteAsync(
  40. "accesspoints", "set", "ap02",
  41. "--model", "Aruba-AP-515",
  42. "--speed", "2.5"
  43. );
  44. Assert.Equal("Access Point 'ap02' updated.\n", output);
  45. Assert.Equal("""
  46. version: 2
  47. resources:
  48. - kind: AccessPoint
  49. model: Unifi-U6-Lite
  50. speed: 1
  51. name: ap01
  52. - kind: AccessPoint
  53. model: Aruba-AP-515
  54. speed: 2.5
  55. name: ap02
  56. """, yaml);
  57. (output, yaml) = await ExecuteAsync("accesspoints", "get", "ap01");
  58. Assert.Equal("ap01 Model: Unifi-U6-Lite, Speed: 1Gbps\n", output);
  59. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  60. Assert.Equal("""
  61. ╭──────┬───────────────┬──────────────╮
  62. │ Name │ Model │ Speed (Gbps) │
  63. ├──────┼───────────────┼──────────────┤
  64. │ ap01 │ Unifi-U6-Lite │ 1 │
  65. │ ap02 │ Aruba-AP-515 │ 2.5 │
  66. ╰──────┴───────────────┴──────────────╯
  67. """, output);
  68. (output, yaml) = await ExecuteAsync("accesspoints", "summary");
  69. Assert.Equal("""
  70. ╭──────┬───────────────┬──────────────╮
  71. │ Name │ Model │ Speed (Gbps) │
  72. ├──────┼───────────────┼──────────────┤
  73. │ ap01 │ Unifi-U6-Lite │ 1 │
  74. │ ap02 │ Aruba-AP-515 │ 2.5 │
  75. ╰──────┴───────────────┴──────────────╯
  76. """, output);
  77. (output, yaml) = await ExecuteAsync("accesspoints", "del", "ap02");
  78. Assert.Equal("""
  79. Access Point 'ap02' deleted.
  80. """, output);
  81. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  82. Assert.Equal("""
  83. ╭──────┬───────────────┬──────────────╮
  84. │ Name │ Model │ Speed (Gbps) │
  85. ├──────┼───────────────┼──────────────┤
  86. │ ap01 │ Unifi-U6-Lite │ 1 │
  87. ╰──────┴───────────────┴──────────────╯
  88. """, output);
  89. }
  90. }