SystemYamlE2ETests.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd;
  4. [Collection("Yaml CLI tests")]
  5. public class SystemYamlE2ETests(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 inputArgs = args.ToArray();
  12. var output = await YamlCliTestHost.RunAsync(
  13. inputArgs,
  14. fs.Root,
  15. outputHelper,
  16. "config.yaml");
  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. var (output, yaml) = await ExecuteAsync("servers", "add", "hypervisor01");
  26. (output, yaml) = await ExecuteAsync("systems", "add", "host01");
  27. Assert.Equal("System 'host01' added.\n", output);
  28. Assert.Equal("""
  29. resources:
  30. - kind: Server
  31. name: hypervisor01
  32. - kind: System
  33. name: host01
  34. """, yaml);
  35. // Update system
  36. (output, yaml) = await ExecuteAsync(
  37. "systems", "set", "host01",
  38. "--type", "baremetal",
  39. "--os", "ubuntu-22.04",
  40. "--cores", "4",
  41. "--ram", "8192",
  42. "--runs-on", "hypervisor01"
  43. );
  44. Assert.Equal("System 'host01' updated.\n", output);
  45. Assert.Equal("""
  46. resources:
  47. - kind: Server
  48. name: hypervisor01
  49. - kind: System
  50. type: baremetal
  51. os: ubuntu-22.04
  52. cores: 4
  53. ram: 8192
  54. runsOn: hypervisor01
  55. name: host01
  56. """, yaml);
  57. // Get system by name
  58. (output, yaml) = await ExecuteAsync("systems", "get", "host01");
  59. Assert.Equal(
  60. "host01 Type: baremetal, OS: ubuntu-22.04, Cores: 4, RAM: 8192GB, Storage: 0GB, \nRunsOn: hypervisor01\n",
  61. output);
  62. // List systems
  63. (output, yaml) = await ExecuteAsync("systems", "list");
  64. Assert.Equal("""
  65. ╭────────┬───────────┬────────────┬───────┬──────────┬────────────┬────────────╮
  66. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage │ Runs On │
  67. │ │ │ │ │ │ (GB) │ │
  68. ├────────┼───────────┼────────────┼───────┼──────────┼────────────┼────────────┤
  69. │ host01 │ baremetal │ ubuntu-22. │ 4 │ 8192 │ 0 │ hypervisor │
  70. │ │ │ 04 │ │ │ │ 01 │
  71. ╰────────┴───────────┴────────────┴───────┴──────────┴────────────┴────────────╯
  72. """, output);
  73. // Report systems
  74. (output, yaml) = await ExecuteAsync("systems", "summary");
  75. Assert.Equal("""
  76. ╭────────┬───────────┬────────────┬───────┬──────────┬────────────┬────────────╮
  77. │ Name │ Type │ OS │ Cores │ RAM (GB) │ Storage │ Runs On │
  78. │ │ │ │ │ │ (GB) │ │
  79. ├────────┼───────────┼────────────┼───────┼──────────┼────────────┼────────────┤
  80. │ host01 │ baremetal │ ubuntu-22. │ 4 │ 8192 │ 0 │ hypervisor │
  81. │ │ │ 04 │ │ │ │ 01 │
  82. ╰────────┴───────────┴────────────┴───────┴──────────┴────────────┴────────────╯
  83. """, output);
  84. // Delete system
  85. (output, yaml) = await ExecuteAsync("systems", "del", "host01");
  86. Assert.Equal("""
  87. System 'host01' deleted.
  88. """, output);
  89. // Ensure list is empty
  90. (output, yaml) = await ExecuteAsync("systems", "list");
  91. Assert.Equal("""
  92. No systems found.
  93. """, output);
  94. }
  95. [Fact]
  96. public async Task system_tree_cli_workflow_test()
  97. {
  98. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  99. var (output, yaml) = await ExecuteAsync("systems", "add", "host01");
  100. Assert.Equal("System 'host01' added.\n", output);
  101. (output, yaml) = await ExecuteAsync("services", "add", "immich");
  102. Assert.Equal("Service 'immich' added.\n", output);
  103. (output, yaml) = await ExecuteAsync("services", "add", "paperless");
  104. Assert.Equal("Service 'paperless' added.\n", output);
  105. (output, yaml) = await ExecuteAsync(
  106. "services", "set", "immich",
  107. "--runs-on", "host01"
  108. );
  109. (output, yaml) = await ExecuteAsync(
  110. "services", "set", "paperless",
  111. "--runs-on", "host01"
  112. );
  113. (output, yaml) = await ExecuteAsync("systems", "tree", "host01");
  114. Assert.Equal("""
  115. host01
  116. ├── Service: immich
  117. └── Service: paperless
  118. """, output);
  119. }
  120. }