This is an automated email from the ASF dual-hosted git repository. rabbah pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-php.git
commit 3e89f427d000c1bda97fb9dc2e42ffcfd17097f8 Author: Rodric Rabbah <[email protected]> AuthorDate: Sat Dec 14 13:34:33 2019 -0500 Add test for getenv/$_ENV equivalence. --- core/php7.3Action/Dockerfile | 18 ++++--- .../Php7ActionContainerTests.scala | 57 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/core/php7.3Action/Dockerfile b/core/php7.3Action/Dockerfile index a7663e5..d601299 100644 --- a/core/php7.3Action/Dockerfile +++ b/core/php7.3Action/Dockerfile @@ -15,14 +15,16 @@ # limitations under the License. # -FROM golang:1.11 as builder -ENV PROXY_SOURCE=https://github.com/apache/openwhisk-runtime-go/archive/[email protected] -RUN curl -L "$PROXY_SOURCE" | tar xzf - \ - && mkdir -p src/github.com/apache \ - && mv openwhisk-runtime-go-golang1.11-1.13.0-incubating \ - src/github.com/apache/incubator-openwhisk-runtime-go \ - && cd src/github.com/apache/incubator-openwhisk-runtime-go/main \ - && CGO_ENABLED=0 go build -o /bin/proxy +FROM golang:1.12 as builder +RUN env CGO_ENABLED=0 go get github.com/apache/openwhisk-runtime-go/main && mv /go/bin/main /bin/proxy +#ENV PROXY_SOURCE=https://github.com/apache/openwhisk-runtime-go/archive/[email protected] +#RUN curl -L "$PROXY_SOURCE" | tar xzf - \ +# && mkdir -p src/github.com/apache \ +# && mv openwhisk-runtime-go-golang1.11-1.13.0-incubating \ +# src/github.com/apache/incubator-openwhisk-runtime-go \ +# && cd src/github.com/apache/incubator-openwhisk-runtime-go/main \ +# && CGO_ENABLED=0 go build -o /bin/proxy + FROM php:7.3.6-cli-stretch # install dependencies diff --git a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala index 0af4983..f8446e5 100644 --- a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala +++ b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala @@ -24,6 +24,7 @@ import actionContainers.{ActionContainer, BasicActionRunnerTests} import actionContainers.ActionContainer.withContainer import actionContainers.ResourceHelpers.ZipBuilder import spray.json._ +import spray.json.DefaultJsonProtocol._ @RunWith(classOf[JUnitRunner]) abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskActorSystem { @@ -158,6 +159,62 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA } + it should s"confirm getenv can read environment variables" in { + val config = { + TestConfig( + """ + |<?php + |function main(array $args) : array { + | return [ + | "api_host" => getenv('__OW_API_HOST'), + | "api_key" => getenv('__OW_API_KEY'), + | "namespace" => getenv('__OW_NAMESPACE'), + | "action_name" => getenv('__OW_ACTION_NAME'), + | "action_version" => getenv('__OW_ACTION_VERSION'), + | "activation_id" => getenv('__OW_ACTIVATION_ID'), + | "deadline" => getenv('__OW_DEADLINE'), + | ]; + |} + """.stripMargin.trim, + enforceEmptyOutputStream = enforceEmptyOutputStream) + } + + val props = Seq( + "api_host" -> "xyz", + "api_key" -> "abc", + "namespace" -> "zzz", + "action_name" -> "xxx", + "action_version" -> "0.0.1", + "activation_id" -> "iii", + "deadline" -> "123") + + val env = props.map { case (k, v) => s"__OW_${k.toUpperCase()}" -> v } + + // the api host is sent as a docker run environment parameter + val (out, err) = withActionContainer(env.take(1).toMap) { c => + val (initCode, _) = c.init(initPayload(config.code, config.main)) + initCode should be(200) + + // we omit the api host from the run payload so the docker run env var is used + val (runCode, out) = c.run(runPayload(JsObject.empty, Some(props.drop(1).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 (config.enforceEmptyOutputStream) o shouldBe empty + if (config.enforceEmptyErrorStream) e shouldBe empty + }) + } + it should "support application errors" in { withPhp7Container { c => val code = """
