Skip to content

Commit

Permalink
test(Variables): Cover custom variable sources
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 12, 2022
1 parent 9d57933 commit 38b93dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/fixtures/programmatic/plugin/custom-variable-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = class CustomVariableSourcePlugin {
constructor(serverless, options, utils) {
this.serverless = serverless;
this.options = options;
this.utils = utils;
this.configurationVariablesSources = {
other: {
async resolve({ address }) {
// `address` contains the name of the variable to resolve:
// In `${foo:some-variable}`, address will contain `some-variable`.

// Resolver is expected to return an object with the value in the `value` property:
return {
//
value: `Resolving variable ${address}`,
};
},
},
};
}
};
14 changes: 14 additions & 0 deletions test/unit/scripts/serverless.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ describe('test/unit/scripts/serverless.test.js', () => {
}
});

it('should support custom variable soruces', async () => {
const { servicePath: serviceDir } = await programmaticFixturesEngine.setup('plugin', {
configExt: {
custom: {
otherVar: '${other:addressValue}',
},
plugins: ['./custom-variable-source'],
},
});
expect(
String((await spawn('node', [serverlessPath, 'print'], { cwd: serviceDir })).stdoutBuffer)
).to.include('otherVar: Resolving variable addressValue');
});

it('should reject unresolved "plugins" property', async () => {
try {
await spawn('node', [serverlessPath, 'print'], {
Expand Down

0 comments on commit 38b93dc

Please sign in to comment.