DesktopWorkflowTests.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.DesktopTests;
  4. [Collection("Yaml CLI tests")]
  5. public class DesktopWorkflowTests(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. );
  15. outputHelper.WriteLine(output);
  16. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  17. return (output, yaml);
  18. }
  19. [Fact]
  20. public async Task desktops_cli_workflow_test() {
  21. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  22. // Add desktop
  23. (var output, var yaml) = await ExecuteAsync("desktops", "add", "workstation01");
  24. Assert.Equal("Desktop 'workstation01' added.\n", output);
  25. Assert.Contains("name: workstation01", yaml);
  26. // Update desktop
  27. (output, yaml) = await ExecuteAsync(
  28. "desktops", "set", "workstation01",
  29. "--model", "Dell Precision 7960"
  30. );
  31. Assert.Equal("Desktop 'workstation01' updated.\n", output);
  32. Assert.Contains("model: Dell Precision 7960", yaml);
  33. // Add CPU
  34. (output, yaml) = await ExecuteAsync(
  35. "desktops", "cpu", "add", "workstation01",
  36. "--model", "Intel Xeon W7-2495X",
  37. "--cores", "24",
  38. "--threads", "48"
  39. );
  40. Assert.Equal("CPU added to desktop 'workstation01'.\n", output);
  41. // Add Drive
  42. (output, yaml) = await ExecuteAsync(
  43. "desktops", "drive", "add", "workstation01",
  44. "--type", "ssd",
  45. "--size", "2000"
  46. );
  47. Assert.Equal("Drive added to desktop 'workstation01'.\n", output);
  48. // Add GPU
  49. (output, yaml) = await ExecuteAsync(
  50. "desktops", "gpu", "add", "workstation01",
  51. "--model", "NVIDIA RTX 4090",
  52. "--vram", "24"
  53. );
  54. Assert.Equal("GPU added to desktop 'workstation01'.\n", output);
  55. // Add NIC
  56. (output, yaml) = await ExecuteAsync(
  57. "desktops", "nic", "add", "workstation01",
  58. "--type", "rj45",
  59. "--speed", "10",
  60. "--ports", "2"
  61. );
  62. Assert.Equal("NIC added to desktop 'workstation01'.\n", output);
  63. // List desktops
  64. (output, yaml) = await ExecuteAsync("desktops", "list");
  65. Assert.Contains("workstation01", output);
  66. // Summary
  67. (output, yaml) = await ExecuteAsync("desktops", "summary");
  68. // Describe
  69. (output, yaml) = await ExecuteAsync("desktops", "describe", "workstation01");
  70. // Identity
  71. Assert.Contains("Desktop", output);
  72. Assert.Contains("workstation01", output);
  73. // Model
  74. Assert.Contains("Dell Precision 7960", output);
  75. // CPU summary
  76. Assert.Contains("CPUs:", output);
  77. Assert.Contains("1", output);
  78. // RAM summary
  79. Assert.Contains("RAM:", output);
  80. Assert.Contains("1", output);
  81. // Drive summary
  82. Assert.Contains("Drives:", output);
  83. Assert.Contains("1", output);
  84. // NIC summary
  85. Assert.Contains("NICs:", output);
  86. Assert.Contains("1", output);
  87. // GPU summary
  88. Assert.Contains("GPUs:", output);
  89. Assert.Contains("1", output);
  90. // ToDo Tree command not currently working as intended
  91. // Tree
  92. // (output, yaml) = await ExecuteAsync("desktops", "tree", "workstation01");
  93. // Assert.Contains("workstation01", output);
  94. // Assert.Contains("CPU:", output);
  95. // Assert.Contains("RAM:", output);
  96. // Assert.Contains("Drive:", output);
  97. // Assert.Contains("GPU:", output);
  98. // Assert.Contains("NIC:", output);
  99. // Delete desktop
  100. (output, yaml) = await ExecuteAsync("desktops", "del", "workstation01");
  101. Assert.Equal("""
  102. Desktop 'workstation01' deleted.
  103. """, output);
  104. }
  105. [Fact]
  106. public async Task desktops_tree_cli_workflow_test() {
  107. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  108. // Add desktop
  109. (var output, var yaml) = await ExecuteAsync("desktops", "add", "workstation01");
  110. Assert.Equal("Desktop 'workstation01' added.\n", output);
  111. // Add systems
  112. (output, yaml) = await ExecuteAsync("systems", "add", "sys01");
  113. Assert.Equal("System 'sys01' added.\n", output);
  114. (output, yaml) = await ExecuteAsync("systems", "add", "sys02");
  115. Assert.Equal("System 'sys02' added.\n", output);
  116. (output, yaml) = await ExecuteAsync("systems", "add", "sys03");
  117. Assert.Equal("System 'sys03' added.\n", output);
  118. // Attach systems
  119. await ExecuteAsync("systems", "set", "sys01", "--runs-on", "workstation01");
  120. await ExecuteAsync("systems", "set", "sys02", "--runs-on", "workstation01");
  121. await ExecuteAsync("systems", "set", "sys03", "--runs-on", "workstation01");
  122. // Add services
  123. await ExecuteAsync("services", "add", "immich");
  124. await ExecuteAsync("services", "add", "paperless");
  125. // Attach services
  126. await ExecuteAsync("services", "set", "immich", "--runs-on", "sys01");
  127. await ExecuteAsync("services", "set", "paperless", "--runs-on", "sys01");
  128. // Render tree
  129. (output, yaml) = await ExecuteAsync("desktops", "tree", "workstation01");
  130. Assert.Equal("""
  131. workstation01
  132. ├── System: sys01
  133. │ ├── Service: immich
  134. │ └── Service: paperless
  135. ├── System: sys02
  136. └── System: sys03
  137. """, output);
  138. }
  139. }