SystemYamlE2ETests.cs 7.2 KB

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