You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dg...@apache.org on 2022/08/15 15:20:42 UTC

[openwhisk-runtime-rust] branch master updated: Support array result include sequence action (#39)

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

dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new ebddcbd  Support array result include sequence action (#39)
ebddcbd is described below

commit ebddcbd04f492efaddd36aaf323a92648538cff7
Author: ningyougang <41...@qq.com>
AuthorDate: Mon Aug 15 23:20:38 2022 +0800

    Support array result include sequence action (#39)
---
 README.md                                          | 37 +++++++++++++++
 core/rust1.34/Dockerfile                           |  8 ++--
 .../ActionLoopRustBasicTests.scala                 | 55 ++++++++++++++++++++++
 3 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 6141791..d6bad70 100644
--- a/README.md
+++ b/README.md
@@ -62,6 +62,43 @@ pub fn main(args: Value) -> Result<Value, Error> {
 
 The action is mainly composed by a `main` function that accepts a JSON `serdes Value` as input and returns a `Result` including a JSON `serde Value`.
 
+For the return result, not only support `A JSON serde Value` but also support `Array serde Value`
+
+So a simple `hello array` funtion would be:
+
+```rust
+extern crate serde_json;
+
+use serde_derive::{Deserialize, Serialize};
+use serde_json::{Error, Value};
+
+
+pub fn main(args: Value) -> Result<Value, Error> {
+    let output = ["a", "b"];
+    serde_json::to_value(output)
+}
+```
+
+And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.
+
+So the function can be:
+
+```rust
+extern crate serde_json;
+
+use serde_derive::{Deserialize, Serialize};
+use serde_json::{Error, Value};
+
+
+pub fn main(args: Value) -> Result<Value, Error> {
+    let inputParam = args.as_array();
+    let defaultOutput = ["c", "d"];
+    match inputParam {
+        None => serde_json::to_value(defaultOutput),
+        Some(x) => serde_json::to_value(x),
+    }
+}
+```
 ### Managing dependencies
 
 If your action needs external dependencies, you need to provide a zip file including your source, and your cargo file with all your dependencies. The folder structure is the following:
diff --git a/core/rust1.34/Dockerfile b/core/rust1.34/Dockerfile
index 6c1e38a..d099341 100644
--- a/core/rust1.34/Dockerfile
+++ b/core/rust1.34/Dockerfile
@@ -16,7 +16,7 @@
 #
 
 # build go proxy from source
-FROM golang:1.16 AS builder_source
+FROM golang:1.18 AS builder_source
 ARG GO_PROXY_GITHUB_USER=apache
 ARG GO_PROXY_GITHUB_BRANCH=master
 RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
@@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \
    mv proxy /bin/proxy
 
 # or build it from a release
-FROM golang:1.16 AS builder_release
-ARG GO_PROXY_RELEASE_VERSION=1.16@1.19.0
+FROM golang:1.18 AS builder_release
+ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0
 RUN curl -sL \
   https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\
   | tar xzf -\
   && cd openwhisk-runtime-go-*/main\
-  && GO111MODULE=on go build -o /bin/proxy
+  && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy
 
 FROM rust:1.34
 
diff --git a/tests/src/test/scala/runtime/actionContainers/ActionLoopRustBasicTests.scala b/tests/src/test/scala/runtime/actionContainers/ActionLoopRustBasicTests.scala
index fd73a36..eeac573 100644
--- a/tests/src/test/scala/runtime/actionContainers/ActionLoopRustBasicTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/ActionLoopRustBasicTests.scala
@@ -21,6 +21,7 @@ import actionContainers.{ActionContainer, BasicActionRunnerTests}
 import common.WskActorSystem
 import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
+import spray.json.{JsArray, JsObject, JsString}
 
 @RunWith(classOf[JUnitRunner])
 class ActionLoopRustBasicTests extends BasicActionRunnerTests with WskActorSystem {
@@ -136,4 +137,58 @@ class ActionLoopRustBasicTests extends BasicActionRunnerTests with WskActorSyste
                   |    Ok(args)
                   |}
                 """.stripMargin)
+
+  it should "support return array result" in {
+    val (out, err) = withActionLoopContainer { c =>
+      val code = """
+                   |extern crate serde_json;
+                   |
+                   |use serde_derive::{Deserialize, Serialize};
+                   |use serde_json::{Error, Value};
+                   |
+                   |
+                   |pub fn main(args: Value) -> Result<Value, Error> {
+                   |    let output = ["a", "b"];
+                   |    serde_json::to_value(output)
+                   |}
+                 """.stripMargin
+
+      val (initCode, _) = c.init(initPayload(code))
+
+      initCode should be(200)
+
+      val (runCode, runRes) = c.runForJsArray(runPayload(JsObject()))
+      runCode should be(200)
+      runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+    }
+  }
+
+  it should "support array as input param" in {
+    val (out, err) = withActionLoopContainer { c =>
+      val code = """
+                   |extern crate serde_json;
+                   |
+                   |use serde_derive::{Deserialize, Serialize};
+                   |use serde_json::{Error, Value};
+                   |
+                   |
+                   |pub fn main(args: Value) -> Result<Value, Error> {
+                   |    let inputParam = args.as_array();
+                   |    let defaultOutput = ["c", "d"];
+                   |    match inputParam {
+                   |        None => serde_json::to_value(defaultOutput),
+                   |        Some(x) => serde_json::to_value(x),
+                   |    }
+                   |}
+                 """.stripMargin
+
+      val (initCode, _) = c.init(initPayload(code))
+
+      initCode should be(200)
+
+      val (runCode, runRes) = c.runForJsArray(runPayload(JsArray(JsString("a"), JsString("b"))))
+      runCode should be(200)
+      runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+    }
+  }
 }