AccessPointE2ETests.cs 4.9 KB

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