LaptopNicWorkflowTests.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.LaptopTests;
  4. [Collection("Yaml CLI tests")]
  5. public class LaptopNicWorkflowTests(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 laptop_nic_cli_workflow_test() {
  20. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  21. await ExecuteAsync("laptops", "add", "lap01");
  22. await ExecuteAsync("laptops", "set", "lap01", "--model", "ThinkPad X1 Carbon");
  23. // Built-in wired NIC.
  24. (var output, var yaml) = await ExecuteAsync(
  25. "laptops", "nic", "add", "lap01",
  26. "--type", "rj45",
  27. "--speed", "1",
  28. "--ports", "1"
  29. );
  30. Assert.Equal("NIC added to Laptop 'lap01'.\n", output);
  31. // Dock, attached over USB.
  32. (output, yaml) = await ExecuteAsync(
  33. "laptops", "nic", "add", "lap01",
  34. "--type", "usb",
  35. "--speed", "10",
  36. "--ports", "2"
  37. );
  38. Assert.Equal("NIC added to Laptop 'lap01'.\n", output);
  39. Assert.Equal("""
  40. version: 4
  41. resources:
  42. - kind: Laptop
  43. model: ThinkPad X1 Carbon
  44. ports:
  45. - type: rj45
  46. speed: 1
  47. count: 1
  48. - type: usb
  49. speed: 10
  50. count: 2
  51. name: lap01
  52. connections: []
  53. """, yaml);
  54. (output, yaml) = await ExecuteAsync(
  55. "laptops", "nic", "set", "lap01", "1",
  56. "--type", "usb",
  57. "--speed", "20",
  58. "--ports", "2"
  59. );
  60. Assert.Equal("NIC #1 updated on Laptop 'lap01'.\n", output);
  61. Assert.Contains("speed: 20", yaml);
  62. // Describe reports the NIC count, matching how desktops report theirs.
  63. (output, yaml) = await ExecuteAsync("laptops", "describe", "lap01");
  64. Assert.Contains("NICs:", output);
  65. Assert.Contains("2", output);
  66. (output, yaml) = await ExecuteAsync("laptops", "nic", "del", "lap01", "1");
  67. Assert.Equal("NIC #1 removed from Laptop 'lap01'.\n", output);
  68. Assert.Equal("""
  69. version: 4
  70. resources:
  71. - kind: Laptop
  72. model: ThinkPad X1 Carbon
  73. ports:
  74. - type: rj45
  75. speed: 1
  76. count: 1
  77. name: lap01
  78. connections: []
  79. """, yaml);
  80. }
  81. [Fact]
  82. public async Task describe_reports_zero_nics_when_laptop_has_none() {
  83. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  84. await ExecuteAsync("laptops", "add", "lap-bare");
  85. (var output, var _) = await ExecuteAsync("laptops", "describe", "lap-bare");
  86. Assert.Contains("NICs:", output);
  87. Assert.Contains("0", output);
  88. }
  89. }