Repository: aliyun/fun
Pull request #197 (2019-04-22 04:08:33)

sunfeiyu : fix oss trigger
#160 修复了两个问题：
第一个是如果 yml 没有配置 events，那么即使线上有也不会提示 warning。
第二个是 warning 没有添加缩进。.


Patch:
diff --git a/lib/deploy/deploy-by-tpl.js b/lib/deploy/deploy-by-tpl.js
index 3e0235f..c2ec899 100644
--- a/lib/deploy/deploy-by-tpl.js
+++ b/lib/deploy/deploy-by-tpl.js
@@ -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`));
   }
 }
 


Test patch:
diff --git a/test/deploy/deploy-by-tpl.test.js b/test/deploy/deploy-by-tpl.test.js
index c6e300c..8796e78 100644
--- a/test/deploy/deploy-by-tpl.test.js
+++ b/test/deploy/deploy-by-tpl.test.js
@@ -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;
@@ -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({});
       }
@@ -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`));
   });
-});
\ No newline at end of file
+});
+