OtherWorkflowTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Tests.EndToEnd.Infra;
  2. using Xunit.Abstractions;
  3. namespace Tests.EndToEnd.OtherTests;
  4. [Collection("Yaml CLI tests")]
  5. public class OtherWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper outputHelper)
  6. : IClassFixture<TempYamlCliFixture> {
  7. private async Task<(string, string)> ExecuteAsync(params string[] args) {
  8. outputHelper.WriteLine($"rpk {string.Join(" ", args)}");
  9. var output = await YamlCliTestHost.RunAsync(
  10. args,
  11. fs.Root,
  12. outputHelper,
  13. "config.yaml");
  14. outputHelper.WriteLine(output);
  15. var yaml = await File.ReadAllTextAsync(Path.Combine(fs.Root, "config.yaml"));
  16. return (output, yaml);
  17. }
  18. [Fact]
  19. public async Task other_cli_workflow_test() {
  20. // Add other hardware
  21. (var output, var yaml) = await ExecuteAsync("other", "add", "radio01");
  22. Assert.Equal("Other hardware 'radio01' added.\n", output);
  23. Assert.Contains("name: radio01", yaml);
  24. // Update other hardware
  25. (output, yaml) = await ExecuteAsync(
  26. "other", "set", "radio01",
  27. "--model", "Building-Bridge-XG",
  28. "--description", "Microwave radio bridge"
  29. );
  30. Assert.Equal("Other hardware 'radio01' updated.\n", output);
  31. Assert.Equal("""
  32. version: 3
  33. resources:
  34. - kind: Other
  35. model: Building-Bridge-XG
  36. description: Microwave radio bridge
  37. name: radio01
  38. connections: []
  39. """, yaml);
  40. // Add second other hardware
  41. (output, yaml) = await ExecuteAsync("other", "add", "bridge01");
  42. Assert.Equal("Other hardware 'bridge01' added.\n", output);
  43. (output, yaml) = await ExecuteAsync(
  44. "other", "set", "bridge01",
  45. "--model", "Interop-Bridge-2",
  46. "--description", "Radio interoperability bridge"
  47. );
  48. Assert.Equal("Other hardware 'bridge01' updated.\n", output);
  49. Assert.Equal("""
  50. version: 3
  51. resources:
  52. - kind: Other
  53. model: Building-Bridge-XG
  54. description: Microwave radio bridge
  55. name: radio01
  56. - kind: Other
  57. model: Interop-Bridge-2
  58. description: Radio interoperability bridge
  59. name: bridge01
  60. connections: []
  61. """, yaml);
  62. // Get other hardware
  63. (output, yaml) = await ExecuteAsync("other", "get", "radio01");
  64. Assert.Contains("radio01", output);
  65. Assert.Contains("Building-Bridge-XG", output);
  66. Assert.Contains("Microwave radio bridge", output);
  67. // List other hardware
  68. (output, yaml) = await ExecuteAsync("other", "list");
  69. Assert.Contains("radio01", output);
  70. Assert.Contains("bridge01", output);
  71. // Summary
  72. (output, yaml) = await ExecuteAsync("other", "summary");
  73. Assert.Contains("radio01", output);
  74. Assert.Contains("bridge01", output);
  75. // Delete other hardware
  76. (output, yaml) = await ExecuteAsync("other", "del", "bridge01");
  77. Assert.Equal("""
  78. Other hardware 'bridge01' deleted.
  79. """, output);
  80. // List again
  81. (output, yaml) = await ExecuteAsync("other", "list");
  82. Assert.Contains("radio01", output);
  83. Assert.DoesNotContain("bridge01", output);
  84. }
  85. }