ServerYamlE2ETests.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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) : IClassFixture<TempYamlCliFixture>
  6. {
  7. private async Task<(string, string)> ExecuteAsync(params string[] args)
  8. {
  9. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  10. var inputArgs = args.ToArray();
  11. var output = await YamlCliTestHost.RunAsync(
  12. inputArgs,
  13. fs.Root,
  14. outputHelper,
  15. "config.yaml"
  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("servers", "tree", "node01");
  60. Assert.Equal("""
  61. node01
  62. ├── System: host01
  63. ├── System: host02
  64. └── System: host03
  65. """, output);
  66. }
  67. }