prehistoric-kite-30979
11/12/2021, 9:49 PMError: Program run without the Pulumi engine available; re-run using the `pulumi` CLI
I think this is because the function I’m testing instantiates a provider?import * as pulumi from '@pulumi/pulumi'
import { assert } from 'chai'
pulumi.runtime.setMocks({
newResource(args: pulumi.runtime.MockResourceArgs): { id: string; state: any } {
console.log(args)
return {
id: `${args.inputs.name}_id`,
state: args.inputs,
}
},
call(args: pulumi.runtime.MockCallArgs) {
console.log(args)
return args.inputs
},
})
describe(__dirname, () => {
let module: typeof import('./azure')
before(async () => {
module = await import('./azure')
})
describe('minimal', () => {
it('must have all args passed through', (done) => {
const minimal = module.AzureMinimal(
'name',
{
subscriptionId: 'subscription',
tenantId: 'tenant',
},
{
protect: true,
},
{
aliases: ['urn'],
},
)
pulumi.all([minimal.provider, minimal.protect]).apply(([provider, protect]) => {
assert.exists(provider)
assert.isTrue(protect)
done()
})
})
})
})
export function AzureMinimal(
name: string,
args: AzureMinimalOptionsArgs,
opts: CustomResourceOptions,
providerOptions?: ProviderOptions,
): AzureMinimalOptions {
const provider = new azure.Provider(
name,
{
subscriptionId: args.subscriptionId,
tenantId: args.tenantId,
},
providerOptions,
)
return {
provider,
...opts,
}
}
steep-toddler-94095
11/12/2021, 10:38 PMprehistoric-kite-30979
11/12/2021, 10:39 PMsteep-toddler-94095
11/12/2021, 10:59 PMprehistoric-kite-30979
11/12/2021, 10:59 PM"test": "mocha -r ts-node/register '**/*.test.ts'",
little-cartoon-10569
11/14/2021, 7:54 PMpulumi.runInPulumiStack()
. You shouldn't often need to using Pulumi functions in testable units, so it's not much of an issue.getStack()
or getProject()
, or anything like that. All that stuff should happen in your program and be passed into your ComponentResources. That way, they're testable.prehistoric-kite-30979
11/16/2021, 10:40 PM