AccessPointE2ETests.cs 4.8 KB

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