AccessPointWorkflowTests.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. version: 2
  34. resources:
  35. - kind: AccessPoint
  36. model: Unifi-U6-Lite
  37. speed: 1
  38. name: ap01
  39. """, yaml);
  40. (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap02");
  41. Assert.Equal("Access Point 'ap02' added.\n", output);
  42. (output, yaml) = await ExecuteAsync(
  43. "accesspoints", "set", "ap02",
  44. "--model", "Aruba-AP-515",
  45. "--speed", "2.5"
  46. );
  47. Assert.Equal("Access Point 'ap02' updated.\n", output);
  48. Assert.Equal("""
  49. version: 2
  50. resources:
  51. - kind: AccessPoint
  52. model: Unifi-U6-Lite
  53. speed: 1
  54. name: ap01
  55. - kind: AccessPoint
  56. model: Aruba-AP-515
  57. speed: 2.5
  58. name: ap02
  59. """, yaml);
  60. (output, yaml) = await ExecuteAsync("accesspoints", "get", "ap01");
  61. Assert.Equal("ap01 Model: Unifi-U6-Lite, Speed: 1Gbps\n", output);
  62. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  63. Assert.Equal("""
  64. ╭──────┬───────────────┬──────────────╮
  65. │ Name │ Model │ Speed (Gbps) │
  66. ├──────┼───────────────┼──────────────┤
  67. │ ap01 │ Unifi-U6-Lite │ 1 │
  68. │ ap02 │ Aruba-AP-515 │ 2.5 │
  69. ╰──────┴───────────────┴──────────────╯
  70. """, output);
  71. (output, yaml) = await ExecuteAsync("accesspoints", "summary");
  72. Assert.Equal("""
  73. ╭──────┬───────────────┬──────────────╮
  74. │ Name │ Model │ Speed (Gbps) │
  75. ├──────┼───────────────┼──────────────┤
  76. │ ap01 │ Unifi-U6-Lite │ 1 │
  77. │ ap02 │ Aruba-AP-515 │ 2.5 │
  78. ╰──────┴───────────────┴──────────────╯
  79. """, output);
  80. (output, yaml) = await ExecuteAsync("accesspoints", "del", "ap02");
  81. Assert.Equal("""
  82. Access Point 'ap02' deleted.
  83. """, output);
  84. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  85. Assert.Equal("""
  86. ╭──────┬───────────────┬──────────────╮
  87. │ Name │ Model │ Speed (Gbps) │
  88. ├──────┼───────────────┼──────────────┤
  89. │ ap01 │ Unifi-U6-Lite │ 1 │
  90. ╰──────┴───────────────┴──────────────╯
  91. """, output);
  92. }
  93. }