AccessPointE2ETests.cs 5.0 KB

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