https://pulumi.com logo
Title
w

wooden-lifeguard-41446

09/23/2021, 8:13 AM
Hi guys, do we have a way to mock StackReference and/or pulumi.config for unit test? I'm stuck with it , can't find any example.
b

boundless-car-60268

09/28/2021, 10:27 AM
Not very elegant, but you could decorate it and use your decorator in place of StackReference in your Pulumi code, then have the decorator check a "Mocking" static property at run time to see whether to use "real" StackReference or some other static properties. Your unit test code could set the static properties and set "Mocking" to true on your decorator. Similarly for pulumi.config.
We already tend to wrap pulumi config usage into a class so we can apply parsing and create strong types (rather than strings) for the value. Plus it's a handy place to put default values if appropriate.
👍 1