SystemWorkflowTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. outputHelper.WriteLine(yaml);
  41. Assert.Equal("""
  42. version: 2
  43. resources:
  44. - kind: Server
  45. name: proxmox-node01
  46. - kind: System
  47. type: vm
  48. os: debian-12
  49. cores: 2
  50. ram: 4
  51. name: sys01
  52. runsOn:
  53. - proxmox-node01
  54. """, yaml);
  55. // Get system
  56. (output, yaml) = await ExecuteAsync("systems", "get", "sys01");
  57. Assert.Equal("sys01 Type: vm, OS: debian-12, Cores: 2, RAM: 4GB, Storage: 0GB, RunsOn: \nproxmox-node01\n", output);
  58. // List systems (strict table)
  59. (output, yaml) = await ExecuteAsync("systems", "list");
  60. Assert.Equal("""
  61. ╭───────┬──────┬───────────┬───────┬──────────┬──────────────┬────────────────╮
  62. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage (GB) │ Runs On │
  63. ├───────┼──────┼───────────┼───────┼──────────┼──────────────┼────────────────┤
  64. │ sys01 │ vm │ debian-12 │ 2 │ 4 │ 0 │ proxmox-node01 │
  65. ╰───────┴──────┴───────────┴───────┴──────────┴──────────────┴────────────────╯
  66. """, output);
  67. // Summary (strict table)
  68. (output, yaml) = await ExecuteAsync("systems", "summary");
  69. Assert.Equal("""
  70. ╭───────┬──────┬───────────┬───────┬──────────┬──────────────┬────────────────╮
  71. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage (GB) │ Runs On │
  72. ├───────┼──────┼───────────┼───────┼──────────┼──────────────┼────────────────┤
  73. │ sys01 │ vm │ debian-12 │ 2 │ 4 │ 0 │ proxmox-node01 │
  74. ╰───────┴──────┴───────────┴───────┴──────────┴──────────────┴────────────────╯
  75. """, output);
  76. // Describe (loose)
  77. (output, yaml) = await ExecuteAsync("systems", "describe", "sys01");
  78. Assert.Contains("sys01", output);
  79. Assert.Contains("vm", output);
  80. Assert.Contains("debian-12", output);
  81. Assert.Contains("Cores", output);
  82. Assert.Contains("RAM", output);
  83. Assert.Contains("Runs On", output);
  84. // Tree (loose)
  85. (output, yaml) = await ExecuteAsync("systems", "tree", "sys01");
  86. Assert.Contains("sys01", output);
  87. // ToDo add a service in the workflow to properly test the tree functionality
  88. //Assert.Contains("Service:", output);
  89. // Delete system
  90. (output, yaml) = await ExecuteAsync("systems", "del", "sys01");
  91. Assert.Equal("""
  92. System 'sys01' deleted.
  93. """, output);
  94. }
  95. }