narrow-guitar-10891
05/25/2023, 5:50 PMimport { NodeApplication } from "../src/nodeApplication";
import * as pulumi from "@pulumi/pulumi";
describe("Node Application", () => {
test("Read from config", () => {
const config = JSON.stringify({
config: {
'test:image': 'test',
'test:team': 'test',
'test:app': {
redis: {
url: '<redis://some-host:6379>',
},
},
},
});
process.env.PULUMI_NODEJS_STACK = "unit";
process.env.PULUMI_NODEJS_PROJECT = "test"
process.env.PULUMI_CONFIG = config;
console.log(process.env.PULUMI_CONFIG);
console.log(pulumi.getProject()); // returns 'project' instead of 'test'
console.log(pulumi.getStack()); // returns 'stack' instead of 'unit'
const appConfig = new pulumi.Config();
console.log(appConfig);
console.log(process.env.PULUMI_CONFIG);
let app = new NodeApplication(); // fails to find required configuration values
});
});
Inside NodeApplication
class there is a config parsing:
. . .
let config = new pulumi.Config();
this.name = pulumi.getProject();
this.image = config.require('image');
this.team = config.require('team');
. . .
I am running tests with jest. And here is an output (simplified):
$ npm run test
> test
> jest
console.log
{"config":{"test:image":"test","test:team":"test","test:app":{"redis":{"url":"<redis://some-host:6379>"}}}}
console.log
project
console.log
stack
console.log
Config { name: 'project' }
FAIL test/redis.test.ts (19.335 s)
Node Application
✕ Read from config (59 ms)
● Node Application › Read from config
Missing required configuration variable 'project:image'
please set a value using the command `pulumi config set project:image <value>`
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 19.505 s
Ran all test suites.
little-cartoon-10569
05/25/2023, 10:24 PMnarrow-guitar-10891
05/26/2023, 7:24 AM