Skip to content

Commit

Permalink
Update tests to pick up upstream changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbah authored and dgrove-oss committed Jul 10, 2018
1 parent 52b3fbc commit 6caf902
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 87 deletions.
4 changes: 4 additions & 0 deletions core/php7.1Action/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#
-->

## 1.0.2
Changes:
- Disallow re-initialization of function.

## 1.0.1

- Change: Update PHP to 7.1.18
Expand Down
2 changes: 1 addition & 1 deletion core/php7.1Action/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function init() : array
$binary = $data['binary'] ?? false; // code is binary?
if (!$code) {
throw new RuntimeException("No code to execute");
throw new RuntimeException("Missing main/no code to execute.");
}

if ($binary) {
Expand Down
4 changes: 4 additions & 0 deletions core/php7.2Action/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#
-->

## 1.0.1
Changes:
- Disallow re-initialization of function.

## 1.0.0
Initial release

Expand Down
2 changes: 1 addition & 1 deletion core/php7.2Action/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function init() : array
$binary = $data['binary'] ?? false; // code is binary?
if (!$code) {
throw new RuntimeException("No code to execute");
throw new RuntimeException("Missing main/no code to execute.");
}

if ($binary) {
Expand Down
5 changes: 0 additions & 5 deletions tests/.pydevproject

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import spray.json._

@RunWith(classOf[JUnitRunner])
abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
// note: "out" will not be empty as the PHP web server outputs a message when
// it starts up
// note: "out" will not be empty as the PHP web server outputs a message when it starts up
val enforceEmptyOutputStream = false

lazy val phpContainerImageName = "action-php-v7.x"
lazy val phpContainerImageName: String = ???

override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
withContainer(phpContainerImageName, env)(code)
Expand All @@ -41,68 +40,94 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA

behavior of phpContainerImageName

testEcho(Seq {
(
"PHP",
override val testNoSourceOrExec = TestConfig("")

override val testNotReturningJson = {
TestConfig(
"""
|<?php
|function main(array $args) {
| return "not a json object";
|}
""".stripMargin,
enforceEmptyOutputStream = enforceEmptyOutputStream,
enforceEmptyErrorStream = false)
}

override val testInitCannotBeCalledMoreThanOnce = {
TestConfig(
"""
|<?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";
|function main(array $args) : array {
| return $args;
|}
""".stripMargin)
""".stripMargin,
enforceEmptyOutputStream = enforceEmptyOutputStream)
}

testUnicode(Seq {
(
"PHP",
override val testEntryPointOtherThanMain = {
TestConfig(
"""
| <?php
| function niam(array $args) {
| return $args;
| }
""".stripMargin,
main = "niam",
enforceEmptyOutputStream = enforceEmptyOutputStream)
}

override val testEcho = {
TestConfig("""
|<?php
|function main(array $args) : array {
| echo 'hello stdout';
| error_log('hello stderr');
| return $args;
|}
""".stripMargin)
}

override val testUnicode = {
TestConfig("""
|<?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)

testInitCannotBeCalledMoreThanOnce("""
|<?php
|function main(array $args) : array {
| echo 'hello stdout';
| error_log('hello stderr');
| return $args;
|}
""".stripMargin)
override val testEnv = {
TestConfig(
"""
|<?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 = enforceEmptyOutputStream)
}

override val testLargeInput = {
TestConfig("""
|<?php
|function main(array $args) : array {
| echo 'hello stdout';
| error_log('hello stderr');
| return $args;
|}
""".stripMargin)
}

it should "fail to initialize with bad code" in {
val (out, err) = withPhp7Container { c =>
Expand All @@ -127,19 +152,6 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
})
}

it should "fail to initialize with no code" in {
val (out, err) = withPhp7Container { 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) = withPhp7Container { c =>
val code = """
Expand Down Expand Up @@ -467,21 +479,6 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
})
}

it should "support actions using non-default entry point" in {
val (out, err) = withPhp7Container { 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
Expand Down

0 comments on commit 6caf902

Please sign in to comment.