https://pulumi.com logo
Title
h

handsome-twilight-36302

04/26/2023, 1:43 PM
Hi. Are there any examples of unit tests with stack references I can refer to? I'm having issues trying to mock my project, which includes a stack reference
l

little-cartoon-10569

04/26/2023, 11:19 PM
If you're getting stack references, then it's not a unit test. You need to test at a different level.
Generally, you get stack references in your
index.ts
,
__main__.py
, or similar. These files are not units, and they're not unit-testable.
ComponentResources are ideal units for unit testing. ComponentResources should not get stack resources: the top program should do that, and pass the values into the ComponentResource constructors.
h

handsome-twilight-36302

04/27/2023, 10:03 AM
I was thinking of mocking the stack reference in this case. What you're saying makes sense, though
l

little-cartoon-10569

04/27/2023, 8:25 PM
Pulumi has written the tests for stack references. You don't need to. Leave those out of the tests.