Is there a known requirement that if you are mocki...
# typescript
b
Is there a known requirement that if you are mocking pulumi resources for unit testing that your pulumi CLI version needs to be the same as the SDK version? I get weird errors when they aren’t the same, but it makes it hard to maintain consistent versions across multiple projects.
l
When you're unit testing, the CLI isn't used, so it doesn't matter. You don't even need it to be installed.
Uh... I think. Now I'm having sudden pangs of uncertainty about this...
b
lol I agree in theory but the only fix I’ve found is installing the same CLI version as the @pulumi/pulumi version in package.json 😕
l
I don't know how to easily uninstall Pulumi, so I renamed the
~/.pulumi/bin/pulumi
file. My tests all pass 100%.
b
hm
l
I'll rename a few more things... maybe the language engine is used directly.
I've renamed ~/.pulumi/bin, and tests all still pass.
I've renamed ~/.pulumi/plugins, still passign. Looks like the CLI isn't used at all. Have you tracked down the code with the error? Maybe there's a particular call that invokes the CLI inside one of your resources? If there is, you can move that out of the tested code, and into your index.ts or similar.
For example, I've learned never to call a function in the
pulumi
namespace from tested code. E.g.
pulumi.getProject()
,
pulumi.isDryRun()
, anything like that. Those are not handled by the Pulumi test engine.
So I always call those from index.ts and pass the values around.
b
ah, that’s definitely in my code. We grab pulumi stack config in the tested function
l
We grab config in index.ts and pass the relevant bits into component constructors. Inversion of control, and all that.
It also means we don't need to stub out config: tests can pass in values, the same as config does.