-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Pulumi.RunException
assertable
#203
Labels
kind/enhancement
Improvements or new features
Comments
JasonWhall
added
kind/enhancement
Improvements or new features
needs-triage
Needs attention from the triage team
labels
Nov 7, 2023
Thanks for the suggestion, @JasonWhall. I don't recall if we had a good reason for making |
mmisztal1980
added a commit
to mmisztal1980/pulumi-dotnet
that referenced
this issue
Oct 16, 2024
github-merge-queue bot
pushed a commit
that referenced
this issue
Oct 18, 2024
…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]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
Issue details
Currently when writing Unit tests for a stack that does
Pulumi.Log.Error("")
. The resulting stack will throw aPulumi.RunException
in the deployment runner. As this is an internal only type currently, we are unable to assert to check this error has been thrown. The workaround currently is to assert on theException
type, but isn't accurate to the type of exception thrown. Below shows an example of a test that would check for this:Could the
RunException
be made public so we can assert on this?Affected area/feature
Pulumi Core
The text was updated successfully, but these errors were encountered: