https://pulumi.com logo
Title
r

rough-window-15889

04/25/2022, 9:21 PM
Does anyone know the best way to mock the resource to unit test?
l

little-cartoon-10569

04/25/2022, 10:17 PM
To fake a resource, Pulumi provides the
pulumi.runtime.setMocks()
function, which allows you to create dumb or smart stubs for all resource constructors and provider getters. Is that what you're looking for?
👍 1
There is no true mocking support, you would have to add that yourself, maybe via a mocking library.
r

rough-window-15889

04/26/2022, 2:48 AM
I have pretty lengthy stack.yaml and using static variables on a class to get access to the configs, but I think you're right I just need to actually just do the mock myself. Thanks!
l

little-cartoon-10569

04/26/2022, 2:54 AM
Generally, configs are best loaded by index.ts, which isn't faked / stubbed. All configuration values, wherever they come from, should be passed into the constructor of a resource.
This helps with lowering coupling and increasing both testability and readability.
❤️ 2
Don't test your use of configuration, just class/component logic.
r

rough-window-15889

04/26/2022, 2:55 AM
Very helpful thank you