ServerYamlE2ETests.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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("servers", "tree", "node01");
  61. Assert.Equal("""
  62. node01
  63. ├── System: host01
  64. ├── System: host02
  65. └── System: host03
  66. """, output);
  67. }
  68. }