ServiceCommandTests.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. {
  8. private async Task<(string output, string yaml)> ExecuteAsync(params string[] args)
  9. {
  10. var output = await YamlCliTestHost.RunAsync(
  11. args,
  12. fs.Root,
  13. outputHelper,
  14. "config.yaml");
  15. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  16. return (output, yaml);
  17. }
  18. [Fact]
  19. public async Task describe_outputs_expected_information()
  20. {
  21. await ExecuteAsync("services", "add", "svc01");
  22. // ToDo Introduce CIDR validation and enforce it in the test
  23. await ExecuteAsync("services", "set", "svc01", "--ip", "1.2.3.4");
  24. var (output, _) = await ExecuteAsync("services", "describe", "svc01");
  25. Assert.Contains("svc01", output);
  26. Assert.Contains("1.2.3.4", output);
  27. }
  28. [Fact]
  29. public async Task help_commands_do_not_throw()
  30. {
  31. Assert.Contains("Manage services", (await ExecuteAsync("services", "--help")).output);
  32. Assert.Contains("Add a new service", (await ExecuteAsync("services", "add", "--help")).output);
  33. Assert.Contains("List all services", (await ExecuteAsync("services", "list", "--help")).output);
  34. Assert.Contains("Retrieve a service", (await ExecuteAsync("services", "get", "--help")).output);
  35. Assert.Contains("Show detailed information", (await ExecuteAsync("services", "describe", "--help")).output);
  36. Assert.Contains("Update properties", (await ExecuteAsync("services", "set", "--help")).output);
  37. Assert.Contains("Delete a service", (await ExecuteAsync("services", "del", "--help")).output);
  38. Assert.Contains("List subnets", (await ExecuteAsync("services", "subnets", "--help")).output);
  39. }
  40. }