SystemYamlE2ETests.cs 6.7 KB

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