SystemWorkflowTests.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.SystemTests;
  4. [Collection("Yaml CLI tests")]
  5. public class SystemWorkflowTests(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 output = await YamlCliTestHost.RunAsync(
  12. args,
  13. fs.Root,
  14. outputHelper,
  15. "config.yaml"
  16. );
  17. outputHelper.WriteLine(output);
  18. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  19. return (output, yaml);
  20. }
  21. [Fact]
  22. public async Task systems_cli_workflow_test()
  23. {
  24. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  25. await ExecuteAsync("servers", "add", "proxmox-node01");
  26. // Add system
  27. var (output, yaml) = await ExecuteAsync("systems", "add", "sys01");
  28. Assert.Equal("System 'sys01' added.\n", output);
  29. Assert.Contains("name: sys01", yaml);
  30. // Update system
  31. (output, yaml) = await ExecuteAsync(
  32. "systems", "set", "sys01",
  33. "--type", "VM",
  34. "--os", "debian-12",
  35. "--cores", "2",
  36. "--ram", "4",
  37. "--runs-on", "proxmox-node01"
  38. );
  39. Assert.Equal("System 'sys01' updated.\n", output);
  40. Assert.Equal("""
  41. version: 1
  42. resources:
  43. - kind: Server
  44. name: proxmox-node01
  45. - kind: System
  46. type: vm
  47. os: debian-12
  48. cores: 2
  49. ram: 4
  50. name: sys01
  51. runsOn: proxmox-node01
  52. """, yaml);
  53. // Get system
  54. (output, yaml) = await ExecuteAsync("systems", "get", "sys01");
  55. Assert.Equal("sys01 Type: vm, OS: debian-12, Cores: 2, RAM: 4GB, Storage: 0GB, RunsOn: \nproxmox-node01\n", output);
  56. // List systems (strict table)
  57. (output, yaml) = await ExecuteAsync("systems", "list");
  58. Assert.Equal("""
  59. ╭───────┬──────┬───────────┬───────┬──────────┬──────────────┬────────────────╮
  60. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage (GB) │ Runs On │
  61. ├───────┼──────┼───────────┼───────┼──────────┼──────────────┼────────────────┤
  62. │ sys01 │ vm │ debian-12 │ 2 │ 4 │ 0 │ proxmox-node01 │
  63. ╰───────┴──────┴───────────┴───────┴──────────┴──────────────┴────────────────╯
  64. """, output);
  65. // Summary (strict table)
  66. (output, yaml) = await ExecuteAsync("systems", "summary");
  67. Assert.Equal("""
  68. ╭───────┬──────┬───────────┬───────┬──────────┬──────────────┬────────────────╮
  69. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage (GB) │ Runs On │
  70. ├───────┼──────┼───────────┼───────┼──────────┼──────────────┼────────────────┤
  71. │ sys01 │ vm │ debian-12 │ 2 │ 4 │ 0 │ proxmox-node01 │
  72. ╰───────┴──────┴───────────┴───────┴──────────┴──────────────┴────────────────╯
  73. """, output);
  74. // Describe (loose)
  75. (output, yaml) = await ExecuteAsync("systems", "describe", "sys01");
  76. Assert.Contains("sys01", output);
  77. Assert.Contains("vm", output);
  78. Assert.Contains("debian-12", output);
  79. Assert.Contains("Cores", output);
  80. Assert.Contains("RAM", output);
  81. Assert.Contains("Runs On", output);
  82. // Tree (loose)
  83. (output, yaml) = await ExecuteAsync("systems", "tree", "sys01");
  84. Assert.Contains("sys01", output);
  85. // ToDo add a service in the workflow to properly test the tree functionality
  86. //Assert.Contains("Service:", output);
  87. // Delete system
  88. (output, yaml) = await ExecuteAsync("systems", "del", "sys01");
  89. Assert.Equal("""
  90. System 'sys01' deleted.
  91. """, output);
  92. }
  93. }