This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-js.git


The following commit(s) were added to refs/heads/master by this push:
     new 47a7ab5  Add support for action limits and annotations (#73)
47a7ab5 is described below

commit 47a7ab501c6e08edece5e3fea47483d4f9950c5c
Author: Olivier Tardieu <tard...@users.noreply.github.com>
AuthorDate: Fri Sep 29 10:24:45 2017 -0400

    Add support for action limits and annotations (#73)
    
    * Add support for action limits and annotations
    * Add unit tests
    * Add documentation for action annotations and limits
---
 README.md                 |  2 ++
 lib/actions.js            |  8 ++++++++
 test/unit/actions.test.js | 42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/README.md b/README.md
index ab80a96..fdd4998 100644
--- a/README.md
+++ b/README.md
@@ -333,6 +333,8 @@ The following mandatory parameters are supported:
 The following optional parameters are supported:
 - `namespace` - set custom namespace for endpoint
 - `params` - object containing default parameters for the action (default: 
`{}`)
+- `annotations` - object containing annotations for the action (default: `{}`)
+- `limits` - object containing limits for the action (default: `{}`)
 - `kind` - runtime environment parameter, ignored when `action` is an object 
(default: `nodejs:default`)
 - `version` - set semantic version of the action. If parameter is empty when 
create new action openwisk generate 0.0.1 value when update an action increase 
the patch version.
 
diff --git a/lib/actions.js b/lib/actions.js
index 05dde00..87ca22c 100644
--- a/lib/actions.js
+++ b/lib/actions.js
@@ -57,6 +57,14 @@ class Actions extends Resources {
       body.version = options.version;
     }
 
+    if (options.limits) {
+      body.limits = options.limits;
+    }
+
+    if (typeof options.annotations === 'object') {
+      body.annotations = Object.keys(options.annotations).map(key => ({ key, 
value: options.annotations[key] }))
+    }
+
     return body
   }
 }
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index cc75ec8..fd16af1 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -328,6 +328,48 @@ test('create a new action with default parameters', t => {
   return actions.create({name: '12345', action, params})
 })
 
+test('create a new action with annotations', t => {
+  t.plan(4)
+  const ns = '_'
+  const client = {}
+  const action = 'function main() { // main function body};'
+  const annotations = {
+    foo: 'bar'
+  }
+  const actions = new Actions(client)
+
+  client.request = (method, path, options) => {
+    t.is(method, 'PUT')
+    t.is(path, `namespaces/${ns}/actions/12345`)
+    t.deepEqual(options.qs, {})
+    t.deepEqual(options.body, {exec: {kind: 'nodejs:default', code: action}, 
annotations: [
+      { key: 'foo', value: 'bar' }
+    ]})
+  }
+
+  return actions.create({name: '12345', action, annotations})
+})
+
+test('create a new action with limits', t => {
+  t.plan(4)
+  const ns = '_'
+  const client = {}
+  const action = 'function main() { // main function body};'
+  const limits = {
+    timeout: 300000
+  }
+  const actions = new Actions(client)
+
+  client.request = (method, path, options) => {
+    t.is(method, 'PUT')
+    t.is(path, `namespaces/${ns}/actions/12345`)
+    t.deepEqual(options.qs, {})
+    t.deepEqual(options.body, {exec: {kind: 'nodejs:default', code: action}, 
limits: {timeout: 300000}})
+  }
+
+  return actions.create({name: '12345', action, limits})
+})
+
 test('create an action without providing an action body', t => {
   const actions = new Actions()
   t.throws(() => actions.create({name: '12345'}), /Missing mandatory action/)

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Reply via email to