|
| 1 | +using ModularityKit.Mutator.Examples.SmokeTests.Support; |
| 2 | + |
| 3 | +namespace ModularityKit.Mutator.Examples.SmokeTests.Examples.Governance; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Smoke coverage for the executable samples shipped under <c>Examples/Governance</c>. |
| 7 | +/// </summary> |
| 8 | +public sealed class GovernanceExamplesSmokeTests |
| 9 | +{ |
| 10 | + [Fact] |
| 11 | + public Task ApprovalWorkflow_runs_successfully() |
| 12 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("ApprovalWorkflow", "Examples/Governance/ApprovalWorkflow/ApprovalWorkflow.csproj")); |
| 13 | + |
| 14 | + [Fact] |
| 15 | + public Task GovernedExecution_runs_successfully() |
| 16 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("GovernedExecution", "Examples/Governance/GovernedExecution/GovernedExecution.csproj")); |
| 17 | + |
| 18 | + [Fact] |
| 19 | + public Task DecisionTaxonomy_runs_successfully() |
| 20 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("DecisionTaxonomy", "Examples/Governance/DecisionTaxonomy/DecisionTaxonomy.csproj")); |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public Task Queries_runs_successfully() |
| 24 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("Queries", "Examples/Governance/Queries/Queries.csproj")); |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public Task RedisQueries_runs_successfully() |
| 28 | + => ExampleSmokeRunner.RunAndAssertAsync(CreateRedis()); |
| 29 | + |
| 30 | + [Fact] |
| 31 | + public Task RequestLifecycle_runs_successfully() |
| 32 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("RequestLifecycle", "Examples/Governance/RequestLifecycle/RequestLifecycle.csproj")); |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public Task VersionedResolution_runs_successfully() |
| 36 | + => ExampleSmokeRunner.RunAndAssertAsync(Create("VersionedResolution", "Examples/Governance/VersionedResolution/VersionedResolution.csproj")); |
| 37 | + |
| 38 | + private static ExampleSmokeCase Create(string name, string projectPath) |
| 39 | + => new( |
| 40 | + name, |
| 41 | + projectPath, |
| 42 | + result => |
| 43 | + { |
| 44 | + if (result.TimedOut) |
| 45 | + return "process timed out"; |
| 46 | + |
| 47 | + if (result.ExitCode != 0) |
| 48 | + return $"expected exit code 0 but got {result.ExitCode}"; |
| 49 | + |
| 50 | + if (string.IsNullOrWhiteSpace(result.StandardOutput) && string.IsNullOrWhiteSpace(result.StandardError)) |
| 51 | + return "example did not produce any output"; |
| 52 | + |
| 53 | + if (result.StandardError.Contains("Unhandled exception", StringComparison.OrdinalIgnoreCase)) |
| 54 | + return "stderr contains unhandled exception output"; |
| 55 | + |
| 56 | + return null; |
| 57 | + }); |
| 58 | + |
| 59 | + private static ExampleSmokeCase CreateRedis() |
| 60 | + => new( |
| 61 | + "RedisQueries", |
| 62 | + "Examples/Governance/RedisQueries/RedisQueries.csproj", |
| 63 | + result => |
| 64 | + { |
| 65 | + if (result.TimedOut) |
| 66 | + return "process timed out"; |
| 67 | + |
| 68 | + if (result.ExitCode != 0) |
| 69 | + return $"expected exit code 0 but got {result.ExitCode}"; |
| 70 | + |
| 71 | + var hasRedisOutput = result.StandardOutput.Contains("Pending Approval Queue", StringComparison.Ordinal) |
| 72 | + && result.StandardOutput.Contains("Recent Execution Outcomes", StringComparison.Ordinal); |
| 73 | + |
| 74 | + var hasExpectedDependencyWarning = |
| 75 | + result.StandardError.Contains("Could not connect to Redis", StringComparison.Ordinal) |
| 76 | + && result.StandardError.Contains("Start Redis locally or set MODULARITYKIT_REDIS to a reachable endpoint.", StringComparison.Ordinal); |
| 77 | + |
| 78 | + if (!hasRedisOutput && !hasExpectedDependencyWarning) |
| 79 | + return "expected either Redis query output or the documented Redis prerequisite warning"; |
| 80 | + |
| 81 | + if (result.StandardError.Contains("Unhandled exception", StringComparison.OrdinalIgnoreCase)) |
| 82 | + return "stderr contains unhandled exception output"; |
| 83 | + |
| 84 | + return null; |
| 85 | + }, |
| 86 | + new Dictionary<string, string?> |
| 87 | + { |
| 88 | + ["MODULARITYKIT_REDIS"] = "localhost:6379,connectTimeout=1000,abortConnect=false,syncTimeout=1000" |
| 89 | + }); |
| 90 | +} |
0 commit comments