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

Commit afed1bc

Browse files
authored
Merge pull request #112 from KeonHee/trigger-with-feed-annotation
Add a feed annotation to a trigger when creating a trigger
2 parents 6f33da6 + 9747390 commit afed1bc

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

deploy/lib/deployTriggers.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ module.exports = {
88
if (this.options.verbose) {
99
this.serverless.cli.log(`Deploying Trigger: ${trigger.triggerName}`);
1010
}
11+
12+
const feed = this.getFeed(trigger)
13+
if (feed) {
14+
Object.assign(trigger, { annotations: [{ key: 'feed', value: feed }] });
15+
}
16+
1117
return ow.triggers.create(trigger)
1218
.then(() => {
1319
if (this.options.verbose) {
@@ -38,5 +44,9 @@ module.exports = {
3844
const trigger = { feed: undefined };
3945
return Object.keys(triggers)
4046
.map(t => Object.assign({}, triggers[t], trigger));
41-
}
47+
},
48+
49+
getFeed(trigger) {
50+
return trigger.feed;
51+
},
4252
};

deploy/tests/deployTriggers.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ describe('deployTriggers', () => {
1616
triggers: {
1717
myTrigger: {
1818
triggerName: 'myTrigger',
19-
namepspace: 'myNamespace',
19+
namespace: 'myNamespace',
2020
action: 'myAction',
2121
trigger: 'myTrigger',
2222
},
23+
feedTrigger: {
24+
triggerName: 'myTrigger',
25+
namespace: 'myNamespace',
26+
action: 'myAction',
27+
trigger: 'myTrigger',
28+
feed: '/whisk.system/alarms/alarm',
29+
},
2330
},
2431
};
2532

2633
beforeEach(() => {
2734
sandbox = sinon.sandbox.create();
28-
const CLI = function () { this.log = function () {};};
29-
serverless = {classes: {Error, CLI}, service: {provider: {}, resources: {}, getAllFunctions: () => []}, getProvider: sandbox.spy()};
35+
const CLI = function () { this.log = function () {}; };
36+
serverless = { classes: { Error, CLI }, service: { provider: {}, resources: {}, getAllFunctions: () => [] }, getProvider: sandbox.spy() };
3037
const options = {
3138
stage: 'dev',
3239
region: 'us-east-1',
@@ -38,7 +45,7 @@ describe('deployTriggers', () => {
3845
apihost: 'openwhisk.org',
3946
auth: 'user:pass',
4047
};
41-
openwhiskDeploy.provider = { client: () => {} }
48+
openwhiskDeploy.provider = { client: () => {} };
4249
});
4350

4451
afterEach(() => {
@@ -73,23 +80,33 @@ describe('deployTriggers', () => {
7380
});
7481

7582
it('should log function deploy information with verbose flag', () => {
76-
openwhiskDeploy.options.verbose = true
77-
const log = sandbox.stub(openwhiskDeploy.serverless.cli, 'log')
78-
const clog = sandbox.stub(openwhiskDeploy.serverless.cli, 'consoleLog')
83+
openwhiskDeploy.options.verbose = true;
84+
const log = sandbox.stub(openwhiskDeploy.serverless.cli, 'log');
85+
const clog = sandbox.stub(openwhiskDeploy.serverless.cli, 'consoleLog');
7986
sandbox.stub(openwhiskDeploy.provider, 'client', () => {
80-
const create = params => {
81-
return Promise.resolve();
82-
};
87+
const create = params => Promise.resolve();
8388

8489
return Promise.resolve({ triggers: { create } });
8590
});
8691

8792
return openwhiskDeploy.deployTrigger(mockTriggerObject.triggers.myTrigger).then(() => {
88-
expect(log.calledTwice).to.be.equal(true);
89-
expect(log.args[0][0]).to.be.equal('Deploying Trigger: myTrigger')
90-
expect(log.args[1][0]).to.be.equal('Deployed Trigger: myTrigger')
91-
})
92-
})
93+
expect(log.calledTwice).to.be.equal(true);
94+
expect(log.args[0][0]).to.be.equal('Deploying Trigger: myTrigger');
95+
expect(log.args[1][0]).to.be.equal('Deployed Trigger: myTrigger');
96+
});
97+
});
9398

99+
it('should deploy trigger with feed annotation to openwhisk', () => {
100+
sandbox.stub(openwhiskDeploy.provider, 'client', () => {
101+
const create = params => {
102+
expect(params).to.be.deep.equal(mockTriggerObject.triggers.feedTrigger);
103+
return Promise.resolve();
104+
};
105+
106+
return Promise.resolve({ triggers: { create } });
107+
});
108+
return expect(openwhiskDeploy.deployTrigger(mockTriggerObject.triggers.feedTrigger))
109+
.to.eventually.be.fulfilled;
110+
});
94111
});
95112
});

0 commit comments

Comments
 (0)