Skip to content

Commit

Permalink
Add warning log indent and will print warning log even no events conf…
Browse files Browse the repository at this point in the history
…igured in yaml (alibaba#197)

Add warning log indent and will print warning log even no events configured in yaml
  • Loading branch information
coco-super authored and tanhe123 committed Apr 22, 2019
1 parent 04ef772 commit 82f3df2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
26 changes: 13 additions & 13 deletions lib/deploy/deploy-by-tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ async function displayTriggerInfo(serviceName, functionName, triggerName, trigge
}

async function deployTriggers(serviceName, functionName, events) {
if (events) {

let localTriggerNames = Object.keys(events);
let onLineTriggerNames = await getTriggerNameList({serviceName, functionName});
events = events || {};

onLineTriggerNames.filter(x =>!_.includes(localTriggerNames,x)).forEach(element => {
let localTriggerNames = Object.keys(events);
let onLineTriggerNames = await getTriggerNameList({serviceName, functionName});

console.warn(red(`The trigger ${element} you configured in fc console does not match the local configuration. Fun will not modify this trigger. You can remove this trigger manually through fc console if necessary`));
onLineTriggerNames.filter(x =>!_.includes(localTriggerNames,x)).forEach(element => {

});

for (const [triggerName, triggerDefinition] of Object.entries(events)) {
console.log(`\t\tWaiting for ${yellow(triggerDefinition.Type)} trigger ${triggerName} to be deployed...`);
console.warn(red(`\t\tThe trigger ${element} you configured in fc console does not match the local configuration.\n\t\tFun will not modify this trigger. You can remove this trigger manually through fc console if necessary`));

await deployTrigger(serviceName, functionName, triggerName, triggerDefinition);
});

for (const [triggerName, triggerDefinition] of Object.entries(events)) {
console.log(`\t\tWaiting for ${yellow(triggerDefinition.Type)} trigger ${triggerName} to be deployed...`);

await displayTriggerInfo(serviceName, functionName, triggerName, triggerDefinition);
await deployTrigger(serviceName, functionName, triggerName, triggerDefinition);

console.log(green(`\t\tfunction ${triggerName} deploy success`));
}
await displayTriggerInfo(serviceName, functionName, triggerName, triggerDefinition);

console.log(green(`\t\tfunction ${triggerName} deploy success`));
}
}

Expand Down
12 changes: 10 additions & 2 deletions test/deploy/deploy-by-tpl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const path = require('path');
const deploySupport = require('../../lib/deploy/deploy-support');
const ram = require('../../lib/ram');
const { setProcess } = require('../test-utils');
const { red } = require('colors');

describe('deploy service role ',() => {
let restoreProcess;
Expand Down Expand Up @@ -88,9 +89,11 @@ describe('deploy', () => {
let restoreProcess;

beforeEach(() => {

sandbox.stub(console, 'warn');
Object.keys(deploySupport).forEach(m => {
if (m === 'getTriggerNameList') {
sandbox.stub(deploySupport, m).resolves([]);
sandbox.stub(deploySupport, m).resolves(['my_trigger_name']);
}else {
sandbox.stub(deploySupport, m).resolves({});
}
Expand Down Expand Up @@ -873,5 +876,10 @@ describe('deploy', () => {
timeout: undefined,
environmentVariables: { StringTypeValue1: 123, StringTypeValue2: 'test' }
});
// add test => no events on local but have onLine
assert.notCalled(deploySupport.makeTrigger);
assert.calledOnce(console.warn);
assert.calledWith(console.warn,red(`\t\tThe trigger my_trigger_name you configured in fc console does not match the local configuration.\n\t\tFun will not modify this trigger. You can remove this trigger manually through fc console if necessary`));
});
});
});

0 comments on commit 82f3df2

Please sign in to comment.