This is an automated email from the ASF dual-hosted git repository. dubeejw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new 0b2644e Replace the test cases of action and package with REST implementation (#2621) 0b2644e is described below commit 0b2644ef56047dd6bbd999e544d35284cbd90e25 Author: Vincent <s...@us.ibm.com> AuthorDate: Tue Oct 24 14:38:59 2017 -0400 Replace the test cases of action and package with REST implementation (#2621) Partially-closes: #2430 --- tests/build.gradle | 11 +++++++++ tests/src/test/scala/common/WskTestHelpers.scala | 8 +++++-- .../test/scala/system/basic/WskActionTests.scala | 22 ++++++----------- .../test/scala/system/basic/WskBasicTests.scala | 5 ++-- .../scala/system/basic/WskCliActionTests.scala | 28 ++++++++++++++++++++++ .../scala/system/basic/WskCliPackageTests.scala | 28 ++++++++++++++++++++++ .../test/scala/system/basic/WskPackageTests.scala | 9 ++++--- .../scala/system/basic/WskRestActionTests.scala | 28 ++++++++++++++++++++++ .../scala/system/basic/WskRestPackageTests.scala | 27 +++++++++++++++++++++ 9 files changed, 142 insertions(+), 24 deletions(-) diff --git a/tests/build.gradle b/tests/build.gradle index 6fa5a66..ee415e3 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 23d6b87..b6aa35e 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 c422bc0..7836b03 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 f97b62d..9e52694 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 0000000..b7649f6 --- /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 0000000..e3a3f84 --- /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 5c19f9e..fe0daba 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 0000000..2dbc866 --- /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 0000000..df5f662 --- /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 +} -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].