ServiceYamlE2ETests.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd;
  4. [Collection("Yaml CLI tests")]
  5. public class ServiceYamlE2ETests(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 systems_cli_workflow_test()
  24. {
  25. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  26. // Add system
  27. var (output, yaml) = await ExecuteAsync("services", "add", "immich");
  28. Assert.Equal("Service 'immich' added.\n", output);
  29. Assert.Equal("""
  30. resources:
  31. - kind: Service
  32. network:
  33. runsOn:
  34. name: immich
  35. tags:
  36. """, yaml);
  37. // Update system
  38. (output, yaml) = await ExecuteAsync(
  39. "services", "set", "immich",
  40. "--ip", "192.168.10.14",
  41. "--port", "80",
  42. "--protocol", "TCP",
  43. "--url", "http://timmoth.lan:80",
  44. "--runs-on", "vm01"
  45. );
  46. Assert.Equal("Service 'immich' updated.\n", output);
  47. Assert.Equal("""
  48. resources:
  49. - kind: Service
  50. network:
  51. ip: 192.168.10.14
  52. port: 80
  53. protocol: TCP
  54. url: http://timmoth.lan:80
  55. runsOn: vm01
  56. name: immich
  57. tags:
  58. """, yaml);
  59. // Get system by name
  60. (output, yaml) = await ExecuteAsync("services", "get", "immich");
  61. Assert.Equal(
  62. "immich Ip: 192.168.10.14, Port: 80, Protocol: TCP, Url: http://timmoth.lan:80, \nRunsOn: vm01\n",
  63. output);
  64. // List systems
  65. (output, yaml) = await ExecuteAsync("services", "list");
  66. Assert.Equal("""
  67. ╭────────┬───────────────┬──────┬──────────┬───────────────────────┬─────────╮
  68. │ Name │ Ip │ Port │ Protocol │ Url │ Runs On │
  69. ├────────┼───────────────┼──────┼──────────┼───────────────────────┼─────────┤
  70. │ immich │ 192.168.10.14 │ 80 │ TCP │ http://timmoth.lan:80 │ vm01 │
  71. ╰────────┴───────────────┴──────┴──────────┴───────────────────────┴─────────╯
  72. """, output);
  73. // Report systems
  74. (output, yaml) = await ExecuteAsync("services", "summary");
  75. Assert.Equal("""
  76. ╭────────┬───────────────┬──────┬──────────┬───────────────────────┬─────────╮
  77. │ Name │ Ip │ Port │ Protocol │ Url │ Runs On │
  78. ├────────┼───────────────┼──────┼──────────┼───────────────────────┼─────────┤
  79. │ immich │ 192.168.10.14 │ 80 │ TCP │ http://timmoth.lan:80 │ vm01 │
  80. ╰────────┴───────────────┴──────┴──────────┴───────────────────────┴─────────╯
  81. """, output);
  82. // Delete system
  83. (output, yaml) = await ExecuteAsync("services", "del", "immich");
  84. Assert.Equal("""
  85. Service 'immich' deleted.
  86. """, output);
  87. // Ensure list is empty
  88. (output, yaml) = await ExecuteAsync("services", "list");
  89. Assert.Equal("""
  90. No Services found.
  91. """, output);
  92. }
  93. }