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 2018/07/06 12:50:31 UTC
[incubator-openwhisk-runtime-swift] 02/02: Update tests.
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/incubator-openwhisk-runtime-swift.git
commit 07763c243e7d91e987b5a0fc2174ac7274923ba7
Author: Rodric Rabbah <ro...@gmail.com>
AuthorDate: Thu Jul 5 21:02:34 2018 -0400
Update tests.
---
.../SwiftActionContainerTests.scala | 139 ++-------------------
.../SwiftCodableActionContainerTests.scala | 5 +-
.../src/test/scala/runtime/sdk/SwiftSDKTests.scala | 9 +-
3 files changed, 18 insertions(+), 135 deletions(-)
diff --git a/tests/src/test/scala/runtime/actionContainers/SwiftActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/SwiftActionContainerTests.scala
index 1ba70b0..8087b77 100644
--- a/tests/src/test/scala/runtime/actionContainers/SwiftActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/SwiftActionContainerTests.scala
@@ -19,9 +19,9 @@ package runtime.actionContainers
import java.io.File
import common.WskActorSystem
-import actionContainers.{ActionContainer, ActionProxyContainerTestUtils, ResourceHelpers}
+import actionContainers.{ActionContainer, BasicActionRunnerTests}
import actionContainers.ActionContainer.withContainer
-import spray.json.DefaultJsonProtocol._
+import actionContainers.ResourceHelpers.readAsBase64
import spray.json._
abstract class SwiftActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
@@ -35,6 +35,8 @@ abstract class SwiftActionContainerTests extends BasicActionRunnerTests with Wsk
behavior of swiftContainerImageName
+ //testNoSourceOrExec(checkResultInLogs = false)
+
testEcho(Seq {
(
"swift echo",
@@ -110,6 +112,12 @@ abstract class SwiftActionContainerTests extends BasicActionRunnerTests with Wsk
},
enforceEmptyOutputStream)
+ testInitCannotBeCalledMoreThanOnce("""
+ | func main(args: [String: Any]) -> [String: Any] {
+ | return args
+ | }
+ """.stripMargin)
+
it should "support actions using non-default entry points" in {
withActionContainer() { c =>
val code = """
@@ -201,7 +209,7 @@ abstract class SwiftActionContainerTests extends BasicActionRunnerTests with Wsk
it should "support pre-compiled binary in a zip file" in {
val zip = new File(swiftBinaryName).toPath
- val code = ResourceHelpers.readAsBase64(zip)
+ val code = readAsBase64(zip)
val (out, err) = withActionContainer() { c =>
val (initCode, initRes) = c.init(initPayload(code))
@@ -252,128 +260,3 @@ abstract class SwiftActionContainerTests extends BasicActionRunnerTests with Wsk
}
}
-
-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
- })
- }
- }
-
- }
-}
diff --git a/tests/src/test/scala/runtime/actionContainers/SwiftCodableActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/SwiftCodableActionContainerTests.scala
index cf60026..fc64f37 100644
--- a/tests/src/test/scala/runtime/actionContainers/SwiftCodableActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/SwiftCodableActionContainerTests.scala
@@ -19,8 +19,9 @@ package runtime.actionContainers
import java.io.File
import common.WskActorSystem
-import actionContainers.{ActionContainer, ResourceHelpers}
+import actionContainers.{ActionContainer, BasicActionRunnerTests}
import actionContainers.ActionContainer.withContainer
+import actionContainers.ResourceHelpers.readAsBase64
import spray.json._
abstract class SwiftCodableActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
@@ -213,7 +214,7 @@ abstract class SwiftCodableActionContainerTests extends BasicActionRunnerTests w
it should "support pre-compiled binary in a zip file" in {
val zip = new File(swiftBinaryName).toPath
- val code = ResourceHelpers.readAsBase64(zip)
+ val code = readAsBase64(zip)
val (out, err) = withActionContainer() { c =>
val (initCode, initRes) = c.init(initPayload(code))
diff --git a/tests/src/test/scala/runtime/sdk/SwiftSDKTests.scala b/tests/src/test/scala/runtime/sdk/SwiftSDKTests.scala
index d5437db..8822e31 100644
--- a/tests/src/test/scala/runtime/sdk/SwiftSDKTests.scala
+++ b/tests/src/test/scala/runtime/sdk/SwiftSDKTests.scala
@@ -18,18 +18,17 @@
package runtime.sdk
import java.io.File
+
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
-import org.scalatest.Matchers
-import common.{TestHelpers, WhiskProperties, WskProps, WskTestHelpers}
-import common.rest.WskRest
+import common._
import spray.json._
import spray.json.DefaultJsonProtocol.StringJsonFormat
-abstract class SwiftSDKTests extends TestHelpers with WskTestHelpers with Matchers {
+abstract class SwiftSDKTests extends TestHelpers with WskTestHelpers with WskActorSystem {
implicit val wskprops = WskProps()
- val wsk = new WskRest
+ val wsk = new Wsk
val activationPollDuration = 2.minutes
lazy val actionKind = "swift:3.1.1"
lazy val lang = actionKind.split(":")(0)