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/10/24 18:39:03 UTC

[GitHub] dubeejw closed pull request #2621: Replace the test cases of action and package with REST implementation

dubeejw closed pull request #2621: Replace the test cases of action and package with REST implementation
URL: https://github.com/apache/incubator-openwhisk/pull/2621
 
 
   

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/build.gradle b/tests/build.gradle
index 6fa5a66e53..ee415e3e1a 100644
--- a/tests/build.gradle
+++ b/tests/build.gradle
@@ -24,6 +24,17 @@ task testLean(type: Test) {
     exclude '**/*ThrottleTests*'
     exclude '**/MaxActionDurationTests*'
     exclude '**/*ApiGwTests*'
+    exclude '**/*Cli*'
+}
+
+task testLeanCli(type: Test) {
+    exclude '**/*Swift*'
+    exclude '**/*Python*'
+    exclude '**/*Java*'
+    exclude '**/*ThrottleTests*'
+    exclude '**/MaxActionDurationTests*'
+    exclude '**/*ApiGwTests*'
+    exclude '**/*Rest*'
 }
 
 // Add all images needed for local testing here
diff --git a/tests/src/test/scala/common/WskTestHelpers.scala b/tests/src/test/scala/common/WskTestHelpers.scala
index 23d6b87d17..b6aa35e31e 100644
--- a/tests/src/test/scala/common/WskTestHelpers.scala
+++ b/tests/src/test/scala/common/WskTestHelpers.scala
@@ -280,9 +280,13 @@ trait WskTestHelpers extends Matchers {
     }
   }
 
-  def removeCLIHeader(response: String): String = response.substring(response.indexOf("\n"))
+  def removeCLIHeader(response: String): String = {
+    if (response.contains("\n")) response.substring(response.indexOf("\n")) else response
+  }
 
-  def getJSONFromCLIResponse(response: String): JsObject = removeCLIHeader(response).parseJson.asJsObject
+  def getJSONFromResponse(response: String, isCli: Boolean = false): JsObject = {
+    if (isCli) removeCLIHeader(response).parseJson.asJsObject else response.parseJson.asJsObject
+  }
 
   def getAdditionalTestSubject(newUser: String): WskProps = {
     val wskadmin = new RunWskAdminCmd {}
diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala b/tests/src/test/scala/system/basic/WskActionTests.scala
index c422bc057e..7836b03d16 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -24,6 +24,7 @@ import common.ActivationResult
 import common.JsHelpers
 import common.TestHelpers
 import common.TestUtils
+import common.BaseWsk
 import common.Wsk
 import common.WskProps
 import common.WskTestHelpers
@@ -33,10 +34,10 @@ import spray.json.JsObject
 import spray.json.pimpAny
 
 @RunWith(classOf[JUnitRunner])
-class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
+abstract class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk: BaseWsk
 
   val testString = "this is a test"
   val testResult = JsObject("count" -> testString.split(" ").length.toJson)
@@ -140,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, wsk.isInstanceOf[Wsk])
+      val origAction = getJSONFromResponse(wsk.action.get(copiedActionName).stdout, wsk.isInstanceOf[Wsk])
 
       copiedAction.fields("annotations") shouldBe origAction.fields("annotations")
       copiedAction.fields("parameters") shouldBe origAction.fields("parameters")
@@ -176,10 +177,11 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
       }
 
       assetHelper.withCleaner(wsk.action, copiedName) { (action, _) =>
+        println("created copied ")
         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, wsk.isInstanceOf[Wsk])
 
       // 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()
@@ -267,16 +269,6 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers {
     }
   }
 
-  it should "reject an invoke with the wrong parameters set" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
-    val fullQualifiedName = s"/$guestNamespace/samples/helloWorld"
-    val payload = "bob"
-    val rr = wsk.cli(
-      Seq("action", "invoke", fullQualifiedName, payload) ++ wskprops.overrides,
-      expectedExitCode = TestUtils.ERROR_EXIT)
-    rr.stderr should include("Run 'wsk --help' for usage.")
-    rr.stderr should include(s"error: Invalid argument(s): $payload")
-  }
-
   it should "not be able to use 'ping' in an action" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
     val name = "ping"
     assetHelper.withCleaner(wsk.action, name) { (action, _) =>
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala
index f97b62db2d..9e52694ec0 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -355,8 +355,9 @@ class WskBasicTests extends TestHelpers with WskTestHelpers {
     }
 
     Seq(strErrInput, numErrInput, boolErrInput) foreach { input =>
-      getJSONFromCLIResponse(
-        wsk.action.invoke(name, parameters = input, blocking = true, expectedExitCode = 246).stderr)
+      getJSONFromResponse(
+        wsk.action.invoke(name, parameters = input, blocking = true, expectedExitCode = 246).stderr,
+        wsk.isInstanceOf[Wsk])
         .fields("response")
         .asJsObject
         .fields("result")
diff --git a/tests/src/test/scala/system/basic/WskCliActionTests.scala b/tests/src/test/scala/system/basic/WskCliActionTests.scala
new file mode 100644
index 0000000000..b7649f6d00
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskCliActionTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.Wsk
+
+@RunWith(classOf[JUnitRunner])
+class WskCliActionTests extends WskActionTests {
+  override val wsk = new Wsk
+}
diff --git a/tests/src/test/scala/system/basic/WskCliPackageTests.scala b/tests/src/test/scala/system/basic/WskCliPackageTests.scala
new file mode 100644
index 0000000000..e3a3f847db
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskCliPackageTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.Wsk
+
+@RunWith(classOf[JUnitRunner])
+class WskCliPackageTests extends WskPackageTests {
+  override val wsk: Wsk = new Wsk
+}
diff --git a/tests/src/test/scala/system/basic/WskPackageTests.scala b/tests/src/test/scala/system/basic/WskPackageTests.scala
index 5c19f9ed34..fe0dabab48 100644
--- a/tests/src/test/scala/system/basic/WskPackageTests.scala
+++ b/tests/src/test/scala/system/basic/WskPackageTests.scala
@@ -24,7 +24,7 @@ import scala.concurrent.duration.DurationInt
 import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
 import common.TestUtils
-import common.Wsk
+import common.BaseWsk
 import common.WskProps
 import spray.json._
 import spray.json.DefaultJsonProtocol.StringJsonFormat
@@ -34,10 +34,10 @@ import common.TestHelpers
 import common.WskProps
 
 @RunWith(classOf[JUnitRunner])
-class WskPackageTests extends TestHelpers with WskTestHelpers {
+abstract class WskPackageTests extends TestHelpers with WskTestHelpers {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk: BaseWsk
   val LOG_DELAY = 80 seconds
 
   behavior of "Wsk Package"
@@ -128,9 +128,8 @@ class WskPackageTests extends TestHelpers with WskTestHelpers {
     val flatDescription = itemDescription.replace("\n", "").replace("\r", "")
     merged.foreach {
       case (key: String, value: JsValue) =>
-        val toFind = s""""key": "${key}",.*"value": ${value.toString}"""
+        val toFind = s""""key":.*"${key}",.*"value":.*${value.toString}"""
         flatDescription should include regex toFind
     }
   }
-
 }
diff --git a/tests/src/test/scala/system/basic/WskRestActionTests.scala b/tests/src/test/scala/system/basic/WskRestActionTests.scala
new file mode 100644
index 0000000000..2dbc866a1f
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskRestActionTests.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.rest.WskRest
+
+@RunWith(classOf[JUnitRunner])
+class WskRestActionTests extends WskActionTests {
+  override val wsk: WskRest = new WskRest
+}
diff --git a/tests/src/test/scala/system/basic/WskRestPackageTests.scala b/tests/src/test/scala/system/basic/WskRestPackageTests.scala
new file mode 100644
index 0000000000..df5f66266c
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskRestPackageTests.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.rest.WskRest
+
+@RunWith(classOf[JUnitRunner])
+class WskRestPackageTests extends WskPackageTests {
+  override val wsk: WskRest = new WskRest
+}


 

----------------------------------------------------------------
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