Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Pulumi.RunException assertable #203

Open
JasonWhall opened this issue Nov 7, 2023 · 1 comment
Open

Make Pulumi.RunException assertable #203

JasonWhall opened this issue Nov 7, 2023 · 1 comment
Labels
kind/enhancement Improvements or new features

Comments

@JasonWhall
Copy link
Contributor

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

Currently when writing Unit tests for a stack that does Pulumi.Log.Error(""). The resulting stack will throw a Pulumi.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 the Exception type, but isn't accurate to the type of exception thrown. Below shows an example of a test that would check for this:

using FluentAssertions;
using NSubstitute;
using Pulumi;
using Pulumi.Testing;

public class UnitTest1
{

    [Fact]
    public async Task Stack_LoggingError_ShouldThrowExpectedException()
    {
        // Arrange
        var mocks = Substitute.For<IMocks>();
        var options = new TestOptions { IsPreview = false };
        static void act()
        {
            Log.Error("Message 1");
        };

        var sut = () => Deployment.TestAsync(mocks, options, act);

        // Act & Assert
        await sut.Should().ThrowAsync<Exception>()
            .WithMessage("Message 1");

        // Desired
        /*
            await sut.Should().ThrowAsync<Pulumi.RunException>()
                .WithMessage("Message 1");
        */
    }
}

Could the RunException be made public so we can assert on this?

Affected area/feature

Pulumi Core

@JasonWhall JasonWhall added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Nov 7, 2023
@justinvp justinvp removed the needs-triage Needs attention from the triage team label Nov 10, 2023
@justinvp
Copy link
Member

Thanks for the suggestion, @JasonWhall. I don't recall if we had a good reason for making RunException internal, other than not intending it to be thrown by users. But I understand why it'd be nice to write a test like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

No branches or pull requests

2 participants