You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2018/06/09 04:23:29 UTC
[incubator-openwhisk] branch master updated: Rationalize
actionContainers tests (#3467)
This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new d041a8e Rationalize actionContainers tests (#3467)
d041a8e is described below
commit d041a8e3ecbfd8993f19d0af68851ea3d2057384
Author: Jonathan Springer <jo...@gmail.com>
AuthorDate: Sat Jun 9 00:23:25 2018 -0400
Rationalize actionContainers tests (#3467)
---
.../scala/actionContainers/ActionContainer.scala | 37 +-
.../ActionProxyContainerTests.scala | 392 ---------------
.../actionContainers/BasicActionRunnerTests.scala | 169 +++++++
.../DockerExampleContainerTests.scala | 151 ------
.../JavaActionContainerTests.scala | 352 -------------
.../NodeJs8ActionContainerTests.scala | 54 --
.../NodeJsActionContainerTests.scala | 554 ---------------------
.../Php71ActionContainerTests.scala | 494 ------------------
.../Python2ActionContainerTests.scala | 31 --
.../PythonActionContainerTests.scala | 383 --------------
.../Swift311ActionContainerTests.scala | 371 --------------
11 files changed, 195 insertions(+), 2793 deletions(-)
diff --git a/tests/src/test/scala/actionContainers/ActionContainer.scala b/tests/src/test/scala/actionContainers/ActionContainer.scala
index 97915c8..b02d3ac 100644
--- a/tests/src/test/scala/actionContainers/ActionContainer.scala
+++ b/tests/src/test/scala/actionContainers/ActionContainer.scala
@@ -39,6 +39,7 @@ import common.StreamLogging
import whisk.common.Logging
import whisk.common.TransactionId
import whisk.core.entity.Exec
+import common.WhiskProperties
/**
* For testing convenience, this interface abstracts away the REST calls to a
@@ -90,8 +91,16 @@ object ActionContainer {
private lazy val dockerCmd: String = {
/*
* The docker host is set to a provided property 'docker.host' if it's
- * available; otherwise by the environment variable DOCKER_HOST
- * (which is usually set, especially for DOCKER_MACHINE).
+ * available; otherwise we check with WhiskProperties to see whether we are
+ * running on a docker-machine.
+ *
+ * IMPLICATION: The test must EITHER have the 'docker.host' system
+ * property set OR the 'OPENWHISK_HOME' environment variable set and a
+ * valid 'whisk.properties' file generated. The 'docker.host' system
+ * property takes precedence.
+ *
+ * WARNING: Adding a non-docker-machine environment that contains 'mac'
+ * (i.e. 'environments/local-mac') will likely break things.
*
* The plan is to move builds to using 'gradle-docker-plugin', which know
* its docker socket and to have it pass the docker socket implicitly using
@@ -104,19 +113,25 @@ object ActionContainer {
sys.props
.get("docker.host")
.orElse(sys.env.get("DOCKER_HOST"))
+ .orElse {
+ // Check if we are running on docker-machine env.
+ Option(WhiskProperties.getProperty("whisk.version.name")).filter(_.toLowerCase.contains("mac")).map {
+ case _ => s"tcp://${WhiskProperties.getMainDockerEndpoint}"
+ }
+ }
.map(" --host " + _)
.getOrElse("")
+
// Test here that this actually works, otherwise throw a somewhat understandable error message
proc(s"$dockerCmdString info").onComplete {
- case Success((v, _, _)) if (v != 0) =>
- throw new RuntimeException(s"""Unable to connect to docker host using $dockerCmdString as command string.
- |The docker host is determined using the Java property 'docker.host' or
- |the envirnoment variable 'DOCKER_HOST'. Please verify that one or the
- |other is set for your build/test process.""".stripMargin)
- case Success((v, _, _)) if (v == 0) =>
- // Do nothing
- case Failure(t) =>
- throw t
+ case Success((v, _, _)) if v != 0 =>
+ throw new RuntimeException(s"""
+ |Unable to connect to docker host using $dockerCmdString as command string.
+ |The docker host is determined using the Java property 'docker.host' or
+ |the envirnoment variable 'DOCKER_HOST'. Please verify that one or the
+ |other is set for your build/test process.""".stripMargin)
+ case Success((v, _, _)) if v == 0 => // Do nothing
+ case Failure(t) => throw t
}
dockerCmdString
diff --git a/tests/src/test/scala/actionContainers/ActionProxyContainerTests.scala b/tests/src/test/scala/actionContainers/ActionProxyContainerTests.scala
deleted file mode 100644
index c06fafc..0000000
--- a/tests/src/test/scala/actionContainers/ActionProxyContainerTests.scala
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import java.io.File
-import java.util.Base64
-
-import org.apache.commons.io.FileUtils
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import ActionContainer.withContainer
-import common.TestUtils
-import common.WskActorSystem
-import spray.json.DefaultJsonProtocol._
-import spray.json._
-
-@RunWith(classOf[JUnitRunner])
-class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSystem {
-
- override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
- withContainer("dockerskeleton", env)(code)
- }
-
- val codeNotReturningJson = """
- |#!/bin/sh
- |echo not a json object
- """.stripMargin.trim
-
- /** Standard code samples, should print 'hello' to stdout and echo the input args. */
- val stdCodeSamples = {
- val bash = """
- |#!/bin/bash
- |echo 'hello stdout'
- |echo 'hello stderr' 1>&2
- |if [[ -z $1 || $1 == '{}' ]]; then
- | echo '{ "msg": "Hello from bash script!" }'
- |else
- | echo $1 # echo the arguments back as the result
- |fi
- """.stripMargin.trim
-
- val python = """
- |#!/usr/bin/env python
- |from __future__ import print_function
- |import sys
- |print('hello stdout')
- |print('hello stderr', file=sys.stderr)
- |print(sys.argv[1])
- """.stripMargin.trim
-
- val perl = """
- |#!/usr/bin/env perl
- |print STDOUT "hello stdout\n";
- |print STDERR "hello stderr\n";
- |print $ARGV[0];
- """.stripMargin.trim
-
- Seq(("bash", bash), ("python", python), ("perl", perl))
- }
-
- val stdUnicodeSamples = {
- // python 3 in base image
- val python = """
- |#!/usr/bin/env python
- |import json, sys
- |j = json.loads(sys.argv[1])
- |sep = j["delimiter"]
- |s = sep + " ☃ " + sep
- |print(s)
- |print(json.dumps({"winter": s}))
- """.stripMargin.trim
-
- Seq(("python", python))
- }
-
- /** Standard code samples, should print 'hello' to stdout and echo the input args. */
- val stdEnvSamples = {
- val bash = """
- |#!/bin/bash
- |echo "{ \
- |\"api_host\": \"$__OW_API_HOST\", \"api_key\": \"$__OW_API_KEY\", \
- |\"namespace\": \"$__OW_NAMESPACE\", \"action_name\": \"$__OW_ACTION_NAME\", \
- |\"activation_id\": \"$__OW_ACTIVATION_ID\", \"deadline\": \"$__OW_DEADLINE\" }"
- """.stripMargin.trim
-
- val python =
- """
- |#!/usr/bin/env python
- |import os
- |
- |print('{ "api_host": "%s", "api_key": "%s", "namespace": "%s", "action_name" : "%s", "activation_id": "%s", "deadline": "%s" }' % (
- | os.environ['__OW_API_HOST'], os.environ['__OW_API_KEY'],
- | os.environ['__OW_NAMESPACE'], os.environ['__OW_ACTION_NAME'],
- | os.environ['__OW_ACTIVATION_ID'], os.environ['__OW_DEADLINE']))
- """.stripMargin.trim
-
- val perl =
- """
- |#!/usr/bin/env perl
- |$a = $ENV{'__OW_API_HOST'};
- |$b = $ENV{'__OW_API_KEY'};
- |$c = $ENV{'__OW_NAMESPACE'};
- |$d = $ENV{'__OW_ACTION_NAME'};
- |$e = $ENV{'__OW_ACTIVATION_ID'};
- |$f = $ENV{'__OW_DEADLINE'};
- |print "{ \"api_host\": \"$a\", \"api_key\": \"$b\", \"namespace\": \"$c\", \"action_name\": \"$d\", \"activation_id\": \"$e\", \"deadline\": \"$f\" }";
- """.stripMargin.trim
-
- Seq(("bash", bash), ("python", python), ("perl", perl))
- }
-
- /** Large param samples, echo the input args with input larger than 128K and using STDIN */
- val stdLargeInputSamples = {
- val bash = """
- |#!/bin/bash
- | read inputstring
- | echo $inputstring
- """.stripMargin.trim
-
- val python = """
- |#!/usr/bin/env python
- |import sys, json
- |params = sys.stdin.readline()
- |j = json.loads(params)
- |print(json.dumps(j))
- """.stripMargin.trim
-
- val perl = """
- |#!/usr/bin/env perl
- |$params=<STDIN>;
- |print $params;
- """.stripMargin.trim
-
- Seq(("bash", bash), ("python", python), ("perl", perl))
- }
-
- behavior of "openwhisk/dockerskeleton"
-
- it should "run sample without init" in {
- val (out, err) = withActionContainer() { c =>
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- out should be(Some(JsObject("error" -> JsString("This is a stub action. Replace it with custom logic."))))
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is a stub action")
- })
- }
-
- it should "run sample with 'null' init" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(null))
- initCode should be(200)
-
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- out should be(Some(JsObject("error" -> JsString("This is a stub action. Replace it with custom logic."))))
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is a stub action")
- })
- }
-
- it should "run sample with init that does nothing" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(JsObject())
- initCode should be(200)
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- out should be(Some(JsObject("error" -> JsString("This is a stub action. Replace it with custom logic."))))
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is a stub action")
- })
- }
-
- it should "respond with 404 for bad run argument" in {
- val (out, err) = withActionContainer() { c =>
- val (runCode, out) = c.run(runPayload(JsString("A")))
- runCode should be(404)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "fail to run a bad script" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(""))
- initCode should be(200)
- val (runCode, out) = c.run(JsNull)
- runCode should be(502)
- out should be(Some(JsObject("error" -> JsString("The action did not return a dictionary."))))
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("error")
- })
- }
-
- it should "extract and run a compatible zip exec" in {
- val zip = FileUtils.readFileToByteArray(new File(TestUtils.getTestActionFilename("blackbox.zip")))
- val contents = Base64.getEncoder.encodeToString(zip)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, err) =
- c.init(JsObject("value" -> JsObject("code" -> JsString(contents), "binary" -> JsBoolean(true))))
- initCode should be(200)
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- out.get should be(JsObject("msg" -> JsString("hello zip")))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe "This is an example zip used with the docker skeleton action."
- e shouldBe empty
- })
- }
-
- testNotReturningJson(codeNotReturningJson, checkResultInLogs = true)
- testEcho(stdCodeSamples)
- testUnicode(stdUnicodeSamples)
- testEnv(stdEnvSamples)
- testLargeInput(stdLargeInputSamples)
-}
-
-trait BasicActionRunnerTests extends ActionProxyContainerTestUtils {
- def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit): (String, String)
-
- /**
- * Runs tests for actions which do not return a dictionary and confirms expected error messages.
- * @param codeNotReturningJson code to execute, should not return a JSON object
- * @param checkResultInLogs should be true iff the result of the action is expected to appear in stdout or stderr
- */
- def testNotReturningJson(codeNotReturningJson: String, checkResultInLogs: Boolean = true) = {
- it should "run and report an error for script not returning a json object" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(codeNotReturningJson))
- initCode should be(200)
- val (runCode, out) = c.run(JsObject())
- runCode should be(502)
- out should be(Some(JsObject("error" -> JsString("The action did not return a dictionary."))))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (checkResultInLogs) {
- (o + e) should include("not a json object")
- } else {
- o shouldBe empty
- e shouldBe empty
- }
- })
- }
- }
-
- /**
- * Runs tests for code samples which are expected to echo the input arguments
- * and print hello [stdout, stderr].
- */
- def testEcho(stdCodeSamples: Seq[(String, String)]) = {
- stdCodeSamples.foreach { s =>
- it should s"run a ${s._1} script" in {
- val argss = List(
- JsObject("string" -> JsString("hello")),
- JsObject("string" -> JsString("❄ ☃ ❄")),
- JsObject("numbers" -> JsArray(JsNumber(42), JsNumber(1))),
- // JsObject("boolean" -> JsBoolean(true)), // fails with swift3 returning boolean: 1
- JsObject("object" -> JsObject("a" -> JsString("A"))))
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(s._2))
- initCode should be(200)
-
- for (args <- argss) {
- val (runCode, out) = c.run(runPayload(args))
- runCode should be(200)
- out should be(Some(args))
- }
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o should include("hello stdout")
- e should include("hello stderr")
- }, argss.length)
- }
- }
- }
-
- def testUnicode(stdUnicodeSamples: Seq[(String, String)]) = {
- stdUnicodeSamples.foreach { s =>
- it should s"run a ${s._1} action and handle unicode in source, input params, logs, and result" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(s._2))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject("delimiter" -> JsString("❄"))))
- runRes.get.fields.get("winter") shouldBe Some(JsString("❄ ☃ ❄"))
- }
-
- checkStreams(out, err, {
- case (o, _) =>
- o.toLowerCase should include("❄ ☃ ❄")
- })
- }
- }
- }
-
- /** Runs tests for code samples which are expected to return the expected standard environment {auth, edge}. */
- def testEnv(stdEnvSamples: Seq[(String, String)],
- enforceEmptyOutputStream: Boolean = true,
- enforceEmptyErrorStream: Boolean = true) = {
- stdEnvSamples.foreach { s =>
- it should s"run a ${s._1} script and confirm expected environment variables" in {
- val props = Seq(
- "api_host" -> "xyz",
- "api_key" -> "abc",
- "namespace" -> "zzz",
- "action_name" -> "xxx",
- "activation_id" -> "iii",
- "deadline" -> "123")
- val env = props.map { case (k, v) => s"__OW_${k.toUpperCase()}" -> v }
-
- val (out, err) = withActionContainer(env.take(1).toMap) { c =>
- val (initCode, _) = c.init(initPayload(s._2))
- initCode should be(200)
-
- val (runCode, out) = c.run(runPayload(JsObject(), Some(props.toMap.toJson.asJsObject)))
- runCode should be(200)
- out shouldBe defined
- props.map {
- case (k, v) =>
- withClue(k) {
- out.get.fields(k) shouldBe JsString(v)
- }
-
- }
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- if (enforceEmptyErrorStream) e shouldBe empty
- })
- }
- }
- }
-
- /**
- * Large param samples, echo the input args with input larger than 128K and using STDIN
- */
- def testLargeInput(stdLargeInputSamples: Seq[(String, String)]) = {
- stdLargeInputSamples.foreach { s =>
- it should s"run a ${s._1} script with large input" in {
- val (out, err) = withActionContainer() { c =>
- val (initCode, _) = c.init(initPayload(s._2))
- initCode should be(200)
-
- val arg = JsObject("arg" -> JsString(("a" * 1048561)))
- val (_, runRes) = c.run(runPayload(arg))
- runRes.get shouldBe arg
- }
-
- }
- }
- }
-
-}
diff --git a/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala b/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
new file mode 100644
index 0000000..7072c86
--- /dev/null
+++ b/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package actionContainers
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import spray.json.DefaultJsonProtocol._
+import spray.json._
+
+@RunWith(classOf[JUnitRunner])
+trait BasicActionRunnerTests extends ActionProxyContainerTestUtils {
+ def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit): (String, String)
+
+ /**
+ * Runs tests for actions which do not return a dictionary and confirms expected error messages.
+ * @param codeNotReturningJson code to execute, should not return a JSON object
+ * @param checkResultInLogs should be true iff the result of the action is expected to appear in stdout or stderr
+ */
+ def testNotReturningJson(codeNotReturningJson: String, checkResultInLogs: Boolean = true) = {
+ it should "run and report an error for script not returning a json object" in {
+ val (out, err) = withActionContainer() { c =>
+ val (initCode, _) = c.init(initPayload(codeNotReturningJson))
+ initCode should be(200)
+ val (runCode, out) = c.run(JsObject())
+ runCode should be(502)
+ out should be(Some(JsObject("error" -> JsString("The action did not return a dictionary."))))
+ }
+
+ checkStreams(out, err, {
+ case (o, e) =>
+ if (checkResultInLogs) {
+ (o + e) should include("not a json object")
+ } else {
+ o shouldBe empty
+ e shouldBe empty
+ }
+ })
+ }
+ }
+
+ /**
+ * Runs tests for code samples which are expected to echo the input arguments
+ * and print hello [stdout, stderr].
+ */
+ def testEcho(stdCodeSamples: Seq[(String, String)]) = {
+ stdCodeSamples.foreach { s =>
+ it should s"run a ${s._1} script" in {
+ val argss = List(
+ JsObject("string" -> JsString("hello")),
+ JsObject("string" -> JsString("❄ ☃ ❄")),
+ JsObject("numbers" -> JsArray(JsNumber(42), JsNumber(1))),
+ // JsObject("boolean" -> JsBoolean(true)), // fails with swift3 returning boolean: 1
+ JsObject("object" -> JsObject("a" -> JsString("A"))))
+
+ val (out, err) = withActionContainer() { c =>
+ val (initCode, _) = c.init(initPayload(s._2))
+ initCode should be(200)
+
+ for (args <- argss) {
+ val (runCode, out) = c.run(runPayload(args))
+ runCode should be(200)
+ out should be(Some(args))
+ }
+ }
+
+ checkStreams(out, err, {
+ case (o, e) =>
+ o should include("hello stdout")
+ e should include("hello stderr")
+ }, argss.length)
+ }
+ }
+ }
+
+ def testUnicode(stdUnicodeSamples: Seq[(String, String)]) = {
+ stdUnicodeSamples.foreach { s =>
+ it should s"run a ${s._1} action and handle unicode in source, input params, logs, and result" in {
+ val (out, err) = withActionContainer() { c =>
+ val (initCode, _) = c.init(initPayload(s._2))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.run(runPayload(JsObject("delimiter" -> JsString("❄"))))
+ runRes.get.fields.get("winter") shouldBe Some(JsString("❄ ☃ ❄"))
+ }
+
+ checkStreams(out, err, {
+ case (o, _) =>
+ o.toLowerCase should include("❄ ☃ ❄")
+ })
+ }
+ }
+ }
+
+ /** Runs tests for code samples which are expected to return the expected standard environment {auth, edge}. */
+ def testEnv(stdEnvSamples: Seq[(String, String)],
+ enforceEmptyOutputStream: Boolean = true,
+ enforceEmptyErrorStream: Boolean = true) = {
+ stdEnvSamples.foreach { s =>
+ it should s"run a ${s._1} script and confirm expected environment variables" in {
+ val props = Seq(
+ "api_host" -> "xyz",
+ "api_key" -> "abc",
+ "namespace" -> "zzz",
+ "action_name" -> "xxx",
+ "activation_id" -> "iii",
+ "deadline" -> "123")
+ val env = props.map { case (k, v) => s"__OW_${k.toUpperCase()}" -> v }
+
+ val (out, err) = withActionContainer(env.take(1).toMap) { c =>
+ val (initCode, _) = c.init(initPayload(s._2))
+ initCode should be(200)
+
+ val (runCode, out) = c.run(runPayload(JsObject(), Some(props.toMap.toJson.asJsObject)))
+ runCode should be(200)
+ out shouldBe defined
+ props.map {
+ case (k, v) =>
+ withClue(k) {
+ out.get.fields(k) shouldBe JsString(v)
+ }
+
+ }
+ }
+
+ checkStreams(out, err, {
+ case (o, e) =>
+ if (enforceEmptyOutputStream) o shouldBe empty
+ if (enforceEmptyErrorStream) e shouldBe empty
+ })
+ }
+ }
+ }
+
+ /**
+ * Large param samples, echo the input args with input larger than 128K and using STDIN
+ */
+ def testLargeInput(stdLargeInputSamples: Seq[(String, String)]) = {
+ stdLargeInputSamples.foreach { s =>
+ it should s"run a ${s._1} script with large input" in {
+ val (out, err) = withActionContainer() { c =>
+ val (initCode, _) = c.init(initPayload(s._2))
+ initCode should be(200)
+
+ val arg = JsObject("arg" -> JsString(("a" * 1048561)))
+ val (_, runRes) = c.run(runPayload(arg))
+ runRes.get shouldBe arg
+ }
+
+ }
+ }
+ }
+
+}
diff --git a/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala b/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala
deleted file mode 100644
index a28b611..0000000
--- a/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import java.util.concurrent.TimeoutException
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import ActionContainer.withContainer
-import common.WskActorSystem
-import spray.json.JsNumber
-import spray.json.JsObject
-import spray.json.JsString
-import spray.json.JsBoolean
-
-@RunWith(classOf[JUnitRunner])
-class DockerExampleContainerTests extends ActionProxyContainerTestUtils with WskActorSystem {
-
- // "example" is the image build by /sdk/docker
- def withPythonContainer(code: ActionContainer => Unit) = withContainer("example")(code)
-
- behavior of "openwhisk/example"
-
- private def checkresponse(res: Option[JsObject], args: JsObject = JsObject()) = {
- res shouldBe defined
- res.get.fields("msg") shouldBe JsString("Hello from arbitrary C program!")
- res.get.fields("args") shouldBe args
- }
-
- it should "run sample without init" in {
- val (out, err) = withPythonContainer { c =>
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- checkresponse(out)
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is an example log message from an arbitrary C program!")
- })
- }
-
- it should "run sample with init that does nothing" in {
- val (out, err) = withPythonContainer { c =>
- val (initCode, _) = c.init(JsObject())
- initCode should be(200)
- val (runCode, out) = c.run(JsObject())
- runCode should be(200)
- checkresponse(out)
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is an example log message from an arbitrary C program!")
- })
- }
-
- it should "run sample with argument" in {
- val (out, err) = withPythonContainer { c =>
- val argss = List(JsObject("a" -> JsString("A")), JsObject("i" -> JsNumber(1)))
-
- for (args <- argss) {
- val (runCode, out) = c.run(runPayload(args))
- runCode should be(200)
- checkresponse(out, args)
- }
- }
-
- checkStreams(out, err, {
- case (o, _) => o should include("This is an example log message from an arbitrary C program!")
- }, 2)
- }
-
- behavior of "bad containers"
-
- it should "timeout init with exception" in {
- val (out, err) = withContainer("badaction") { c =>
- a[TimeoutException] should be thrownBy {
- val (code, out) = c.init(initPayload("sleep"))
- println(code, out)
- }
- }
-
- out should include("sleeping")
- err shouldBe empty
- }
-
- it should "abort init with empty response" in {
- val (out, err) = withContainer("badaction") { c =>
- val (code, out) = c.init(initPayload("exit"))
- code shouldBe 500
- out shouldBe empty
- }
-
- out should include("exit")
- // err stream may not be empty if the proxy did not get a chance to
- // drain the action's out/err streams; skip check on err stream
- }
-
- it should "timeout run with exception" in {
- val (out, err) = withContainer("badaction") { c =>
- a[TimeoutException] should be thrownBy {
- val (code, out) = c.run(runPayload(JsObject("sleep" -> JsBoolean(true))))
- println(code, out)
- }
- }
-
- out should include("sleeping")
- err shouldBe empty
- }
-
- it should "abort run with empty response" in {
- val (out, err) = withContainer("badaction") { c =>
- val (code, out) = c.run(runPayload(JsObject("exit" -> JsBoolean(true))))
- code shouldBe 500
- out shouldBe empty
- }
-
- out should include("exit")
- // err stream may not be empty if the proxy did not get a chance to
- // drain the action's out/err streams; skip check on err stream
- }
-
- it should "timeout bad proxy with exception" in {
- val (out, err) = withContainer("badproxy") { c =>
- val ex = the[Exception] thrownBy {
- val (code, out) = c.init(JsObject())
- println(code, out)
- }
-
- ex should (be(a[TimeoutException]) or be(a[IllegalStateException]))
- }
-
- out shouldBe empty
- err shouldBe empty
- }
-}
diff --git a/tests/src/test/scala/actionContainers/JavaActionContainerTests.scala b/tests/src/test/scala/actionContainers/JavaActionContainerTests.scala
deleted file mode 100644
index efa2743..0000000
--- a/tests/src/test/scala/actionContainers/JavaActionContainerTests.scala
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.FlatSpec
-import org.scalatest.Matchers
-import org.scalatest.junit.JUnitRunner
-import spray.json.DefaultJsonProtocol._
-import spray.json._
-
-import ActionContainer.withContainer
-import ResourceHelpers.JarBuilder
-
-import common.WskActorSystem
-
-@RunWith(classOf[JUnitRunner])
-class JavaActionContainerTests extends FlatSpec with Matchers with WskActorSystem with ActionProxyContainerTestUtils {
-
- // Helpers specific to java actions
- def withJavaContainer(code: ActionContainer => Unit, env: Map[String, String] = Map.empty) =
- withContainer("java8action", env)(code)
-
- override def initPayload(mainClass: String, jar64: String) =
- JsObject(
- "value" -> JsObject("name" -> JsString("dummyAction"), "main" -> JsString(mainClass), "code" -> JsString(jar64)))
-
- behavior of "Java action"
-
- it should s"run a java snippet and confirm expected environment variables" in {
- val props = Seq(
- "api_host" -> "xyz",
- "api_key" -> "abc",
- "namespace" -> "zzz",
- "action_name" -> "xxx",
- "activation_id" -> "iii",
- "deadline" -> "123")
- val env = props.map { case (k, v) => s"__OW_${k.toUpperCase}" -> v }
- val (out, err) =
- withJavaContainer(
- { c =>
- val jar = JarBuilder.mkBase64Jar(
- Seq("example", "HelloWhisk.java") -> """
- | package example;
- |
- | import com.google.gson.JsonObject;
- |
- | public class HelloWhisk {
- | public static JsonObject main(JsonObject args) {
- | JsonObject response = new JsonObject();
- | response.addProperty("api_host", System.getenv("__OW_API_HOST"));
- | response.addProperty("api_key", System.getenv("__OW_API_KEY"));
- | response.addProperty("namespace", System.getenv("__OW_NAMESPACE"));
- | response.addProperty("action_name", System.getenv("__OW_ACTION_NAME"));
- | response.addProperty("activation_id", System.getenv("__OW_ACTIVATION_ID"));
- | response.addProperty("deadline", System.getenv("__OW_DEADLINE"));
- | return response;
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar))
- initCode should be(200)
-
- val (runCode, out) = c.run(runPayload(JsObject(), Some(props.toMap.toJson.asJsObject)))
- runCode should be(200)
- props.map {
- case (k, v) => out.get.fields(k) shouldBe JsString(v)
-
- }
- },
- env.take(1).toMap)
-
- out.trim shouldBe empty
- err.trim shouldBe empty
- }
-
- it should "support valid flows" in {
- val (out, err) = withJavaContainer { c =>
- val jar = JarBuilder.mkBase64Jar(
- Seq("example", "HelloWhisk.java") -> """
- | package example;
- |
- | import com.google.gson.JsonObject;
- |
- | public class HelloWhisk {
- | public static JsonObject main(JsonObject args) {
- | String name = args.getAsJsonPrimitive("name").getAsString();
- | JsonObject response = new JsonObject();
- | response.addProperty("greeting", "Hello " + name + "!");
- | return response;
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar))
- initCode should be(200)
-
- val (runCode1, out1) = c.run(runPayload(JsObject("name" -> JsString("Whisk"))))
- runCode1 should be(200)
- out1 should be(Some(JsObject("greeting" -> JsString("Hello Whisk!"))))
-
- val (runCode2, out2) = c.run(runPayload(JsObject("name" -> JsString("ksihW"))))
- runCode2 should be(200)
- out2 should be(Some(JsObject("greeting" -> JsString("Hello ksihW!"))))
- }
-
- out.trim shouldBe empty
- err.trim shouldBe empty
- }
-
- it should "handle unicode in source, input params, logs, and result" in {
- val (out, err) = withJavaContainer { c =>
- val jar = JarBuilder.mkBase64Jar(
- Seq("example", "HelloWhisk.java") -> """
- | package example;
- |
- | import com.google.gson.JsonObject;
- |
- | public class HelloWhisk {
- | public static JsonObject main(JsonObject args) {
- | String delimiter = args.getAsJsonPrimitive("delimiter").getAsString();
- | JsonObject response = new JsonObject();
- | String str = delimiter + " ☃ " + delimiter;
- | System.out.println(str);
- | response.addProperty("winter", str);
- | return response;
- | }
- | }
- """.stripMargin)
-
- val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar))
- val (runCode, runRes) = c.run(runPayload(JsObject("delimiter" -> JsString("❄"))))
- runRes.get.fields.get("winter") shouldBe Some(JsString("❄ ☃ ❄"))
- }
-
- out should include("❄ ☃ ❄")
- err.trim shouldBe empty
- }
-
- it should "fail to initialize with bad code" in {
- val (out, err) = withJavaContainer { c =>
- // This is valid zip file containing a single file, but not a valid
- // jar file.
- val brokenJar = ("UEsDBAoAAAAAAPxYbkhT4iFbCgAAAAoAAAANABwAbm90YWNsYXNzZmlsZVV" +
- "UCQADzNPmVszT5lZ1eAsAAQT1AQAABAAAAABzYXVjaXNzb24KUEsBAh4DCg" +
- "AAAAAA/FhuSFPiIVsKAAAACgAAAA0AGAAAAAAAAQAAAKSBAAAAAG5vdGFjb" +
- "GFzc2ZpbGVVVAUAA8zT5lZ1eAsAAQT1AQAABAAAAABQSwUGAAAAAAEAAQBT" +
- "AAAAUQAAAAAA")
-
- val (initCode, _) = c.init(initPayload("example.Broken", brokenJar))
- initCode should not be (200)
- }
-
- // Somewhere, the logs should contain an exception.
- val combined = out + err
- combined.toLowerCase should include("exception")
- }
-
- it should "return some error on action error" in {
- val (out, err) = withJavaContainer { c =>
- val jar = JarBuilder.mkBase64Jar(
- Seq("example", "HelloWhisk.java") -> """
- | package example;
- |
- | import com.google.gson.JsonObject;
- |
- | public class HelloWhisk {
- | public static JsonObject main(JsonObject args) throws Exception {
- | throw new Exception("noooooooo");
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should not be (200)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
-
- val combined = out + err
- combined.toLowerCase should include("exception")
- }
-
- it should "support application errors" in {
- val (out, err) = withJavaContainer { c =>
- val jar = JarBuilder.mkBase64Jar(
- Seq("example", "Error.java") -> """
- | package example;
- |
- | import com.google.gson.JsonObject;
- |
- | public class Error {
- | public static JsonObject main(JsonObject args) throws Exception {
- | JsonObject error = new JsonObject();
- | error.addProperty("error", "This action is unhappy.");
- | return error;
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.Error", jar))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
-
- val combined = out + err
- combined.trim shouldBe empty
- }
-
- it should "survive System.exit" in {
- val (out, err) = withJavaContainer { c =>
- val jar =
- JarBuilder.mkBase64Jar(Seq("example", "Quitter.java") -> """
- | package example;
- |
- | import com.google.gson.*;
- |
- | public class Quitter {
- | public static JsonObject main(JsonObject main) {
- | System.exit(1);
- | return new JsonObject();
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.Quitter", jar))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should not be (200)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
-
- val combined = out + err
- combined.toLowerCase should include("system.exit")
- }
-
- it should "enforce that the user returns an object" in {
- withJavaContainer { c =>
- val jar =
- JarBuilder.mkBase64Jar(Seq("example", "Nuller.java") -> """
- | package example;
- |
- | import com.google.gson.*;
- |
- | public class Nuller {
- | public static JsonObject main(JsonObject args) {
- | return null;
- | }
- | }
- """.stripMargin.trim)
-
- val (initCode, _) = c.init(initPayload("example.Nuller", jar))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should not be (200)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
- }
-
- val dynamicLoadingJar = JarBuilder.mkBase64Jar(
- Seq(
- Seq("example", "EntryPoint.java") -> """
- | package example;
- |
- | import com.google.gson.*;
- | import java.lang.reflect.*;
- |
- | public class EntryPoint {
- | private final static String CLASS_NAME = "example.DynamicClass";
- | public static JsonObject main(JsonObject args) throws Exception {
- | String cl = args.getAsJsonPrimitive("classLoader").getAsString();
- |
- | Class d = null;
- | if("local".equals(cl)) {
- | d = Class.forName(CLASS_NAME);
- | } else if("thread".equals(cl)) {
- | d = Thread.currentThread().getContextClassLoader().loadClass(CLASS_NAME);
- | }
- |
- | Object o = d.newInstance();
- | Method m = o.getClass().getMethod("getMessage");
- | String msg = (String)m.invoke(o);
- |
- | JsonObject response = new JsonObject();
- | response.addProperty("message", msg);
- | return response;
- | }
- | }
- |""".stripMargin.trim,
- Seq("example", "DynamicClass.java") -> """
- | package example;
- |
- | public class DynamicClass {
- | public String getMessage() {
- | return "dynamic!";
- | }
- | }
- |""".stripMargin.trim))
-
- def classLoaderTest(param: String) = {
- val (out, err) = withJavaContainer { c =>
- val (initCode, _) = c.init(initPayload("example.EntryPoint", dynamicLoadingJar))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject("classLoader" -> JsString(param))))
- runCode should be(200)
-
- runRes shouldBe defined
- runRes.get.fields.get("message") shouldBe Some(JsString("dynamic!"))
- }
- (out ++ err).trim shouldBe empty
- }
-
- it should "support loading classes from the current classloader" in {
- classLoaderTest("local")
- }
-
- it should "support loading classes from the Thread classloader" in {
- classLoaderTest("thread")
- }
-}
diff --git a/tests/src/test/scala/actionContainers/NodeJs8ActionContainerTests.scala b/tests/src/test/scala/actionContainers/NodeJs8ActionContainerTests.scala
deleted file mode 100644
index 8727a7f..0000000
--- a/tests/src/test/scala/actionContainers/NodeJs8ActionContainerTests.scala
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-import spray.json.JsObject
-
-@RunWith(classOf[JUnitRunner])
-class NodeJs8ActionContainerTests extends NodeJsActionContainerTests {
-
- override lazy val nodejsContainerImageName = "action-nodejs-v8"
-
- it should "support async and await" in {
- withNodeJsContainer { c =>
- val code = """
- | const util = require('util');
- | const fs = require('fs');
- |
- | const stat = util.promisify(fs.stat);
- |
- | async function main() {
- | const stats = await stat('.');
- | return stats
- | }
- """.stripMargin;
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("uid") shouldBe defined
- }
- }
-
-}
diff --git a/tests/src/test/scala/actionContainers/NodeJsActionContainerTests.scala b/tests/src/test/scala/actionContainers/NodeJsActionContainerTests.scala
deleted file mode 100644
index be45a52..0000000
--- a/tests/src/test/scala/actionContainers/NodeJsActionContainerTests.scala
+++ /dev/null
@@ -1,554 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import ActionContainer.withContainer
-import ResourceHelpers.ZipBuilder
-
-import common.WskActorSystem
-import spray.json._
-
-@RunWith(classOf[JUnitRunner])
-class NodeJsActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
-
- lazy val nodejsContainerImageName = "nodejs6action"
-
- override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
- withContainer(nodejsContainerImageName, env)(code)
- }
-
- def withNodeJsContainer(code: ActionContainer => Unit) = withActionContainer()(code)
-
- behavior of nodejsContainerImageName
-
- testNotReturningJson("""
- |function main(args) {
- | return "not a json object"
- |}
- """.stripMargin)
-
- testEcho(Seq {
- (
- "node",
- """
- |function main(args) {
- | console.log('hello stdout')
- | console.error('hello stderr')
- | return args
- |}
- """.stripMargin)
- })
-
- testUnicode(Seq {
- (
- "node",
- """
- |function main(args) {
- | var str = args.delimiter + " ☃ " + args.delimiter;
- | console.log(str);
- | return { "winter": str };
- |}
- """.stripMargin.trim)
- })
-
- testEnv(Seq {
- (
- "node",
- """
- |function main(args) {
- | return {
- | "api_host": process.env['__OW_API_HOST'],
- | "api_key": process.env['__OW_API_KEY'],
- | "namespace": process.env['__OW_NAMESPACE'],
- | "action_name": process.env['__OW_ACTION_NAME'],
- | "activation_id": process.env['__OW_ACTIVATION_ID'],
- | "deadline": process.env['__OW_DEADLINE']
- | }
- |}
- """.stripMargin.trim)
- })
-
- it should "fail to initialize with bad code" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | 10 PRINT "Hello world!"
- | 20 GOTO 10
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should not be (200)
- }
-
- // Somewhere, the logs should mention an error occurred.
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("syntax")
- })
- }
-
- it should "fail to initialize with no code" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = ""
-
- val (initCode, error) = c.init(initPayload(code))
-
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("no code to execute")
- }
- }
-
- it should "return some error on action error" in {
- withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | throw "nooooo";
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should not be (200)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- runRes.get.fields("error").toString.toLowerCase should include("nooooo")
- }
- }
-
- it should "support application errors" in {
- withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | return { "error" : "sorry" };
- | }
- """.stripMargin;
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
- }
-
- it should "support the documentation examples (1)" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | // an action in which each path results in a synchronous activation
- | function main(params) {
- | if (params.payload == 0) {
- | return;
- | } else if (params.payload == 1) {
- | return {payload: 'Hello, World!'} // indicates normal completion
- | } else if (params.payload == 2) {
- | return {error: 'payload must be 0 or 1'} // indicates abnormal completion
- | }
- | }
- """.stripMargin
-
- c.init(initPayload(code))._1 should be(200)
-
- val (c1, r1) = c.run(runPayload(JsObject("payload" -> JsNumber(0))))
- val (c2, r2) = c.run(runPayload(JsObject("payload" -> JsNumber(1))))
- val (c3, r3) = c.run(runPayload(JsObject("payload" -> JsNumber(2))))
-
- c1 should be(200)
- r1 should be(Some(JsObject()))
-
- c2 should be(200)
- r2 should be(Some(JsObject("payload" -> JsString("Hello, World!"))))
-
- c3 should be(200) // application error, not container or system
- r3.get.fields.get("error") shouldBe Some(JsString("payload must be 0 or 1"))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- }, 3)
-
- }
-
- it should "support the documentation examples (2)" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(params) {
- | if (params.payload) {
- | // asynchronous activation
- | return new Promise(function(resolve, reject) {
- | setTimeout(function() {
- | resolve({ done: true });
- | }, 100);
- | })
- | } else {
- | // synchronous activation
- | return {done: true};
- | }
- | }
- """.stripMargin
-
- c.init(initPayload(code))._1 should be(200)
-
- val (c1, r1) = c.run(runPayload(JsObject()))
- val (c2, r2) = c.run(runPayload(JsObject("payload" -> JsBoolean(true))))
-
- c1 should be(200)
- r1 should be(Some(JsObject("done" -> JsBoolean(true))))
-
- c2 should be(200)
- r2 should be(Some(JsObject("done" -> JsBoolean(true))))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- }, 2)
- }
-
- it should "error when requiring a non-existent package" in {
- // NPM package names cannot start with a dot, and so there is no danger
- // of the package below ever being valid.
- // https://docs.npmjs.com/files/package.json
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | require('.mildlyinvalidnameofanonexistentpackage');
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should be(200)
-
- val (runCode, out) = c.run(runPayload(JsObject()))
-
- runCode should not be (200)
- }
-
- // Somewhere, the logs should mention an error occurred.
- checkStreams(out, err, {
- case (o, e) => (o + e) should include("MODULE_NOT_FOUND")
- })
- }
-
- it should "have openwhisk package available" in {
- // GIVEN that it should "error when requiring a non-existent package" (see test above for this)
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | require('openwhisk');
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should be(200)
-
- // WHEN I run an action that requires ws and socket.io.client
- val (runCode, out) = c.run(runPayload(JsObject()))
-
- // THEN it should pass only when these packages are available
- runCode should be(200)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support resolved promises" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | return new Promise(function(resolve, reject) {
- | setTimeout(function() {
- | resolve({ done: true });
- | }, 100);
- | })
- | }
- """.stripMargin
-
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200)
- runRes should be(Some(JsObject("done" -> JsBoolean(true))))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support rejected promises" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | return new Promise(function(resolve, reject) {
- | setTimeout(function() {
- | reject({ done: true });
- | }, 100);
- | })
- | }
- """.stripMargin
-
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("error") shouldBe defined
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support rejected promises with no message" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | return new Promise(function (resolve, reject) {
- | reject();
- | });
- | }""".stripMargin
-
- c.init(initPayload(code))._1 should be(200)
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("error") shouldBe defined
- }
- }
-
- it should "support large-ish actions" in {
- val thought = " I took the one less traveled by, and that has made all the difference."
- val assignment = " x = \"" + thought + "\";\n"
-
- val code = """
- | function main(args) {
- | var x = "hello";
- """.stripMargin + (assignment * 7000) + """
- | x = "world";
- | return { "message" : x };
- | }
- """.stripMargin
-
- // Lest someone should make it too easy.
- code.length should be >= 500000
-
- val (out, err) = withNodeJsContainer { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("message") shouldBe Some(JsString("world"))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- val examplePackageDotJson: String = """
- | {
- | "name": "wskaction",
- | "version": "1.0.0",
- | "description": "An OpenWhisk action as an npm package.",
- | "main": "index.js",
- | "author": "info@openwhisk.org",
- | "license": "Apache-2.0"
- | }
- """.stripMargin
-
- it should "support zip-encoded npm package actions" in {
- val srcs = Seq(
- Seq("package.json") -> examplePackageDotJson,
- Seq("index.js") -> """
- | exports.main = function (args) {
- | var name = typeof args["name"] === "string" ? args["name"] : "stranger";
- |
- | return {
- | greeting: "Hello " + name + ", from an npm package action."
- | };
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withNodeJsContainer { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("greeting") shouldBe Some(JsString("Hello stranger, from an npm package action."))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support zip-encoded npm package actions without a package.json file" in {
- val srcs = Seq(
- Seq("index.js") -> """
- | exports.main = function (args) {
- | var name = typeof args["name"] === "string" ? args["name"] : "stranger";
- |
- | return {
- | greeting: "Hello " + name + ", from an npm package action without a package.json."
- | };
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withNodeJsContainer { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("greeting") shouldBe Some(
- JsString("Hello stranger, from an npm package action without a package.json."))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "fail gracefully on invalid zip files" in {
- // Some text-file encoded to base64.
- val code = "Q2VjaSBuJ2VzdCBwYXMgdW4gemlwLgo="
-
- val (out, err) = withNodeJsContainer { c =>
- c.init(initPayload(code))._1 should not be (200)
- }
-
- // Somewhere, the logs should mention the connection to the archive.
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("uncompressing")
- })
- }
-
- it should "fail gracefully on valid zip files that are not actions" in {
- val srcs = Seq(Seq("hello") -> """
- | Hello world!
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withNodeJsContainer { c =>
- c.init(initPayload(code))._1 should not be (200)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("zipped actions must contain either package.json or index.js at the root.")
- })
- }
-
- it should "support actions using non-default entry point" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function niam(args) {
- | return { result: "it works" };
- | }
- """.stripMargin
-
- c.init(initPayload(code, main = "niam"))._1 should be(200)
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
- it should "support zipped actions using non-default entry point" in {
- val srcs = Seq(
- Seq("package.json") -> examplePackageDotJson,
- Seq("index.js") -> """
- | exports.niam = function (args) {
- | return { result: "it works" };
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- withNodeJsContainer { c =>
- c.init(initPayload(code, main = "niam"))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
- it should "support default function parameters" in {
- val (out, err) = withNodeJsContainer { c =>
- val code = """
- | function main(args) {
- | let foo = 3;
- | return {isValid: (function (a, b = 2) {return a === 3 && b === 2;}(foo))};
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200)
- runRes should be(Some(JsObject("isValid" -> JsBoolean(true))))
-
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-}
diff --git a/tests/src/test/scala/actionContainers/Php71ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Php71ActionContainerTests.scala
deleted file mode 100644
index 4653dc0..0000000
--- a/tests/src/test/scala/actionContainers/Php71ActionContainerTests.scala
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import ActionContainer.withContainer
-import ResourceHelpers.ZipBuilder
-
-import common.WskActorSystem
-import spray.json._
-
-@RunWith(classOf[JUnitRunner])
-class Php71ActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
- // note: "out" will not be empty as the PHP web server outputs a message when
- // it starts up
- val enforceEmptyOutputStream = false
-
- lazy val php71ContainerImageName = "action-php-v7.1"
-
- override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
- withContainer(php71ContainerImageName, env)(code)
- }
-
- def withPhp71Container(code: ActionContainer => Unit) = withActionContainer()(code)
-
- behavior of php71ContainerImageName
-
- testEcho(Seq {
- (
- "PHP",
- """
- |<?php
- |function main(array $args) : array {
- | echo 'hello stdout';
- | error_log('hello stderr');
- | return $args;
- |}
- """.stripMargin)
- })
-
- testNotReturningJson("""
- |<?php
- |function main(array $args) {
- | return "not a json object";
- |}
- """.stripMargin)
-
- testUnicode(Seq {
- (
- "PHP",
- """
- |<?php
- |function main(array $args) : array {
- | $str = $args['delimiter'] . " ☃ " . $args['delimiter'];
- | echo $str . "\n";
- | return ["winter" => $str];
- |}
- """.stripMargin.trim)
- })
-
- testEnv(
- Seq {
- (
- "PHP",
- """
- |<?php
- |function main(array $args) : array {
- | return [
- | "env" => $_ENV,
- | "api_host" => $_ENV['__OW_API_HOST'],
- | "api_key" => $_ENV['__OW_API_KEY'],
- | "namespace" => $_ENV['__OW_NAMESPACE'],
- | "action_name" => $_ENV['__OW_ACTION_NAME'],
- | "activation_id" => $_ENV['__OW_ACTIVATION_ID'],
- | "deadline" => $_ENV['__OW_DEADLINE'],
- | ];
- |}
- """.stripMargin.trim)
- },
- enforceEmptyOutputStream)
-
- it should "fail to initialize with bad code" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- |<?php
- | 10 PRINT "Hello world!"
- | 20 GOTO 10
- """.stripMargin
-
- val (initCode, error) = c.init(initPayload(code))
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("PHP syntax error")
- }
-
- // Somewhere, the logs should mention an error occurred.
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("syntax")
- })
- }
-
- it should "fail to initialize with no code" in {
- val (out, err) = withPhp71Container { c =>
- val code = ""
-
- val (initCode, error) = c.init(initPayload(code))
-
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("No code to execute")
- }
- }
-
- it should "return some error on action error" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- |<?php
- | function main(array $args) : array {
- | throw new Exception ("nooooo");
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should not be (200)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- // runRes.get.fields("error").toString.toLowerCase should include("nooooo")
- }
-
- // Somewhere, the logs should be the error text
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("nooooo")
- })
-
- }
-
- it should "support application errors" in {
- withPhp71Container { c =>
- val code = """
- |<?php
- | function main(array $args) : array {
- | return [ "error" => "sorry" ];
- | }
- """.stripMargin;
-
- val (initCode, error) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- runRes.get.fields("error").toString.toLowerCase should include("sorry")
- }
- }
-
- it should "fail gracefully when an action has a fatal error" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | function main(array $args) : array {
- | eval("class Error {};");
- | return [ "hello" => "world" ];
- | }
- """.stripMargin;
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(502)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- runRes.get.fields("error").toString should include("An error occurred running the action.")
- }
-
- // Somewhere, the logs should be the error text
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("fatal error")
- })
- }
-
- it should "suport returning a stdClass" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | function main($params) {
- | $obj = new stdClass();
- | $obj->hello = 'world';
- | return $obj;
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("hello") shouldBe defined
- runRes.get.fields("hello").toString.toLowerCase should include("world")
- }
- }
-
- it should "support returning an object with a getArrayCopy() method" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | function main($params) {
- | $obj = new ArrayObject();
- | $obj['hello'] = 'world';
- | return $obj;
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes.get.fields.get("hello") shouldBe defined
- runRes.get.fields.get("hello") shouldBe Some(JsString("world"))
- }
- }
-
- it should "support the documentation examples (1)" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | function main($params) {
- | if ($params['payload'] == 0) {
- | return;
- | } else if ($params['payload'] == 1) {
- | return ['payload' => 'Hello, World!'] ; // indicates normal completion
- | } else if ($params['payload'] == 2) {
- | return ['error' => 'payload must be 0 or 1']; // indicates abnormal completion
- | }
- | }
- """.stripMargin
-
- c.init(initPayload(code))._1 should be(200)
-
- val (c1, r1) = c.run(runPayload(JsObject("payload" -> JsNumber(0))))
- val (c2, r2) = c.run(runPayload(JsObject("payload" -> JsNumber(1))))
- val (c3, r3) = c.run(runPayload(JsObject("payload" -> JsNumber(2))))
-
- c1 should be(200)
- r1 should be(Some(JsObject()))
-
- c2 should be(200)
- r2 should be(Some(JsObject("payload" -> JsString("Hello, World!"))))
-
- c3 should be(200) // application error, not container or system
- r3.get.fields.get("error") shouldBe Some(JsString("payload must be 0 or 1"))
- }
- }
-
- it should "have Guzzle and Uuid packages available" in {
- // GIVEN that it should "error when requiring a non-existent package" (see test above for this)
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | use Ramsey\Uuid\Uuid;
- | use GuzzleHttp\Client;
- | function main(array $args) {
- | Uuid::uuid4();
- | new Client();
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should be(200)
-
- // WHEN I run an action that calls a Guzzle & a Uuid method
- val (runCode, out) = c.run(runPayload(JsObject()))
-
- // THEN it should pass only when these packages are available
- runCode should be(200)
- }
- }
-
- it should "support large-ish actions" in {
- val thought = " I took the one less traveled by, and that has made all the difference."
- val assignment = " $x = \"" + thought + "\";\n"
-
- val code = """
- | <?php
- | function main(array $args) {
- | $x = "hello";
- """.stripMargin + (assignment * 7000) + """
- | $x = "world";
- | return [ "message" => $x ];
- | }
- """.stripMargin
-
- // Lest someone should make it too easy.
- code.length should be >= 500000
-
- val (out, err) = withPhp71Container { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("message") shouldBe defined
- runRes.get.fields.get("message") shouldBe Some(JsString("world"))
- }
- }
-
- val exampleOutputDotPhp: String = """
- | <?php
- | function output($data) {
- | return ['result' => $data];
- | }
- """.stripMargin
-
- it should "support zip-encoded packages" in {
- val srcs = Seq(
- Seq("output.php") -> exampleOutputDotPhp,
- Seq("index.php") -> """
- | <?php
- | require __DIR__ . '/output.php';
- | function main(array $args) {
- | $name = $args['name'] ?? 'stranger';
- | return output($name);
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withPhp71Container { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("result") shouldBe defined
- runRes.get.fields.get("result") shouldBe Some(JsString("stranger"))
- }
- }
-
- it should "support replacing vendor in zip-encoded packages " in {
- val srcs = Seq(
- Seq("vendor/autoload.php") -> exampleOutputDotPhp,
- Seq("index.php") -> """
- | <?php
- | function main(array $args) {
- | $name = $args['name'] ?? 'stranger';
- | return output($name);
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withPhp71Container { c =>
- c.init(initPayload(code))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
-
- runCode should be(200)
- runRes.get.fields.get("result") shouldBe defined
- runRes.get.fields.get("result") shouldBe Some(JsString("stranger"))
- }
- }
-
- it should "fail gracefully on invalid zip files" in {
- // Some text-file encoded to base64.
- val code = "Q2VjaSBuJ2VzdCBwYXMgdW4gemlwLgo="
-
- val (out, err) = withPhp71Container { c =>
- val (initCode, error) = c.init(initPayload(code))
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("Failed to open zip file")
- }
-
- // Somewhere, the logs should mention the failure
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("failed to open zip file")
- })
- }
-
- it should "fail gracefully on valid zip files that are not actions" in {
- val srcs = Seq(Seq("hello") -> """
- | Hello world!
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withPhp71Container { c =>
- c.init(initPayload(code))._1 should not be (200)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("zipped actions must contain index.php at the root.")
- })
- }
-
- it should "fail gracefully on valid zip files with invalid code in index.php" in {
- val (out, err) = withPhp71Container { c =>
- val srcs = Seq(Seq("index.php") -> """
- | <?php
- | 10 PRINT "Hello world!"
- | 20 GOTO 10
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (initCode, error) = c.init(initPayload(code))
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("PHP syntax error in index.php")
- }
-
- // Somewhere, the logs should mention an error occurred.
- checkStreams(out, err, {
- case (o, e) =>
- (o + e).toLowerCase should include("error")
- (o + e).toLowerCase should include("syntax")
- })
- }
-
- it should "support actions using non-default entry point" in {
- val (out, err) = withPhp71Container { c =>
- val code = """
- | <?php
- | function niam(array $args) {
- | return [result => "it works"];
- | }
- """.stripMargin
-
- c.init(initPayload(code, main = "niam"))._1 should be(200)
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
- it should "support zipped actions using non-default entry point" in {
- val srcs = Seq(Seq("index.php") -> """
- | <?php
- | function niam(array $args) {
- | return [result => "it works"];
- | }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- withPhp71Container { c =>
- c.init(initPayload(code, main = "niam"))._1 should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-}
diff --git a/tests/src/test/scala/actionContainers/Python2ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Python2ActionContainerTests.scala
deleted file mode 100644
index 1740401..0000000
--- a/tests/src/test/scala/actionContainers/Python2ActionContainerTests.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-import common.WskActorSystem
-
-@RunWith(classOf[JUnitRunner])
-class Python2ActionContainerTests extends PythonActionContainerTests with WskActorSystem {
-
- override lazy val imageName = "python2action"
-
- /** indicates if strings in python are unicode by default (i.e., python3 -> true, python2.7 -> false) */
- override lazy val pythonStringAsUnicode = false
-}
diff --git a/tests/src/test/scala/actionContainers/PythonActionContainerTests.scala b/tests/src/test/scala/actionContainers/PythonActionContainerTests.scala
deleted file mode 100644
index cb880be..0000000
--- a/tests/src/test/scala/actionContainers/PythonActionContainerTests.scala
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-import ActionContainer.withContainer
-import ResourceHelpers.{readAsBase64, ZipBuilder}
-import spray.json.DefaultJsonProtocol._
-import spray.json._
-import common.WskActorSystem
-import common.TestUtils
-import java.nio.file.Paths
-
-@RunWith(classOf[JUnitRunner])
-class PythonActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
-
- lazy val imageName = "python3action"
-
- /** indicates if strings in python are unicode by default (i.e., python3 -> true, python2.7 -> false) */
- lazy val pythonStringAsUnicode = true
-
- override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
- withContainer(imageName, env)(code)
- }
-
- behavior of imageName
-
- testNotReturningJson(
- """
- |def main(args):
- | return "not a json object"
- """.stripMargin,
- checkResultInLogs = false)
-
- testEcho(Seq {
- (
- "python",
- """
- |from __future__ import print_function
- |import sys
- |def main(args):
- | print('hello stdout')
- | print('hello stderr', file=sys.stderr)
- | return args
- """.stripMargin)
- })
-
- testUnicode(Seq {
- if (pythonStringAsUnicode) {
- (
- "python",
- """
- |def main(args):
- | sep = args['delimiter']
- | str = sep + " ☃ " + sep
- | print(str)
- | return {"winter" : str }
- """.stripMargin.trim)
- } else {
- (
- "python",
- """
- |def main(args):
- | sep = args['delimiter']
- | str = sep + " ☃ ".decode('utf-8') + sep
- | print(str.encode('utf-8'))
- | return {"winter" : str }
- """.stripMargin.trim)
- }
- })
-
- testEnv(Seq {
- (
- "python",
- """
- |import os
- |def main(dict):
- | return {
- | "api_host": os.environ['__OW_API_HOST'],
- | "api_key": os.environ['__OW_API_KEY'],
- | "namespace": os.environ['__OW_NAMESPACE'],
- | "action_name": os.environ['__OW_ACTION_NAME'],
- | "activation_id": os.environ['__OW_ACTIVATION_ID'],
- | "deadline": os.environ['__OW_DEADLINE']
- | }
- """.stripMargin.trim)
- })
-
- it should "support actions using non-default entry points" in {
- withActionContainer() { c =>
- val code = """
- |def niam(dict):
- | return { "result": "it works" }
- |""".stripMargin
-
- val (initCode, initRes) = c.init(initPayload(code, main = "niam"))
- initCode should be(200)
-
- val (_, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
- it should "support zip-encoded action using non-default entry points" in {
- val srcs = Seq(
- Seq("__main__.py") -> """
- |from echo import echo
- |def niam(args):
- | return echo(args)
- """.stripMargin,
- Seq("echo.py") -> """
- |def echo(args):
- | return { "echo": args }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "niam"))
- initCode should be(200)
-
- val args = JsObject("msg" -> JsString("it works"))
- val (runCode, runRes) = c.run(runPayload(args))
-
- runCode should be(200)
- runRes.get.fields.get("echo") shouldBe Some(args)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support zip-encoded action which can read from relative paths" in {
- val srcs = Seq(
- Seq("__main__.py") -> """
- |def main(args):
- | f = open('workfile', 'r')
- | return {'file': f.read()}
- """.stripMargin,
- Seq("workfile") -> "this is a test string")
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code))
- initCode should be(200)
-
- val args = JsObject()
- val (runCode, runRes) = c.run(runPayload(args))
-
- runCode should be(200)
- runRes.get.fields.get("file") shouldBe Some("this is a test string".toJson)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "report error if zip-encoded action does not include required file" in {
- val srcs = Seq(Seq("echo.py") -> """
- |def echo(args):
- | return { "echo": args }
- """.stripMargin)
-
- val code = ZipBuilder.mkBase64Zip(srcs)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "echo"))
- initCode should be(502)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Zip file does not include")
- })
- }
-
- it should "run zipped Python action containing a virtual environment" in {
- val zippedPythonAction = if (imageName == "python2action") "python2_virtualenv.zip" else "python3_virtualenv.zip"
- val zippedPythonActionName = TestUtils.getTestActionFilename(zippedPythonAction)
- val code = readAsBase64(Paths.get(zippedPythonActionName))
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "main"))
- initCode should be(200)
- val args = JsObject("msg" -> JsString("any"))
- val (runCode, runRes) = c.run(runPayload(args))
- runCode should be(200)
- runRes.get.toString() should include("netmask")
- }
- checkStreams(out, err, {
- case (o, e) =>
- o should include("netmask")
- e shouldBe empty
- })
- }
-
- it should "run zipped Python action containing a virtual environment with non-standard entry point" in {
- val zippedPythonAction = if (imageName == "python2action") "python2_virtualenv.zip" else "python3_virtualenv.zip"
- val zippedPythonActionName = TestUtils.getTestActionFilename(zippedPythonAction)
- val code = readAsBase64(Paths.get(zippedPythonActionName))
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "naim"))
- initCode should be(200)
- val args = JsObject("msg" -> JsString("any"))
- val (runCode, runRes) = c.run(runPayload(args))
- runCode should be(200)
- runRes.get.toString() should include("netmask")
- }
- checkStreams(out, err, {
- case (o, e) =>
- o should include("netmask")
- e shouldBe empty
- })
- }
-
- it should "report error if zipped Python action containing a virtual environment for wrong python version" in {
- val zippedPythonAction = if (imageName == "python3action") "python2_virtualenv.zip" else "python3_virtualenv.zip"
- val zippedPythonActionName = TestUtils.getTestActionFilename(zippedPythonAction)
- val code = readAsBase64(Paths.get(zippedPythonActionName))
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "main"))
- initCode should be(200)
- val args = JsObject("msg" -> JsString("any"))
- val (runCode, runRes) = c.run(runPayload(args))
- runCode should be(502)
- }
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- if (imageName == "python2action") { e should include("ImportError") }
- if (imageName == "python3action") { e should include("ModuleNotFoundError") }
- })
- }
-
- it should "report error if zipped Python action has wrong main module name" in {
- val zippedPythonActionWrongName = TestUtils.getTestActionFilename("python_virtualenv_name.zip")
-
- val code = readAsBase64(Paths.get(zippedPythonActionWrongName))
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "main"))
- initCode should be(502)
- }
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Zip file does not include __main__.py")
- })
- }
-
- it should "report error if zipped Python action has invalid virtualenv directory" in {
- val zippedPythonActionWrongDir = TestUtils.getTestActionFilename("python_virtualenv_dir.zip")
-
- val code = readAsBase64(Paths.get(zippedPythonActionWrongDir))
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code, main = "main"))
- initCode should be(502)
- }
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Zip file does not include /virtualenv/bin/")
- })
- }
-
- it should "return on action error when action fails" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- |def div(x, y):
- | return x/y
- |
- |def main(dict):
- | return {"divBy0": div(5,0)}
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(502)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Traceback")
- })
- }
-
- it should "log compilation errors" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- | 10 PRINT "Hello!"
- | 20 GOTO 10
- """.stripMargin
-
- val (initCode, res) = c.init(initPayload(code))
- // init checks whether compilation was successful, so return 502
- initCode should be(502)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Traceback")
- })
- }
-
- it should "support application errors" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- |def main(args):
- | return { "error": "sorry" }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes should be(Some(JsObject("error" -> JsString("sorry"))))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "error when importing a not-supported package" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- |import iamnotsupported
- |def main(args):
- | return { "error": "not reaching here" }
- """.stripMargin
-
- val (initCode, res) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(502)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- o shouldBe empty
- e should include("Traceback")
- })
- }
-}
diff --git a/tests/src/test/scala/actionContainers/Swift311ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Swift311ActionContainerTests.scala
deleted file mode 100644
index 24e0dc1..0000000
--- a/tests/src/test/scala/actionContainers/Swift311ActionContainerTests.scala
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package actionContainers
-
-import java.io.File
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import ActionContainer.withContainer
-import common.WskActorSystem
-import spray.json.JsObject
-import spray.json.JsString
-import common.TestUtils
-
-@RunWith(classOf[JUnitRunner])
-class Swift311ActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
-
- // note: "out" will likely not be empty in some swift build as the compiler
- // prints status messages and there doesn't seem to be a way to quiet them
- val enforceEmptyOutputStream = false
- lazy val swiftContainerImageName = "action-swift-v3.1.1"
- lazy val envCode = makeEnvCode("ProcessInfo.processInfo")
-
- def makeEnvCode(processInfo: String) = ("""
- |func main(args: [String: Any]) -> [String: Any] {
- | let env = """ + processInfo + """.environment
- | var a = "???"
- | var b = "???"
- | var c = "???"
- | var d = "???"
- | var e = "???"
- | var f = "???"
- | if let v : String = env["__OW_API_HOST"] {
- | a = "\(v)"
- | }
- | if let v : String = env["__OW_API_KEY"] {
- | b = "\(v)"
- | }
- | if let v : String = env["__OW_NAMESPACE"] {
- | c = "\(v)"
- | }
- | if let v : String = env["__OW_ACTION_NAME"] {
- | d = "\(v)"
- | }
- | if let v : String = env["__OW_ACTIVATION_ID"] {
- | e = "\(v)"
- | }
- | if let v : String = env["__OW_DEADLINE"] {
- | f = "\(v)"
- | }
- | return ["api_host": a, "api_key": b, "namespace": c, "action_name": d, "activation_id": e, "deadline": f]
- |}
- """).stripMargin
-
- lazy val errorCode = """
- | // You need an indirection, or swiftc detects the div/0
- | // at compile-time. Smart.
- | func div(x: Int, y: Int) -> Int {
- | return x/y
- | }
- | func main(args: [String: Any]) -> [String: Any] {
- | return [ "divBy0": div(x:5, y:0) ]
- | }
- """.stripMargin
- lazy val watsonCode = """
- | import AlchemyDataNewsV1
- | import ConversationV1
- | import DiscoveryV1
- | import DocumentConversionV1
- | import NaturalLanguageClassifierV1
- | import NaturalLanguageUnderstandingV1
- | import PersonalityInsightsV3
- | import RetrieveAndRankV1
- | import ToneAnalyzerV3
- | import TradeoffAnalyticsV1
- | import VisualRecognitionV3
- |
- | func main(args: [String:Any]) -> [String:Any] {
- | return ["message": "I compiled and was able to import Watson SDKs"]
- | }
- """.stripMargin
- lazy val swiftBinaryName = "helloSwift311.zip"
-
- // Helpers specific to swift actions
- override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
- withContainer(swiftContainerImageName, env)(code)
- }
-
- behavior of swiftContainerImageName
-
- // remove this test: it will not even compile under Swift 3 anymore
- // so it should not be possible to write an action that does not return
- // a [String:Any]
- /*testNotReturningJson(
- """
- |func main(args: [String: Any]) -> String {
- | return "not a json object"
- |}
- """.stripMargin)
- */
-
- testEcho(Seq {
- (
- "swift",
- """
- | import Foundation
- |
- | extension FileHandle : TextOutputStream {
- | public func write(_ string: String) {
- | guard let data = string.data(using: .utf8) else { return }
- | self.write(data)
- | }
- | }
- |
- | func main(args: [String: Any]) -> [String: Any] {
- | print("hello stdout")
- | var standardError = FileHandle.standardError
- | print("hello stderr", to: &standardError)
- | return args
- | }
- """.stripMargin)
- })
-
- testUnicode(Seq {
- (
- "swift",
- """
- | func main(args: [String: Any]) -> [String: Any] {
- | if let str = args["delimiter"] as? String {
- | let msg = "\(str) ☃ \(str)"
- | print(msg)
- | return [ "winter" : msg ]
- | } else {
- | return [ "error" : "no delimiter" ]
- | }
- | }
- """.stripMargin.trim)
- })
-
- testEnv(Seq {
- ("swift", envCode)
- }, enforceEmptyOutputStream)
-
- it should "support actions using non-default entry points" in {
- withActionContainer() { c =>
- val code = """
- | func niam(args: [String: Any]) -> [String: Any] {
- | return [ "result": "it works" ]
- | }
- |""".stripMargin
-
- val (initCode, initRes) = c.init(initPayload(code, main = "niam"))
- initCode should be(200)
-
- val (_, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
- it should "return some error on action error" in {
- val (out, err) = withActionContainer() { c =>
- val code = errorCode
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(502)
-
- runRes shouldBe defined
- runRes.get.fields.get("error") shouldBe defined
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "log compilation errors" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- | 10 PRINT "Hello!"
- | 20 GOTO 10
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should not be (200)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e.toLowerCase should include("error")
- })
- }
-
- it should "support application errors" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- | func main(args: [String: Any]) -> [String: Any] {
- | return [ "error": "sorry" ]
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
- initCode should be(200)
-
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runCode should be(200) // action writer returning an error is OK
-
- runRes shouldBe defined
- runRes should be(Some(JsObject("error" -> JsString("sorry"))))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support support multiple files in a zip file" in {
- val zip = new File(TestUtils.getTestActionFilename("multiSwift.zip")).toPath
- val code = ResourceHelpers.readAsBase64(zip)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code))
- initCode should be(200)
-
- val args = JsObject()
- val (runCode, runRes) = c.run(runPayload(args))
-
- runCode should be(200)
- runRes.get shouldBe JsObject("greeting" -> (JsString("Hello stranger!")))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "support pre-compiled binary in a zip file" in {
- val zip = new File(TestUtils.getTestActionFilename(swiftBinaryName)).toPath
- val code = ResourceHelpers.readAsBase64(zip)
-
- val (out, err) = withActionContainer() { c =>
- val (initCode, initRes) = c.init(initPayload(code))
- initCode should be(200)
-
- val args = JsObject()
- val (runCode, runRes) = c.run(runPayload(args))
-
- runCode should be(200)
- runRes.get shouldBe JsObject("greeting" -> (JsString("Hello stranger!")))
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "properly use KituraNet and Dispatch" in {
- val (out, err) = withActionContainer() { c =>
- val code = """
- | import KituraNet
- | import Foundation
- | import Dispatch
- | func main(args:[String: Any]) -> [String:Any] {
- | let retries = 3
- | var resp = [String:Any]()
- | var attempts = 0
- | if let url = args["getUrl"] as? String {
- | while attempts < retries {
- | let group = DispatchGroup()
- | let queue = DispatchQueue.global(qos: .default)
- | group.enter()
- | queue.async {
- | HTTP.get(url, callback: { response in
- | if let response = response {
- | do {
- | var jsonData = Data()
- | try response.readAllData(into: &jsonData)
- | if let dic = WhiskJsonUtils.jsonDataToDictionary(jsonData: jsonData) {
- | resp = dic
- | } else {
- | resp = ["error":"response from server is not JSON"]
- | }
- | } catch {
- | resp["error"] = error.localizedDescription
- | }
- | }
- | group.leave()
- | })
- | }
- | switch group.wait(timeout: DispatchTime.distantFuture) {
- | case DispatchTimeoutResult.success:
- | resp["attempts"] = attempts
- | return resp
- | case DispatchTimeoutResult.timedOut:
- | attempts = attempts + 1
- | }
- | }
- | }
- | return ["status":"Exceeded \(retries) attempts, aborting."]
- | }
- """.stripMargin
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should be(200)
-
- val argss = List(JsObject("getUrl" -> JsString("https://openwhisk.ng.bluemix.net/api/v1")))
-
- for (args <- argss) {
- val (runCode, out) = c.run(runPayload(args))
- runCode should be(200)
- }
- }
-
- // in side try catch finally print (out file)
- // in catch block an error has occurred, get docker logs and print
- // throw
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-
- it should "make Watson SDKs available to action authors" in {
- val (out, err) = withActionContainer() { c =>
- val code = watsonCode
-
- val (initCode, _) = c.init(initPayload(code))
-
- initCode should be(200)
-
- val (runCode, out) = c.run(runPayload(JsObject()))
- runCode should be(200)
- }
-
- checkStreams(out, err, {
- case (o, e) =>
- if (enforceEmptyOutputStream) o shouldBe empty
- e shouldBe empty
- })
- }
-}
--
To stop receiving notification emails like this one, please contact
csantanapr@apache.org.