ServerYamlE2ETests.cs 3.3 KB

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