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/12/14 08:00:08 UTC

[GitHub] markusthoemmes commented on a change in pull request #2996: Rewrite WskBasicUsageTests

markusthoemmes commented on a change in pull request #2996: Rewrite WskBasicUsageTests
URL: https://github.com/apache/incubator-openwhisk/pull/2996#discussion_r156874144
 
 

 ##########
 File path: tests/src/test/scala/common/rest/WskRest.scala
 ##########
 @@ -1325,19 +1358,33 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd with Matchers with ScalaFu
   }
 
   def fullEntityName(name: String)(implicit wp: WskProps) = {
-    val sep = "/"
-    if (name.startsWith(sep)) name
-    else s"/${wp.namespace}/$name"
+    name.split("/") match {
+      // Example: /namespace/package_name/entity_name
+      case Array(empty, namespace, packageName, entityName) if empty.isEmpty => s"/$namespace/$packageName/$entityName"
+      // Example: /namespace/entity_name
+      case Array(empty, namespace, entityName) if empty.isEmpty => s"/$namespace/$entityName"
+      // Example: namespace/package_name/entity_name
+      case Array(namespace, packageName, entityName) => s"/$namespace/$packageName/$entityName"
+      // Example: /namespace
+      case Array(empty, namespace) if empty.isEmpty => namespace
+      // Example: package_name/entity_name
+      case Array(packageName, entityName) if !packageName.isEmpty => s"/${wp.namespace}/$packageName/$entityName"
+      // Example: entity_name
+      case Array(entityName) => s"/${wp.namespace}/$name"
+      case _                 => s"/${wp.namespace}/$name"
+    }
   }
 
-  def convertIntoComponents(comps: String)(implicit wp: WskProps): JsArray = {
+  def convertIntoComponents(comps: String)(implicit wp: WskProps): Vector[JsString] = {
     var paramsList = Vector[JsString]()
-    comps.split(",") foreach {
-      case (value) =>
-        val fullName = fullEntityName(value)
-        paramsList :+= JsString(fullName)
+    if (!comps.isEmpty()) {
+      comps.split(",") foreach {
+        case (value) =>
+          val fullName = fullEntityName(value)
+          paramsList :+= JsString(fullName)
+      }
     }
-    JsArray(paramsList)
+    paramsList
 
 Review comment:
   No mutability needed as well:
   
   ```scala
   def convertIntoComponents(comps: String)(implicit wp: WskProps): Vector[JsString] = {
     comps.split(",").filter(_.nonEmpty).map(comp => fullEntityName(comp).toJson)
   }
   ```

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