https://pulumi.com logo
#dotnet
Title
m

miniature-leather-70472

05/18/2021, 8:53 AM
Another migration question, updating to Pulumi 3.0 has broken our unit testing mock, the example here seems to have been updated to fix the breaking change, but it doesn't work https://www.pulumi.com/docs/guides/testing/unit/#add-mocks it complains about args not existing, are there any working examples to update the RunAsync method? It also looks like the full code example here https://github.com/pulumi/examples/tree/74db62a03d013c2854d2cf933c074ea0a3bbf69d/testing-unit-cs has not been updated
t

tall-librarian-49374

05/18/2021, 9:16 AM
Thank you for reporting this! The example should be something like
Copy code
public static class Testing
{
    public static Task<ImmutableArray<Resource>> RunAsync<T>() where T : Stack, new()
    {
        var mocks = new Mock<IMocks>();
        mocks.Setup(m => m.NewResourceAsync(It.IsAny<MockResourceArgs>()))
            .ReturnsAsync((MockResourceArgs args) => (args.Id, args.Inputs));
        mocks.Setup(m => m.CallAsync(It.IsAny<MockCallArgs>()))
            .ReturnsAsync((MockCallArgs args) => args.Args);
        return Deployment.TestAsync<T>(mocks.Object, new TestOptions { IsPreview = false });
    }
}
If this works for you, I will open a PR for docs
m

miniature-leather-70472

05/18/2021, 9:28 AM
So it sort of works, it does return the resource properties, but the resource name is null
Thats the actual Azure resource name property, not the Pulumi resource name
t

tall-librarian-49374

05/18/2021, 11:12 AM
I guess you’d need to set it manually in the callback. Was it working in 2.0?
m

miniature-leather-70472

05/18/2021, 1:30 PM
Yeah it was
t

tall-librarian-49374

05/18/2021, 1:38 PM
Which resources are you testing? Azure Native? Was it also Azure Native in 2.0?