AccessPointWorkflowTests.cs 4.7 KB

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