Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…364) As per discussion in #203 . This is a simple improvement in order to make the exception assertable by testing frameworks such as `FluentAssertions` using: ```csharp var action = () => { // (...) // provision failing pulumi resources here }; action.Should().Throw<Pulumi.RunException>(); ``` This will significantly improve testing scenarios where exceptions are being thrown, as everything gets wrapped in an internal `Pulumi.RunException` while testing: ```csharp // Disassembled code internal static async Task<(ImmutableArray<Resource> Resources, Exception? Exception)> TryTestAsync( IMocks mocks, Func<IRunner, Task<int>> runAsync, TestOptions? options = null) { var engine = new MockEngine(); var monitor = new MockMonitor(mocks); await CreateRunnerAndRunAsync(() => new Deployment(engine, monitor, options), runAsync).ConfigureAwait(false); Exception? err = engine.Errors.Count switch { 1 => new RunException(engine.Errors.Single()), // <-- wrapping takes place here var v when v > 1 => new AggregateException(engine.Errors.Select(e => new RunException(e))), _ => null }; return (Resources: monitor.Resources.ToImmutableArray(), Exception: err); } ``` --------- Co-authored-by: Thomas Gummerer <[email protected]>
- Loading branch information