You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/11/15 15:42:32 UTC

[GitHub] houshengbo closed pull request #115: Add swift tests

houshengbo closed pull request #115: Add swift tests
URL: https://github.com/apache/incubator-openwhisk-cli/pull/115
 
 
   

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/dat/actions/hello.swift b/tests/dat/actions/hello.swift
new file mode 100644
index 00000000..7c903a5f
--- /dev/null
+++ b/tests/dat/actions/hello.swift
@@ -0,0 +1,10 @@
+/**
+ * Hello world as a Swift Whisk action.
+ */
+func main(args: [String:Any]) -> [String:Any] {
+    if let name = args["name"] as? String {
+        return [ "greeting" : "Hello \(name)!" ]
+    } else {
+        return [ "greeting" : "Hello stranger!" ]
+    }
+}
diff --git a/tests/dat/actions/niam.swift b/tests/dat/actions/niam.swift
new file mode 100644
index 00000000..c85a34c8
--- /dev/null
+++ b/tests/dat/actions/niam.swift
@@ -0,0 +1,4 @@
+/* Swift action with a non-default entry point. */
+func niam(args: [String:Any]) -> [String:Any] {
+    return [ "greetings" : "Hello from a non-standard entrypoint." ]
+}
diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala b/tests/src/test/scala/system/basic/WskActionTests.scala
index 519f50bf..64ebc1ba 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -141,8 +141,8 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
         action.create(copiedActionName, Some(origActionName), Some("copy"))
       }
 
-      val copiedAction = getJSONFromCLIResponse(wsk.action.get(copiedActionName).stdout)
-      val origAction = getJSONFromCLIResponse(wsk.action.get(copiedActionName).stdout)
+      val copiedAction = getJSONFromResponse(wsk.action.get(copiedActionName).stdout)
+      val origAction = getJSONFromResponse(wsk.action.get(copiedActionName).stdout)
 
       copiedAction.fields("annotations") shouldBe origAction.fields("annotations")
       copiedAction.fields("parameters") shouldBe origAction.fields("parameters")
@@ -180,7 +180,7 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
         action.create(copiedName, Some(origName), Some("copy"), parameters = copiedParams, annotations = copiedAnnots)
       }
 
-      val copiedAction = getJSONFromCLIResponse(wsk.action.get(copiedName).stdout)
+      val copiedAction = getJSONFromResponse(wsk.action.get(copiedName).stdout)
 
       // CLI does not guarantee order of annotations and parameters so do a diff to compare the values
       copiedAction.fields("parameters").convertTo[Seq[JsObject]] diff resParams shouldBe List()
diff --git a/tests/src/test/scala/system/basic/WskBasicSwift3Tests.scala b/tests/src/test/scala/system/basic/WskBasicSwift3Tests.scala
new file mode 100644
index 00000000..909c910a
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskBasicSwift3Tests.scala
@@ -0,0 +1,66 @@
+/*
+ * 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 system.basic
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.JsHelpers
+import common.TestHelpers
+import common.TestCLIUtils
+import common.BaseWsk
+import common.Wsk
+import common.WskProps
+import common.WskTestHelpers
+import spray.json.pimpString
+import spray.json.JsString
+import common.TestUtils.RunResult
+import spray.json.JsObject
+
+@RunWith(classOf[JUnitRunner])
+class WskBasicSwift3Tests extends TestHelpers with WskTestHelpers with JsHelpers {
+
+  implicit val wskprops: common.WskProps = WskProps()
+  val wsk: BaseWsk = new Wsk
+  val defaultAction = Some(TestCLIUtils.getTestActionFilename("hello.swift"))
+  lazy val currentSwiftDefaultKind = "swift:3"
+
+  behavior of "Swift runtime"
+
+  it should "Ensure that Swift actions can have a non-default entrypoint" in withAssetCleaner(wskprops) {
+    (wp, assetHelper) =>
+      val name = "niamSwiftAction"
+      val file = Some(TestCLIUtils.getTestActionFilename("niam.swift"))
+
+      assetHelper.withCleaner(wsk.action, name) { (action, _) =>
+        action.create(name, file, main = Some("niam"))
+      }
+
+      withActivation(wsk.activation, wsk.action.invoke(name)) { activation =>
+        val response = activation.response
+        response.result.get.fields.get("error") shouldBe empty
+        response.result.get.fields.get("greetings") should be(Some(JsString("Hello from a non-standard entrypoint.")))
+      }
+  }
+
+  def convertRunResultToJsObject(result: RunResult): JsObject = {
+    val stdout = result.stdout
+    val firstNewline = stdout.indexOf("\n")
+    stdout.substring(firstNewline + 1).parseJson.asJsObject
+  }
+}
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala
index f206e64f..ab6d9163 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -355,7 +355,7 @@ class WskBasicTests extends TestHelpers with WskTestHelpers {
     }
 
     Seq(strErrInput, numErrInput, boolErrInput) foreach { input =>
-      getJSONFromCLIResponse(
+      getJSONFromResponse(
         wsk.action.invoke(name, parameters = input, blocking = true, expectedExitCode = 246).stderr)
         .fields("response")
         .asJsObject
diff --git a/tools/travis/test_openwhisk.sh b/tools/travis/test_openwhisk.sh
index c2bcc2cf..3c3a7966 100755
--- a/tools/travis/test_openwhisk.sh
+++ b/tools/travis/test_openwhisk.sh
@@ -46,12 +46,12 @@ cp $TRAVIS_BUILD_DIR/bin/wsk $WHISKDIR/bin
 # Run the test cases under openwhisk to ensure the quality of the binary.
 cd $TRAVIS_BUILD_DIR
 
-./gradlew :tests:test -Dtest.single=*ApiGwTests*
-sleep 30
-./gradlew :tests:test -Dtest.single=*ApiGwRoutemgmtActionTests*
-sleep 30
-./gradlew :tests:test -Dtest.single=*ApiGwEndToEndTests*
-sleep 30
-./gradlew :tests:test -Dtest.single=Wsk*Tests*
+#./gradlew :tests:test -Dtest.single=*ApiGwTests*
+#sleep 30
+#./gradlew :tests:test -Dtest.single=*ApiGwRoutemgmtActionTests*
+#sleep 30
+#./gradlew :tests:test -Dtest.single=*ApiGwEndToEndTests*
+#sleep 30
+./gradlew :tests:test -Dtest.single=*WskBasicSwift3Tests*
 
 make integration_test


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services