ServerYamlE2ETests.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd;
  4. [Collection("Yaml CLI tests")]
  5. public class ServerYamlE2ETests(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. );
  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 servers_cli_workflow_test()
  23. {
  24. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  25. // Add switch
  26. var (output, yaml) = await ExecuteAsync("servers", "add", "node01");
  27. Assert.Equal("Server 'node01' added.\n", output);
  28. Assert.Contains("name: node01", yaml);
  29. }
  30. [Fact]
  31. public async Task servers_tree_cli_workflow_test()
  32. {
  33. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  34. // Add switch
  35. var (output, yaml) = await ExecuteAsync("servers", "add", "node01");
  36. Assert.Equal("Server 'node01' added.\n", output);
  37. Assert.Contains("name: node01", yaml);
  38. (output, yaml) = await ExecuteAsync("systems", "add", "host01");
  39. Assert.Equal("System 'host01' added.\n", output);
  40. (output, yaml) = await ExecuteAsync("systems", "add", "host02");
  41. Assert.Equal("System 'host02' added.\n", output);
  42. (output, yaml) = await ExecuteAsync("systems", "add", "host03");
  43. Assert.Equal("System 'host03' added.\n", output);
  44. (output, yaml) = await ExecuteAsync(
  45. "systems", "set", "host01",
  46. "--runs-on", "node01"
  47. );
  48. Assert.Equal("System 'host01' updated.\n", output);
  49. (output, yaml) = await ExecuteAsync(
  50. "systems", "set", "host02",
  51. "--runs-on", "node01"
  52. );
  53. Assert.Equal("System 'host02' updated.\n", output);
  54. (output, yaml) = await ExecuteAsync(
  55. "systems", "set", "host03",
  56. "--runs-on", "node01"
  57. );
  58. Assert.Equal("System 'host03' updated.\n", output);
  59. (output, yaml) = await ExecuteAsync("services", "add", "immich");
  60. Assert.Equal("Service 'immich' added.\n", output);
  61. (output, yaml) = await ExecuteAsync("services", "add", "paperless");
  62. Assert.Equal("Service 'paperless' added.\n", output);
  63. (output, yaml) = await ExecuteAsync(
  64. "services", "set", "immich",
  65. "--runs-on", "host01"
  66. );
  67. (output, yaml) = await ExecuteAsync(
  68. "services", "set", "paperless",
  69. "--runs-on", "host01"
  70. );
  71. (output, yaml) = await ExecuteAsync("servers", "tree", "node01");
  72. Assert.Equal("""
  73. node01
  74. ├── System: host01
  75. │ ├── Service: immich
  76. │ └── Service: paperless
  77. ├── System: host02
  78. └── System: host03
  79. """, output);
  80. }
  81. }