Hi everyone, I’m currently working on testing my P...
# general
c
Hi everyone, I’m currently working on testing my Pulumi code and aiming for good coverage with unit testings. I’ve been following this tutorial, but I’ve run into several issues (mainly race conditions) when trying to run unit tests with a broader scope and multiple mocks of Pulumi calls. The tutorial doesn’t seem to provide many examples of this kind of Pulumi unit testing. Do you know where I could find some good examples of Pulumi unit tests (we use Pulumi with AWS as our main provider) or any best-practice guidelines? Thank you!
m
There are some examples of unit testing in various languages in the pulumi examples repo. Perhaps you could share a little bit more about your use of multiple mocks and what kinds of race conditions you are seeing?
l
One tip I have is to avoid calling any (well, most) Pulumi utility functions from tests. Many of them don't work well with the fake runtime. I can't remember which ones gave us problems, but as a rule, stay away from anything that isn't in a provider.
pulumi.output()
is definitely ok, but
pulumi.registerStackTransformation()
is probably best avoided in tested code. This hasn't ever been a problem for us: we only ever test component resources, and none of those functions are used in component resources.
c
Thank you we will have a look ! Did you experience some race conditions with the fake runtime and
pulumu.output
? @mammoth-restaurant-4670 We got inspirations from this repo and we could some small tests that look like those ones. However, when we start to have multiples conditions in our runtime mock function, we start to observe that we don't always have the same output when we execute the function and we were wondering if there is something we can do to avoid this behavior
l
I don't remember what the problem was, it was years ago that we found and resolved all the issues, and came up with our testing policies. Fairly sure there were never any race conditions that we encountered.
You may need to show an example of the sorts of things you're putting in
setMocks()
that cause the problem. We don't generally have much in there; just setting up availability zones so that the AWS provider works.