4
0

ServerYamlE2ETests.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_labels_cli_workflow_test()
  24. {
  25. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  26. // Create server
  27. var (output, yaml) = await ExecuteAsync("servers", "add", "web-01");
  28. Assert.Contains("web-01", yaml);
  29. // Add label
  30. (output, yaml) = await ExecuteAsync("servers", "label", "add", "web-01", "--key", "env", "--value", "production");
  31. Assert.Contains("Label 'env' added", output);
  32. Assert.Contains("env:", yaml);
  33. Assert.Contains("production", yaml);
  34. // Describe should show label
  35. (output, _) = await ExecuteAsync("servers", "describe", "web-01");
  36. Assert.Contains("env", output);
  37. Assert.Contains("production", output);
  38. // Remove label
  39. (output, yaml) = await ExecuteAsync("servers", "label", "remove", "web-01", "--key", "env");
  40. Assert.Contains("Label 'env' removed", output);
  41. Assert.DoesNotContain("env:", yaml);
  42. }
  43. [Fact]
  44. public async Task servers_cli_workflow_test()
  45. {
  46. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  47. // Add switch
  48. var (output, yaml) = await ExecuteAsync("servers", "add", "node01");
  49. Assert.Equal("Server 'node01' added.\n", output);
  50. Assert.Contains("name: node01", yaml);
  51. }
  52. [Fact]
  53. public async Task servers_tree_cli_workflow_test()
  54. {
  55. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  56. // Add switch
  57. var (output, yaml) = await ExecuteAsync("servers", "add", "node01");
  58. Assert.Equal("Server 'node01' added.\n", output);
  59. Assert.Contains("name: node01", yaml);
  60. (output, yaml) = await ExecuteAsync("systems", "add", "host01");
  61. Assert.Equal("System 'host01' added.\n", output);
  62. (output, yaml) = await ExecuteAsync("systems", "add", "host02");
  63. Assert.Equal("System 'host02' added.\n", output);
  64. (output, yaml) = await ExecuteAsync("systems", "add", "host03");
  65. Assert.Equal("System 'host03' added.\n", output);
  66. (output, yaml) = await ExecuteAsync(
  67. "systems", "set", "host01",
  68. "--runs-on", "node01"
  69. );
  70. Assert.Equal("System 'host01' updated.\n", output);
  71. (output, yaml) = await ExecuteAsync(
  72. "systems", "set", "host02",
  73. "--runs-on", "node01"
  74. );
  75. Assert.Equal("System 'host02' updated.\n", output);
  76. (output, yaml) = await ExecuteAsync(
  77. "systems", "set", "host03",
  78. "--runs-on", "node01"
  79. );
  80. Assert.Equal("System 'host03' updated.\n", output);
  81. (output, yaml) = await ExecuteAsync("services", "add", "immich");
  82. Assert.Equal("Service 'immich' added.\n", output);
  83. (output, yaml) = await ExecuteAsync("services", "add", "paperless");
  84. Assert.Equal("Service 'paperless' added.\n", output);
  85. (output, yaml) = await ExecuteAsync(
  86. "services", "set", "immich",
  87. "--runs-on", "host01"
  88. );
  89. (output, yaml) = await ExecuteAsync(
  90. "services", "set", "paperless",
  91. "--runs-on", "host01"
  92. );
  93. (output, yaml) = await ExecuteAsync("servers", "tree", "node01");
  94. Assert.Equal("""
  95. node01
  96. ├── System: host01
  97. │ ├── Service: immich
  98. │ └── Service: paperless
  99. ├── System: host02
  100. └── System: host03
  101. """, output);
  102. }
  103. }