ServiceCommandTests.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.ServiceTests;
  4. [Collection("Yaml CLI tests")]
  5. public class ServiceCommandTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture> {
  7. private async Task<(string output, string yaml)> ExecuteAsync(params string[] args) {
  8. var output = await YamlCliTestHost.RunAsync(
  9. args,
  10. fs.Root,
  11. outputHelper,
  12. "config.yaml");
  13. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  14. return (output, yaml);
  15. }
  16. [Fact]
  17. public async Task describe_outputs_expected_information() {
  18. await ExecuteAsync("services", "add", "svc01");
  19. // ToDo Introduce CIDR validation and enforce it in the test
  20. await ExecuteAsync("services", "set", "svc01", "--ip", "1.2.3.4");
  21. (var output, var _) = await ExecuteAsync("services", "describe", "svc01");
  22. Assert.Contains("svc01", output);
  23. Assert.Contains("1.2.3.4", output);
  24. }
  25. [Fact]
  26. public async Task help_commands_do_not_throw() {
  27. Assert.Contains("Manage services", (await ExecuteAsync("services", "--help")).output);
  28. Assert.Contains("Add a new service", (await ExecuteAsync("services", "add", "--help")).output);
  29. Assert.Contains("List all services", (await ExecuteAsync("services", "list", "--help")).output);
  30. Assert.Contains("Retrieve a service", (await ExecuteAsync("services", "get", "--help")).output);
  31. Assert.Contains("Show detailed information", (await ExecuteAsync("services", "describe", "--help")).output);
  32. Assert.Contains("Update properties", (await ExecuteAsync("services", "set", "--help")).output);
  33. Assert.Contains("Delete a service", (await ExecuteAsync("services", "del", "--help")).output);
  34. Assert.Contains("List subnets", (await ExecuteAsync("services", "subnets", "--help")).output);
  35. }
  36. }