abundant-king-20145
06/16/2021, 10:22 PMError: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
When you use a debugger the call ends when a resource is being created. Doing that things after the resource creation are unreachable:
Here is my test .
import * as pulumi from '@pulumi/pulumi';
import { MockCallArgs } from '@pulumi/pulumi/runtime';
import { describe, it, before } from 'mocha';
pulumi.runtime.setMocks({
newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} {
return {
id: args.inputs.name + "_id",
state: args.inputs,
};
},
call: function(args: MockCallArgs) {
return args.inputs;
},
});
describe('Example Service', () => {
let definitions: typeof import('./service-example');
before(async () => {
definitions = await import('./service-example');
})
it('should forward port 80 to 80', (done) => {
pulumi.all([definitions.ServiceExample]).apply(([ServiceExample]) => {
const se = new ServiceExample()
const service = se.aService;
done()
})
});
})
And my base class that I want to test.
import * as k8s from '@pulumi/kubernetes';
import {ComponentResource} from "@pulumi/pulumi";
export class ServiceExample extends ComponentResource{
private name: string = 'S1'
aService: k8s.core.v1.Service;
constructor() {
super('k8s:Service', 'S1');
this.aService = this.createService()
}
createService: () => k8s.core.v1.Service = () => {
return new k8s.core.v1.Service(
this.name = '-service',
{
metadata: {
name: this.name,
namespace: 'one'
},
spec: {
selector: {
foo: 'bar'
},
ports: [
{
name: 'http',
port: 80,
targetPort: 80}
]
}
}
)
}
}
And here is the repo if you want to clone it and test it on your own:
https://gitlab.com/diego.huerta/pulumi-example