Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 016e9ea

Browse files
committed
Fixes #134 - Invoke Local Should Use Package Params
1 parent 3a548e1 commit 016e9ea

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

invokeLocal/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class OpenWhiskInvokeLocal {
1616
this.hooks = {
1717
'invoke:local:invoke': () => BbPromise.bind(this)
1818
.then(this.validate)
19+
.then(this.mergePackageParams)
1920
.then(this.loadEnvVars)
2021
.then(this.invokeLocal),
2122
};
@@ -63,6 +64,21 @@ class OpenWhiskInvokeLocal {
6364
});
6465
}
6566

67+
mergePackageParams() {
68+
const functionObj = this.serverless.service.getFunction(this.options.function) || {}
69+
const name = functionObj.name || ''
70+
const id = name.match(/^(.+)\/.+$/)
71+
if (id) {
72+
const pgke = id[1]
73+
const manifestPackages = this.serverless.service.resources.packages || {};
74+
const packageDetails = manifestPackages[pgke] || {}
75+
const packageParams = packageDetails.parameters || {}
76+
this.options.data = Object.assign(packageParams, this.options.data);
77+
}
78+
79+
return BbPromise.resolve();
80+
}
81+
6682
loadEnvVars() {
6783
return this.provider.props().then(props => {
6884
const envVars = {

invokeLocal/tests/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,41 @@ describe('OpenWhiskInvokeLocal', () => {
250250
);
251251
});
252252

253+
describe('#mergePackageParams()', () => {
254+
beforeEach(() => {
255+
serverless.config.servicePath = true;
256+
serverless.service.provider = {
257+
namespace: 'testing_ns',
258+
environment: {
259+
providerVar: 'providerValue',
260+
},
261+
};
262+
263+
serverless.service.functions.first.name = 'mypackage/first'
264+
serverless.service.functions.first.parameters = {
265+
foo: 'bar', nums: 1, arr: ['foo', 'bar']
266+
}
267+
openwhiskInvokeLocal.options = { data: { foo: 'bar', nums: 1, arr: ['foo', 'bar'] }};
268+
});
269+
270+
271+
it('it should ignore implicit packages without parameters', () => openwhiskInvokeLocal
272+
.mergePackageParams().then(() => {
273+
expect(openwhiskInvokeLocal.options.data).to.deep.equal(serverless.service.functions.first.parameters);
274+
})
275+
);
276+
277+
it('it should merge implicit packages with parameters', () => {
278+
serverless.service.resources.packages = {
279+
mypackage: { parameters: { hello: 'world', foo: 'baz' } }
280+
}
281+
return openwhiskInvokeLocal.mergePackageParams().then(() => {
282+
const merged = Object.assign(serverless.service.resources.packages.mypackage.parameters, openwhiskInvokeLocal.options.data)
283+
expect(openwhiskInvokeLocal.options.data).to.deep.equal(merged);
284+
})
285+
});
286+
});
287+
253288
describe('#invokeLocal()', () => {
254289
let invokeLocalNodeJsStub, invokeLocalPythonStub;
255290

0 commit comments

Comments
 (0)