You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ch...@apache.org on 2018/07/12 04:41:27 UTC

[incubator-openwhisk-cli] branch master updated: Enable test scala formatting check in Travis (#351)

This is an automated email from the ASF dual-hosted git repository.

chetanm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 993a75a  Enable test scala formatting check in Travis (#351)
993a75a is described below

commit 993a75ae20fe368d329e01f6eddf0883de98a815
Author: David Cariello <dr...@us.ibm.com>
AuthorDate: Wed Jul 11 23:41:23 2018 -0500

    Enable test scala formatting check in Travis (#351)
    
    Enable format check and format existing code to confirm to the checks
---
 .travis.yml                                        |   1 +
 build.gradle                                       |  15 +++
 settings.gradle                                    |   5 +
 .../scala/system/basic/WskCliActionTests.scala     |   9 +-
 .../test/scala/system/basic/WskCliBasicTests.scala |  15 ++-
 .../whisk/core/cli/test/ApiGwCliBasicTests.scala   | 146 +++++++++++----------
 .../scala/whisk/core/cli/test/ApiGwCliTests.scala  |  84 ++++++------
 7 files changed, 158 insertions(+), 117 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f1782d4..a2e3f7b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -51,6 +51,7 @@ install:
 
 before_script:
   - cd $TRAVIS_BUILD_DIR
+  - ./gradlew --console=plain checkScalafmtAll
   - GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/)
   - test -z "$(gofmt -s -l $(echo $GO_FILES))"
   - cd $TRAVIS_BUILD_DIR/..
diff --git a/build.gradle b/build.gradle
index 1932eed..5eb5bf0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -15,10 +15,25 @@
  * limitations under the License.
  */
 
+ /* - Scalafmt Toolage -*/
+buildscript {
+  repositories {
+    jcenter()
+  }
+  dependencies {
+    classpath "cz.alenkacz:gradle-scalafmt:${gradle.scalafmt.version}"
+  }
+}
+
 plugins {
     id 'com.github.blindpirate.gogradle' version '0.8.1'
 }
 
+subprojects {
+  apply plugin: 'scalafmt'
+  scalafmt.configFilePath = gradle.scalafmt.config
+}
+
 golang {
     packagePath = 'github.com/apache/incubator-openwhisk-cli' as String
     buildTags = (rootProject.findProperty('goTags')?:'').split(',')
diff --git a/settings.gradle b/settings.gradle
index 60529da..baeb0be 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -27,3 +27,8 @@ gradle.ext.scala = [
     version: '2.11.8',
     compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import']
 ]
+
+gradle.ext.scalafmt = [
+    version: '1.5.0',
+    config: new File(rootProject.projectDir, '.scalafmt.conf')
+]
diff --git a/tests/src/test/scala/system/basic/WskCliActionTests.scala b/tests/src/test/scala/system/basic/WskCliActionTests.scala
index 042f0bd..668676b 100644
--- a/tests/src/test/scala/system/basic/WskCliActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskCliActionTests.scala
@@ -31,8 +31,13 @@ class WskCliActionTests extends WskActionTests {
   it should "not be able to use --kind and --docker at the same time when running action create or update" in {
     val file = TestUtils.getTestActionFilename(s"echo.js")
     Seq(false, true).foreach { updateValue =>
-      val out = wsk.action.create(name = "kindAndDockerAction", artifact = Some(file), expectedExitCode = NOT_ALLOWED,
-      kind = Some("nodejs:6"), docker = Some("mydockerimagename"), update = updateValue)
+      val out = wsk.action.create(
+        name = "kindAndDockerAction",
+        artifact = Some(file),
+        expectedExitCode = NOT_ALLOWED,
+        kind = Some("nodejs:6"),
+        docker = Some("mydockerimagename"),
+        update = updateValue)
       out.stderr should include("Cannot specify both --kind and --docker at the same time")
     }
   }
diff --git a/tests/src/test/scala/system/basic/WskCliBasicTests.scala b/tests/src/test/scala/system/basic/WskCliBasicTests.scala
index 283e401..db617a6 100644
--- a/tests/src/test/scala/system/basic/WskCliBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskCliBasicTests.scala
@@ -483,7 +483,8 @@ class WskCliBasicTests extends TestHelpers with WskTestHelpers {
     }
 
     val trigger = wsk.trigger.get(triggerName)
-    getJSONFromResponse(trigger.stdout, true).fields("parameters") shouldBe JsArray(JsObject("key" -> JsString("a"), "value" -> JsString("A")))
+    getJSONFromResponse(trigger.stdout, true).fields("parameters") shouldBe JsArray(
+      JsObject("key" -> JsString("a"), "value" -> JsString("A")))
     getJSONFromResponse(trigger.stdout, true).fields("publish") shouldBe false.toJson
     getJSONFromResponse(trigger.stdout, true).fields("version") shouldBe "0.0.2".toJson
 
@@ -614,10 +615,14 @@ class WskCliBasicTests extends TestHelpers with WskTestHelpers {
       wsk.trigger
         .get(triggerName, fieldFilter = Some("namespace"))
         .stdout should include regex (s"""(?i)$successMsg namespace\n"$ns"""")
-      wsk.trigger.get(triggerName, fieldFilter = Some("name")).stdout should include(s"""$successMsg name\n"$triggerName"""")
-      wsk.trigger.get(triggerName, fieldFilter = Some("version")).stdout should include(s"""$successMsg version\n"0.0.1"""")
-      wsk.trigger.get(triggerName, fieldFilter = Some("publish")).stdout should include(s"""$successMsg publish\nfalse""")
-      wsk.trigger.get(triggerName, fieldFilter = Some("annotations")).stdout should include(s"""$successMsg annotations\n[]""")
+      wsk.trigger.get(triggerName, fieldFilter = Some("name")).stdout should include(
+        s"""$successMsg name\n"$triggerName"""")
+      wsk.trigger.get(triggerName, fieldFilter = Some("version")).stdout should include(
+        s"""$successMsg version\n"0.0.1"""")
+      wsk.trigger.get(triggerName, fieldFilter = Some("publish")).stdout should include(
+        s"""$successMsg publish\nfalse""")
+      wsk.trigger.get(triggerName, fieldFilter = Some("annotations")).stdout should include(
+        s"""$successMsg annotations\n[]""")
       wsk.trigger
         .get(triggerName, fieldFilter = Some("parameters"))
         .stdout should include regex (s"""$successMsg parameters\n\\[\\s+\\{\\s+"key":\\s+"payload",\\s+"value":\\s+"test"\\s+\\}\\s+\\]""")
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
index abc682d..df3eb73 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
@@ -109,7 +109,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     rr.stdout should include(testbasepath + testrelpath)
   }
 
-  def verifyApiGet(rr: RunResult, apihost:String): Unit = {
+  def verifyApiGet(rr: RunResult, apihost: String): Unit = {
     rr.stdout should include regex (s""""operationId":\\s+"getPathWithSub_pathsInIt"""")
     rr.stdout should include regex (s""""target-url":\\s+"https://$apihost""")
   }
@@ -187,7 +187,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     return swaggerfile
   }
 
-  def getSwaggerUrl(rr: RunResult) : String = {
+  def getSwaggerUrl(rr: RunResult): String = {
     rr.stdout.split("\n")(1)
   }
 
@@ -207,15 +207,30 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
   }
 
   def getParametersFromJson(json: JsObject, pathName: String): Vector[JsValue] = {
-    json.fields("paths").asJsObject.fields(pathName).asJsObject.fields("get").asJsObject.fields("parameters").convertTo[JsArray].elements
+    json
+      .fields("paths")
+      .asJsObject
+      .fields(pathName)
+      .asJsObject
+      .fields("get")
+      .asJsObject
+      .fields("parameters")
+      .convertTo[JsArray]
+      .elements
   }
 
   def getSslConfig(): RestAssuredConfig = {
     // force RestAssured to allow all hosts in SSL certificates
-    new RestAssuredConfig().sslConfig(new SSLConfig().keystore("keystore", WhiskProperties.getSslCertificateChallenge).allowAllHostnames())
+    new RestAssuredConfig()
+      .sslConfig(new SSLConfig().keystore("keystore", WhiskProperties.getSslCertificateChallenge).allowAllHostnames())
   }
 
-  def validateParameter(parameter: JsObject, name: String, in: String, required: Boolean, pType: String, description: String): Unit = {
+  def validateParameter(parameter: JsObject,
+                        name: String,
+                        in: String,
+                        required: Boolean,
+                        pType: String,
+                        description: String): Unit = {
     parameter.fields("name") should be(name.toJson)
     parameter.fields("in") should be(in.toJson)
     parameter.fields("required") should be(required.toJson)
@@ -227,68 +242,66 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
 
   behavior of "Cli Wsk api creation with path parameters with swagger"
 
-  it should "create the API when swagger file contains path parameters" in withAssetCleaner(
-    wskprops) { (wp, assetHelper) =>
-    val actionName = "cli_apigwtest_path_param_swagger_action"
-    val apiName = "/guest/v1"
-    val reqPath = "\\$\\(request.path\\)"
-    val testRelPath = "/api2/greeting2/{name}"
-    val testUrlName = "scooby"
-    val testRelPathGet = s"/api2/greeting2/$testUrlName"
-    val testUrlOp = "get"
-    var file = TestUtils.getTestActionFilename(s"echo-web-http.js")
-    val hostRegex = "%HOST%".r
-    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
-      (action, _) =>
+  it should "create the API when swagger file contains path parameters" in withAssetCleaner(wskprops) {
+    (wp, assetHelper) =>
+      val actionName = "cli_apigwtest_path_param_swagger_action"
+      val apiName = "/guest/v1"
+      val reqPath = "\\$\\(request.path\\)"
+      val testRelPath = "/api2/greeting2/{name}"
+      val testUrlName = "scooby"
+      val testRelPathGet = s"/api2/greeting2/$testUrlName"
+      val testUrlOp = "get"
+      var file = TestUtils.getTestActionFilename(s"echo-web-http.js")
+      val hostRegex = "%HOST%".r
+      assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
         action.create(actionName, Some(file), web = Some("true"))
-    }
-    try {
-      //Create the API
-      var rr : RunResult = apiCreate(
-        basepath = Some(apiName),
-        relpath = Some(testRelPath),
-        operation = Some(testUrlOp),
-        action = Some(actionName),
-        responsetype = Some("http")
-      )
-      verifyApiCreated(rr)
-
-      //Get the api so we can create the swagger from the returned output
-      rr = apiGet(basepathOrApiName = Some(apiName))
-      rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
-      val swaggerFile = writeSwaggerFile(rr)
-
-      //Delete the api so we can re-create it using the swagger
-      rr = apiDelete(basepathOrApiName = apiName)
-      verifyApiDeleted(rr)
-
-      //Create the api using the swagger file.
-      rr = apiCreate(swagger = Some(swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT)
-      verifyApiCreated(rr)
-      val swaggerApiUrl = getSwaggerUrl(rr).replace("{name}", testUrlName)
-
-      //Lets validate that the swagger we get from the create contains the correct info.
-      rr = apiGet(basepathOrApiName = Some(apiName))
-      rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
-
-      val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
-      params.size should be(1)
-      validateParameter(params(0).asJsObject, "name", "path", true, "string", "Default description for 'name'")
-
-      //Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
-      val apiToInvoke = s"$swaggerApiUrl"
-      println(s"Invoking: '${apiToInvoke}'")
-      val response = whisk.utils.retry({
-        val response = RestAssured.given().config(getSslConfig()).get(s"$apiToInvoke")
-        response.statusCode should be(200)
-        response
-      }, 6, Some(2.second))
-      val jsonResponse = response.body.asString.parseJson.asJsObject
-
-      jsonResponse.fields("__ow_path").toString should include (testRelPathGet)
-    } finally {
-      apiDelete(basepathOrApiName = apiName)
-    }
+      }
+      try {
+        //Create the API
+        var rr: RunResult = apiCreate(
+          basepath = Some(apiName),
+          relpath = Some(testRelPath),
+          operation = Some(testUrlOp),
+          action = Some(actionName),
+          responsetype = Some("http"))
+        verifyApiCreated(rr)
+
+        //Get the api so we can create the swagger from the returned output
+        rr = apiGet(basepathOrApiName = Some(apiName))
+        rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
+        val swaggerFile = writeSwaggerFile(rr)
+
+        //Delete the api so we can re-create it using the swagger
+        rr = apiDelete(basepathOrApiName = apiName)
+        verifyApiDeleted(rr)
+
+        //Create the api using the swagger file.
+        rr = apiCreate(swagger = Some(swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT)
+        verifyApiCreated(rr)
+        val swaggerApiUrl = getSwaggerUrl(rr).replace("{name}", testUrlName)
+
+        //Lets validate that the swagger we get from the create contains the correct info.
+        rr = apiGet(basepathOrApiName = Some(apiName))
+        rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
+
+        val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
+        params.size should be(1)
+        validateParameter(params(0).asJsObject, "name", "path", true, "string", "Default description for 'name'")
+
+        //Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
+        val apiToInvoke = s"$swaggerApiUrl"
+        println(s"Invoking: '${apiToInvoke}'")
+        val response = whisk.utils.retry({
+          val response = RestAssured.given().config(getSslConfig()).get(s"$apiToInvoke")
+          response.statusCode should be(200)
+          response
+        }, 6, Some(2.second))
+        val jsonResponse = response.body.asString.parseJson.asJsObject
+
+        jsonResponse.fields("__ow_path").toString should include(testRelPathGet)
+      } finally {
+        apiDelete(basepathOrApiName = apiName)
+      }
   }
 
   it should "reject an api commands with an invalid path parameter" in {
@@ -493,7 +506,6 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     }
   }
 
-
   it should "verify get API name " in {
     val testName = "CLI_APIGWTEST3"
     val testbasepath = "/" + testName + "_bp"
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliTests.scala
index 8fa0f61..626a183 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliTests.scala
@@ -30,52 +30,51 @@ import scala.concurrent.duration.DurationInt
 import spray.json._
 
 /**
-  * Tests for basic CLI usage. Some of these tests require a deployed backend.
-  */
+ * Tests for basic CLI usage. Some of these tests require a deployed backend.
+ */
 @RunWith(classOf[JUnitRunner])
 class ApiGwCliTests extends ApiGwCliBasicTests {
   override lazy val wsk: common.Wsk = new Wsk
   override lazy val createCode = SUCCESS_EXIT
   behavior of "Cli Wsk api creation with path parameters no swagger"
 
-  it should "fail to create an API if the base path contains path parameters" in withAssetCleaner(wskprops) {(wp, assetHelper) =>
-    val actionName = "APIGWTEST_BAD_BASE_PATH_ACTION"
-    val basePath = "/mybase/{path}"
-    val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
-    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
-      (action, _) =>
+  it should "fail to create an API if the base path contains path parameters" in withAssetCleaner(wskprops) {
+    (wp, assetHelper) =>
+      val actionName = "APIGWTEST_BAD_BASE_PATH_ACTION"
+      val basePath = "/mybase/{path}"
+      val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
+      assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
         action.create(actionName, Some(file), web = Some("true"))
-    }
-    val relPath = "/bad/{path}/value"
-    val rr = apiCreate(basepath = Some(basePath),
-      relpath = Some(relPath),
-      operation = Some("GET"),
-      action = Some(actionName),
-      expectedExitCode = ANY_ERROR_EXIT)
-    rr.stderr should include(
-      s"The base path '${basePath}' cannot have parameters. Only the relative path supports path parameters.")
+      }
+      val relPath = "/bad/{path}/value"
+      val rr = apiCreate(
+        basepath = Some(basePath),
+        relpath = Some(relPath),
+        operation = Some("GET"),
+        action = Some(actionName),
+        expectedExitCode = ANY_ERROR_EXIT)
+      rr.stderr should include(
+        s"The base path '${basePath}' cannot have parameters. Only the relative path supports path parameters.")
   }
 
   it should "fail to create an Api if path parameters are specified but http response type is not given" in withAssetCleaner(
     wskprops) { (wp, assetHelper) =>
     val actionName = "CLI_APIGWTEST_PATH_param_fail1_action"
     val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
-    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
-      (action, _) =>
-        action.create(actionName, Some(file), web = Some("true"))
+    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
+      action.create(actionName, Some(file), web = Some("true"))
     }
     val relPath = "/bad/{path}/value"
-    val rr = apiCreate(basepath = Some("/mybase"),
-                       relpath = Some(relPath),
-                       operation = Some("GET"),
-                       action = Some(actionName),
-                       expectedExitCode = ANY_ERROR_EXIT)
-    rr.stderr should include(
-      s"A response type of 'http' is required when using path parameters.")
+    val rr = apiCreate(
+      basepath = Some("/mybase"),
+      relpath = Some(relPath),
+      operation = Some("GET"),
+      action = Some(actionName),
+      expectedExitCode = ANY_ERROR_EXIT)
+    rr.stderr should include(s"A response type of 'http' is required when using path parameters.")
   }
 
-  it should "create api with path parameters for the verb" in withAssetCleaner(
-    wskprops) { (wp, assetHelper) =>
+  it should "create api with path parameters for the verb" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
     val testName = "CLI_APIGWTEST_PATH_PARAMS1"
     val testBasePath = s"/${testName}_bp"
     val testUrlName1 = "scooby"
@@ -89,9 +88,8 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
 
     // Create the action for the API.  It must be a "web-action" action.
     val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
-    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
-      (action, _) =>
-        action.create(actionName, Some(file), web = Some("true"))
+    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
+      action.create(actionName, Some(file), web = Some("true"))
     }
     try {
       var rr = apiCreate(
@@ -100,8 +98,7 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
         operation = Some(testUrlOp),
         action = Some(actionName),
         apiname = Some(testApiName),
-        responsetype = Some("http")
-      )
+        responsetype = Some("http"))
       verifyApiCreated(rr)
       val swaggerApiUrl = getSwaggerUrl(rr).replace("{with}", testUrlName1).replace("{path}", testUrlName2)
 
@@ -126,7 +123,7 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
       }, 6, Some(2.second))
       val jsonResponse = response.body.asString.parseJson.asJsObject
 
-      jsonResponse.fields("__ow_path").toString should include (testRelPathGet)
+      jsonResponse.fields("__ow_path").toString should include(testRelPathGet)
     } finally {
       apiDelete(basepathOrApiName = testBasePath)
     }
@@ -148,9 +145,8 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
     val reqPath = "\\$\\(request.path\\)"
     // Create the action for the API.  It must be a "web-action" action.
     val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
-    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
-      (action, _) =>
-        action.create(actionName, Some(file), web = Some("true"))
+    assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
+      action.create(actionName, Some(file), web = Some("true"))
     }
     try {
       var rr = apiCreate(
@@ -159,11 +155,13 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
         operation = Some(testUrlOp),
         action = Some(actionName),
         apiname = Some(testApiName),
-        responsetype = Some("http")
-      )
+        responsetype = Some("http"))
       verifyApiCreated(rr)
-      val swaggerApiUrl = getSwaggerUrl(rr).replace("{with}", testUrlName1).replace("{path}", testUrlName2)
-          .replace("{double}", testUrlName3).replace("{extra}", testUrlName4)
+      val swaggerApiUrl = getSwaggerUrl(rr)
+        .replace("{with}", testUrlName1)
+        .replace("{path}", testUrlName2)
+        .replace("{double}", testUrlName3)
+        .replace("{extra}", testUrlName4)
 
       //Validate the api created contained parameters and they were correct
       rr = apiGet(basepathOrApiName = Some(testApiName))
@@ -190,7 +188,7 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
       }, 6, Some(2.second))
       val jsonResponse = response.body.asString.parseJson.asJsObject
 
-      jsonResponse.fields("__ow_path").toString should include (testRelPathGet)
+      jsonResponse.fields("__ow_path").toString should include(testRelPathGet)
     } finally {
       apiDelete(basepathOrApiName = testBasePath)
     }