AccessPointE2ETests.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. );
  18. outputHelper.WriteLine(output);
  19. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  20. return (output, yaml);
  21. }
  22. [Fact]
  23. public async Task accesspoints_cli_workflow_test()
  24. {
  25. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  26. // Add AP
  27. var (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap01");
  28. Assert.Equal("Access Point 'ap01' added.\n", output);
  29. Assert.Contains("name: ap01", yaml);
  30. // Update AP
  31. (output, yaml) = await ExecuteAsync(
  32. "accesspoints", "set", "ap01",
  33. "--model", "Unifi-U6-Lite",
  34. "--speed", "1"
  35. );
  36. Assert.Equal("Access Point 'ap01' updated.\n", output);
  37. Assert.Equal("""
  38. resources:
  39. - kind: AccessPoint
  40. model: Unifi-U6-Lite
  41. speed: 1
  42. name: ap01
  43. tags:
  44. """, yaml);
  45. // Add second AP
  46. (output, yaml) = await ExecuteAsync("accesspoints", "add", "ap02");
  47. Assert.Equal("Access Point 'ap02' added.\n", output);
  48. (output, yaml) = await ExecuteAsync(
  49. "accesspoints", "set", "ap02",
  50. "--model", "Aruba-AP-515",
  51. "--speed", "2.5"
  52. );
  53. Assert.Equal("Access Point 'ap02' updated.\n", output);
  54. Assert.Equal("""
  55. resources:
  56. - kind: AccessPoint
  57. model: Unifi-U6-Lite
  58. speed: 1
  59. name: ap01
  60. tags:
  61. - kind: AccessPoint
  62. model: Aruba-AP-515
  63. speed: 2.5
  64. name: ap02
  65. tags:
  66. """, yaml);
  67. // Get AP
  68. (output, yaml) = await ExecuteAsync("accesspoints", "get", "ap01");
  69. Assert.Equal("ap01 Model: Unifi-U6-Lite, Speed: 1Gbps\n", output);
  70. // List APs
  71. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  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. // Summary
  81. (output, yaml) = await ExecuteAsync("accesspoints", "summary");
  82. Assert.Equal("""
  83. ╭──────┬───────────────┬──────────────╮
  84. │ Name │ Model │ Speed (Gbps) │
  85. ├──────┼───────────────┼──────────────┤
  86. │ ap01 │ Unifi-U6-Lite │ 1 │
  87. │ ap02 │ Aruba-AP-515 │ 2.5 │
  88. ╰──────┴───────────────┴──────────────╯
  89. """, output);
  90. // Delete AP
  91. (output, yaml) = await ExecuteAsync("accesspoints", "del", "ap02");
  92. Assert.Equal("""
  93. Access Point 'ap02' deleted.
  94. """, output);
  95. // List again
  96. (output, yaml) = await ExecuteAsync("accesspoints", "list");
  97. Assert.Equal("""
  98. ╭──────┬───────────────┬──────────────╮
  99. │ Name │ Model │ Speed (Gbps) │
  100. ├──────┼───────────────┼──────────────┤
  101. │ ap01 │ Unifi-U6-Lite │ 1 │
  102. ╰──────┴───────────────┴──────────────╯
  103. """, output);
  104. }
  105. }