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