ServiceYamlE2ETests.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. outputHelper.WriteLine(output);
  17. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  18. return (output, yaml);
  19. }
  20. [Fact]
  21. public async Task services_cli_yaml_test()
  22. {
  23. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  24. // Add system
  25. var (output, yaml) = await ExecuteAsync("services", "add", "immich");
  26. Assert.Equal("Service 'immich' added.\n", output);
  27. Assert.Equal("""
  28. resources:
  29. - kind: Service
  30. network:
  31. runsOn:
  32. name: immich
  33. tags:
  34. """, yaml);
  35. // Update system
  36. (output, yaml) = await ExecuteAsync(
  37. "services", "set", "immich",
  38. "--ip", "192.168.10.14",
  39. "--port", "80",
  40. "--protocol", "TCP",
  41. "--url", "http://timmoth.lan:80",
  42. "--runs-on", "vm01"
  43. );
  44. Assert.Equal("Service 'immich' updated.\n", output);
  45. Assert.Equal("""
  46. resources:
  47. - kind: Service
  48. network:
  49. ip: 192.168.10.14
  50. port: 80
  51. protocol: TCP
  52. url: http://timmoth.lan:80
  53. runsOn: vm01
  54. name: immich
  55. tags:
  56. """, yaml);
  57. // Delete system
  58. (output, yaml) = await ExecuteAsync("services", "del", "immich");
  59. Assert.Equal("""
  60. Service 'immich' deleted.
  61. """, output);
  62. Assert.Equal("""
  63. resources: []
  64. """, yaml);
  65. // Ensure list is empty
  66. (output, yaml) = await ExecuteAsync("services", "list");
  67. Assert.Equal("""
  68. No Services found.
  69. """, output);
  70. }
  71. [Fact]
  72. public async Task services_cli_workflow_test()
  73. {
  74. await File.WriteAllTextAsync(Path.Combine(fs.Root, "config.yaml"), "");
  75. // Add system
  76. var (output, yaml) = await ExecuteAsync("services", "add", "immich");
  77. Assert.Equal("Service 'immich' added.\n", output);
  78. (output, yaml) = await ExecuteAsync("systems", "add", "vm01");
  79. Assert.Equal("System 'vm01' added.\n", output);
  80. (output, yaml) = await ExecuteAsync(
  81. "systems", "set", "vm01",
  82. "--runs-on", "c6400"
  83. );
  84. (output, yaml) = await ExecuteAsync("servers", "add", "c6400");
  85. Assert.Equal("Server 'c6400' added.\n", output);
  86. // Update system
  87. (output, yaml) = await ExecuteAsync(
  88. "services", "set", "immich",
  89. "--ip", "192.168.10.14",
  90. "--port", "80",
  91. "--protocol", "TCP",
  92. "--url", "http://timmoth.lan:80",
  93. "--runs-on", "vm01"
  94. );
  95. Assert.Equal("Service 'immich' updated.\n", output);
  96. // Get system by name
  97. (output, yaml) = await ExecuteAsync("services", "get", "immich");
  98. Assert.Equal(
  99. """
  100. immich Ip: 192.168.10.14, Port: 80, Protocol: TCP, Url: http://timmoth.lan:80,
  101. RunsOn: c6400/vm01
  102. """
  103. ,
  104. output);
  105. // List systems
  106. (output, yaml) = await ExecuteAsync("services", "list");
  107. Assert.Equal("""
  108. ╭────────┬───────────────┬──────┬──────────┬──────────────────────┬────────────╮
  109. │ Name │ Ip │ Port │ Protocol │ Url │ Runs On │
  110. ├────────┼───────────────┼──────┼──────────┼──────────────────────┼────────────┤
  111. │ immich │ 192.168.10.14 │ 80 │ TCP │ http://timmoth.lan:8 │ c6400/vm01 │
  112. │ │ │ │ │ 0 │ │
  113. ╰────────┴───────────────┴──────┴──────────┴──────────────────────┴────────────╯
  114. """, output);
  115. // Report systems
  116. (output, yaml) = await ExecuteAsync("services", "summary");
  117. Assert.Equal("""
  118. ╭────────┬───────────────┬──────┬──────────┬──────────────────────┬────────────╮
  119. │ Name │ Ip │ Port │ Protocol │ Url │ Runs On │
  120. ├────────┼───────────────┼──────┼──────────┼──────────────────────┼────────────┤
  121. │ immich │ 192.168.10.14 │ 80 │ TCP │ http://timmoth.lan:8 │ c6400/vm01 │
  122. │ │ │ │ │ 0 │ │
  123. ╰────────┴───────────────┴──────┴──────────┴──────────────────────┴────────────╯
  124. """, output);
  125. // Delete system
  126. (output, yaml) = await ExecuteAsync("services", "del", "immich");
  127. Assert.Equal("""
  128. Service 'immich' deleted.
  129. """, output);
  130. // Ensure list is empty
  131. (output, yaml) = await ExecuteAsync("services", "list");
  132. Assert.Equal("""
  133. No Services found.
  134. """, output);
  135. }
  136. }