OtherPortWorkflowTests.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.OtherTests;
  4. [Collection("Yaml CLI tests")]
  5. public class OtherPortWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture> {
  7. private async Task<(string, string)> ExecuteAsync(params string[] args) {
  8. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  9. var output = await YamlCliTestHost.RunAsync(
  10. args,
  11. fs.Root,
  12. outputHelper,
  13. "config.yaml");
  14. outputHelper.WriteLine(output);
  15. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  16. return (output, yaml);
  17. }
  18. [Fact]
  19. public async Task other_port_cli_workflow_test() {
  20. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  21. await ExecuteAsync("other", "add", "decoder01");
  22. await ExecuteAsync(
  23. "other", "set", "decoder01",
  24. "--model", "TVIP-v605",
  25. "--description", "IPTV set-top box"
  26. );
  27. (var output, var yaml) = await ExecuteAsync(
  28. "other", "port", "add", "decoder01",
  29. "--type", "rj45",
  30. "--speed", "0.1",
  31. "--count", "1"
  32. );
  33. Assert.Equal("Port added to other hardware 'decoder01'.\n", output);
  34. (output, yaml) = await ExecuteAsync(
  35. "other", "port", "add", "decoder01",
  36. "--type", "usb",
  37. "--speed", "0.48",
  38. "--count", "2"
  39. );
  40. Assert.Equal("Port added to other hardware 'decoder01'.\n", output);
  41. Assert.Equal("""
  42. version: 4
  43. resources:
  44. - kind: Other
  45. model: TVIP-v605
  46. description: IPTV set-top box
  47. ports:
  48. - type: rj45
  49. speed: 0.1
  50. count: 1
  51. - type: usb
  52. speed: 0.48
  53. count: 2
  54. name: decoder01
  55. connections: []
  56. """, yaml);
  57. (output, yaml) = await ExecuteAsync(
  58. "other", "port", "set", "decoder01",
  59. "--index", "1",
  60. "--type", "usb",
  61. "--speed", "0.48",
  62. "--count", "3"
  63. );
  64. Assert.Equal("Port #1 updated on other hardware 'decoder01'.\n", output);
  65. Assert.Contains("count: 3", yaml);
  66. (output, yaml) = await ExecuteAsync("other", "describe", "decoder01");
  67. Assert.Contains("Ports:", output);
  68. Assert.Contains("rj45: 1", output);
  69. Assert.Contains("usb: 3", output);
  70. (output, yaml) = await ExecuteAsync("other", "port", "del", "decoder01", "--index", "0");
  71. Assert.Equal("Port #0 removed from other hardware 'decoder01'.\n", output);
  72. Assert.Equal("""
  73. version: 4
  74. resources:
  75. - kind: Other
  76. model: TVIP-v605
  77. description: IPTV set-top box
  78. ports:
  79. - type: usb
  80. speed: 0.48
  81. count: 3
  82. name: decoder01
  83. connections: []
  84. """, yaml);
  85. }
  86. [Fact]
  87. public async Task describe_reports_none_when_other_has_no_ports() {
  88. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  89. await ExecuteAsync("other", "add", "bare01");
  90. (var output, var _) = await ExecuteAsync("other", "describe", "bare01");
  91. Assert.Contains("Ports:", output);
  92. Assert.Contains("None", output);
  93. }
  94. }