dgrove-oss closed pull request #3844: Add test for empty initializer. Document
other tests.
URL: https://github.com/apache/incubator-openwhisk/pull/3844
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
b/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
index 3d85fa09f4..cb36472468 100644
--- a/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
+++ b/tests/src/test/scala/actionContainers/BasicActionRunnerTests.scala
@@ -19,7 +19,6 @@ package actionContainers
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
-
import spray.json.DefaultJsonProtocol._
import spray.json._
@@ -27,6 +26,19 @@ import spray.json._
trait BasicActionRunnerTests extends ActionProxyContainerTestUtils {
def withActionContainer(env: Map[String, String] = Map.empty)(code:
ActionContainer => Unit): (String, String)
+ /**
+ * Runs tests for actions which receive an empty initializer (no source or
exec).
+ */
+ def testNoSourceOrExec() = {
+ it should "report an error when no code is present for initialization" in {
+ val (out, err) = withActionContainer() { c =>
+ val (initCode, out) = c.init(initPayload(""))
+ initCode should not be (200)
+ out should be(Some(JsObject("error" -> JsString("The action did not
initialize."))))
+ }
+ }
+ }
+
/**
* 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
@@ -55,8 +67,10 @@ trait BasicActionRunnerTests extends
ActionProxyContainerTestUtils {
}
/**
- * Runs tests for code samples which are expected to echo the input arguments
- * and print hello [stdout, stderr].
+ * Tests the echo action for different input parameters.
+ * The test actions must also print hello [stdout, stderr] to the respective
streams.
+ * @param stdCodeSamples a sequence of tuples, where each tuple provide a
test name in the first component
+ * and the identity/echo function in the second
component.
*/
def testEcho(stdCodeSamples: Seq[(String, String)]) = {
stdCodeSamples.foreach { s =>
@@ -88,6 +102,13 @@ trait BasicActionRunnerTests extends
ActionProxyContainerTestUtils {
}
}
+ /**
+ * Tests a unicode action. The action must properly handle unicode
characters in the executable,
+ * receive a unicode character, and construct a response with a unicode
character. It must also
+ * emit unicode characters correctly to stdout.
+ * @param stdUnicodeSamples a sequence of tuples, where each tuple provide a
test name in the first component
+ * a function in the second component: { delimiter
} => { winter: "❄ " + delimiter + " ❄"}
+ */
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 {
@@ -107,7 +128,21 @@ trait BasicActionRunnerTests extends
ActionProxyContainerTestUtils {
}
}
- /** Runs tests for code samples which are expected to return the expected
standard environment {auth, edge}. */
+ /**
+ * Tests the action constructs the activation context correctly.
+ *
+ * @param stdEnvSamples a sequence of tuples, where each tuple provide a
test name in the first component
+ * and a function returning the activation context
consisting of the following dictionary
+ * {
+ * "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
+ * }
+ *
+ */
def testEnv(stdEnvSamples: Seq[(String, String)],
enforceEmptyOutputStream: Boolean = true,
enforceEmptyErrorStream: Boolean = true) = {
@@ -148,7 +183,9 @@ trait BasicActionRunnerTests extends
ActionProxyContainerTestUtils {
}
/**
- * Large param samples, echo the input args with input larger than 128K and
using STDIN
+ * Tests the action to confirm it can handle a large parameter (larger than
128K) when using STDIN.
+ * @param stdLargeInputSamples a sequence of tuples, where each tuple
provide a test name in the first component
+ * and the identity/echo function in the second
component.
*/
def testLargeInput(stdLargeInputSamples: Seq[(String, String)]) = {
stdLargeInputSamples.foreach { s =>
@@ -161,31 +198,29 @@ trait BasicActionRunnerTests extends
ActionProxyContainerTestUtils {
val (_, runRes) = c.run(runPayload(arg))
runRes.get shouldBe arg
}
-
}
}
}
/**
- * Runs tests for actions which do not allow more than one initialisation
and confirms expected error messages.
- * @param code the code to execute, should be valid
+ * Tests that an action will not allow more than one initialization and
confirms expected error messages.
+ * @param code the code to execute, the identity/echo function is sufficient.
*/
def testInitCannotBeCalledMoreThanOnce(code: String) = {
it should "fail to initialize a second time" in {
+ val errorMessage = "Cannot initialize the action more than once."
val (out, err) = withActionContainer() { c =>
val (initCode1, _) = c.init(initPayload(code))
initCode1 should be(200)
val (initCode2, error2) = c.init(initPayload(code))
initCode2 should be(403)
- error2 shouldBe a[Some[_]]
- error2.get shouldBe a[JsObject]
- error2.get.fields("error").toString should include("Cannot initialize
the action more than once.")
+ error2 should be(Some(JsObject("error" -> JsString(errorMessage))))
}
checkStreams(out, err, {
case (o, e) =>
- (o + e) should include("Cannot initialize the action more than once")
+ (o + e) should include(errorMessage)
})
}
}
diff --git a/tools/build/redo b/tools/build/redo
index f40171558f..941104d3f3 100755
--- a/tools/build/redo
+++ b/tools/build/redo
@@ -274,7 +274,7 @@ Components = [
yaml = 'postdeploy.yml'),
# the following (re)build images via gradle
- makeComponent('runtime:([\w]+)',
+ makeComponent('runtime:([\w.-]+)',
'build a runtime action container, matching name using the
regex; NOTE: must use --dir for path to runtime directory',
yaml = False,
gradle = 'core:$1:distDocker'),
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services