Skip to content

Commit 993a75a

Browse files
David Cariellochetanmeh
authored andcommitted
Enable test scala formatting check in Travis (#351)
Enable format check and format existing code to confirm to the checks
1 parent 73331c6 commit 993a75a

File tree

7 files changed

+158
-117
lines changed

7 files changed

+158
-117
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ install:
5151

5252
before_script:
5353
- cd $TRAVIS_BUILD_DIR
54+
- ./gradlew --console=plain checkScalafmtAll
5455
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/)
5556
- test -z "$(gofmt -s -l $(echo $GO_FILES))"
5657
- cd $TRAVIS_BUILD_DIR/..

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,25 @@
1515
* limitations under the License.
1616
*/
1717

18+
/* - Scalafmt Toolage -*/
19+
buildscript {
20+
repositories {
21+
jcenter()
22+
}
23+
dependencies {
24+
classpath "cz.alenkacz:gradle-scalafmt:${gradle.scalafmt.version}"
25+
}
26+
}
27+
1828
plugins {
1929
id 'com.github.blindpirate.gogradle' version '0.8.1'
2030
}
2131

32+
subprojects {
33+
apply plugin: 'scalafmt'
34+
scalafmt.configFilePath = gradle.scalafmt.config
35+
}
36+
2237
golang {
2338
packagePath = 'github.com/apache/incubator-openwhisk-cli' as String
2439
buildTags = (rootProject.findProperty('goTags')?:'').split(',')

settings.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ gradle.ext.scala = [
2727
version: '2.11.8',
2828
compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import']
2929
]
30+
31+
gradle.ext.scalafmt = [
32+
version: '1.5.0',
33+
config: new File(rootProject.projectDir, '.scalafmt.conf')
34+
]

tests/src/test/scala/system/basic/WskCliActionTests.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ class WskCliActionTests extends WskActionTests {
3131
it should "not be able to use --kind and --docker at the same time when running action create or update" in {
3232
val file = TestUtils.getTestActionFilename(s"echo.js")
3333
Seq(false, true).foreach { updateValue =>
34-
val out = wsk.action.create(name = "kindAndDockerAction", artifact = Some(file), expectedExitCode = NOT_ALLOWED,
35-
kind = Some("nodejs:6"), docker = Some("mydockerimagename"), update = updateValue)
34+
val out = wsk.action.create(
35+
name = "kindAndDockerAction",
36+
artifact = Some(file),
37+
expectedExitCode = NOT_ALLOWED,
38+
kind = Some("nodejs:6"),
39+
docker = Some("mydockerimagename"),
40+
update = updateValue)
3641
out.stderr should include("Cannot specify both --kind and --docker at the same time")
3742
}
3843
}

tests/src/test/scala/system/basic/WskCliBasicTests.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ class WskCliBasicTests extends TestHelpers with WskTestHelpers {
483483
}
484484

485485
val trigger = wsk.trigger.get(triggerName)
486-
getJSONFromResponse(trigger.stdout, true).fields("parameters") shouldBe JsArray(JsObject("key" -> JsString("a"), "value" -> JsString("A")))
486+
getJSONFromResponse(trigger.stdout, true).fields("parameters") shouldBe JsArray(
487+
JsObject("key" -> JsString("a"), "value" -> JsString("A")))
487488
getJSONFromResponse(trigger.stdout, true).fields("publish") shouldBe false.toJson
488489
getJSONFromResponse(trigger.stdout, true).fields("version") shouldBe "0.0.2".toJson
489490

@@ -614,10 +615,14 @@ class WskCliBasicTests extends TestHelpers with WskTestHelpers {
614615
wsk.trigger
615616
.get(triggerName, fieldFilter = Some("namespace"))
616617
.stdout should include regex (s"""(?i)$successMsg namespace\n"$ns"""")
617-
wsk.trigger.get(triggerName, fieldFilter = Some("name")).stdout should include(s"""$successMsg name\n"$triggerName"""")
618-
wsk.trigger.get(triggerName, fieldFilter = Some("version")).stdout should include(s"""$successMsg version\n"0.0.1"""")
619-
wsk.trigger.get(triggerName, fieldFilter = Some("publish")).stdout should include(s"""$successMsg publish\nfalse""")
620-
wsk.trigger.get(triggerName, fieldFilter = Some("annotations")).stdout should include(s"""$successMsg annotations\n[]""")
618+
wsk.trigger.get(triggerName, fieldFilter = Some("name")).stdout should include(
619+
s"""$successMsg name\n"$triggerName"""")
620+
wsk.trigger.get(triggerName, fieldFilter = Some("version")).stdout should include(
621+
s"""$successMsg version\n"0.0.1"""")
622+
wsk.trigger.get(triggerName, fieldFilter = Some("publish")).stdout should include(
623+
s"""$successMsg publish\nfalse""")
624+
wsk.trigger.get(triggerName, fieldFilter = Some("annotations")).stdout should include(
625+
s"""$successMsg annotations\n[]""")
621626
wsk.trigger
622627
.get(triggerName, fieldFilter = Some("parameters"))
623628
.stdout should include regex (s"""$successMsg parameters\n\\[\\s+\\{\\s+"key":\\s+"payload",\\s+"value":\\s+"test"\\s+\\}\\s+\\]""")

tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
109109
rr.stdout should include(testbasepath + testrelpath)
110110
}
111111

112-
def verifyApiGet(rr: RunResult, apihost:String): Unit = {
112+
def verifyApiGet(rr: RunResult, apihost: String): Unit = {
113113
rr.stdout should include regex (s""""operationId":\\s+"getPathWithSub_pathsInIt"""")
114114
rr.stdout should include regex (s""""target-url":\\s+"https://$apihost""")
115115
}
@@ -187,7 +187,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
187187
return swaggerfile
188188
}
189189

190-
def getSwaggerUrl(rr: RunResult) : String = {
190+
def getSwaggerUrl(rr: RunResult): String = {
191191
rr.stdout.split("\n")(1)
192192
}
193193

@@ -207,15 +207,30 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
207207
}
208208

209209
def getParametersFromJson(json: JsObject, pathName: String): Vector[JsValue] = {
210-
json.fields("paths").asJsObject.fields(pathName).asJsObject.fields("get").asJsObject.fields("parameters").convertTo[JsArray].elements
210+
json
211+
.fields("paths")
212+
.asJsObject
213+
.fields(pathName)
214+
.asJsObject
215+
.fields("get")
216+
.asJsObject
217+
.fields("parameters")
218+
.convertTo[JsArray]
219+
.elements
211220
}
212221

213222
def getSslConfig(): RestAssuredConfig = {
214223
// force RestAssured to allow all hosts in SSL certificates
215-
new RestAssuredConfig().sslConfig(new SSLConfig().keystore("keystore", WhiskProperties.getSslCertificateChallenge).allowAllHostnames())
224+
new RestAssuredConfig()
225+
.sslConfig(new SSLConfig().keystore("keystore", WhiskProperties.getSslCertificateChallenge).allowAllHostnames())
216226
}
217227

218-
def validateParameter(parameter: JsObject, name: String, in: String, required: Boolean, pType: String, description: String): Unit = {
228+
def validateParameter(parameter: JsObject,
229+
name: String,
230+
in: String,
231+
required: Boolean,
232+
pType: String,
233+
description: String): Unit = {
219234
parameter.fields("name") should be(name.toJson)
220235
parameter.fields("in") should be(in.toJson)
221236
parameter.fields("required") should be(required.toJson)
@@ -227,68 +242,66 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
227242

228243
behavior of "Cli Wsk api creation with path parameters with swagger"
229244

230-
it should "create the API when swagger file contains path parameters" in withAssetCleaner(
231-
wskprops) { (wp, assetHelper) =>
232-
val actionName = "cli_apigwtest_path_param_swagger_action"
233-
val apiName = "/guest/v1"
234-
val reqPath = "\\$\\(request.path\\)"
235-
val testRelPath = "/api2/greeting2/{name}"
236-
val testUrlName = "scooby"
237-
val testRelPathGet = s"/api2/greeting2/$testUrlName"
238-
val testUrlOp = "get"
239-
var file = TestUtils.getTestActionFilename(s"echo-web-http.js")
240-
val hostRegex = "%HOST%".r
241-
assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) {
242-
(action, _) =>
245+
it should "create the API when swagger file contains path parameters" in withAssetCleaner(wskprops) {
246+
(wp, assetHelper) =>
247+
val actionName = "cli_apigwtest_path_param_swagger_action"
248+
val apiName = "/guest/v1"
249+
val reqPath = "\\$\\(request.path\\)"
250+
val testRelPath = "/api2/greeting2/{name}"
251+
val testUrlName = "scooby"
252+
val testRelPathGet = s"/api2/greeting2/$testUrlName"
253+
val testUrlOp = "get"
254+
var file = TestUtils.getTestActionFilename(s"echo-web-http.js")
255+
val hostRegex = "%HOST%".r
256+
assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true) { (action, _) =>
243257
action.create(actionName, Some(file), web = Some("true"))
244-
}
245-
try {
246-
//Create the API
247-
var rr : RunResult = apiCreate(
248-
basepath = Some(apiName),
249-
relpath = Some(testRelPath),
250-
operation = Some(testUrlOp),
251-
action = Some(actionName),
252-
responsetype = Some("http")
253-
)
254-
verifyApiCreated(rr)
255-
256-
//Get the api so we can create the swagger from the returned output
257-
rr = apiGet(basepathOrApiName = Some(apiName))
258-
rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
259-
val swaggerFile = writeSwaggerFile(rr)
260-
261-
//Delete the api so we can re-create it using the swagger
262-
rr = apiDelete(basepathOrApiName = apiName)
263-
verifyApiDeleted(rr)
264-
265-
//Create the api using the swagger file.
266-
rr = apiCreate(swagger = Some(swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT)
267-
verifyApiCreated(rr)
268-
val swaggerApiUrl = getSwaggerUrl(rr).replace("{name}", testUrlName)
269-
270-
//Lets validate that the swagger we get from the create contains the correct info.
271-
rr = apiGet(basepathOrApiName = Some(apiName))
272-
rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
273-
274-
val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
275-
params.size should be(1)
276-
validateParameter(params(0).asJsObject, "name", "path", true, "string", "Default description for 'name'")
277-
278-
//Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
279-
val apiToInvoke = s"$swaggerApiUrl"
280-
println(s"Invoking: '${apiToInvoke}'")
281-
val response = whisk.utils.retry({
282-
val response = RestAssured.given().config(getSslConfig()).get(s"$apiToInvoke")
283-
response.statusCode should be(200)
284-
response
285-
}, 6, Some(2.second))
286-
val jsonResponse = response.body.asString.parseJson.asJsObject
287-
288-
jsonResponse.fields("__ow_path").toString should include (testRelPathGet)
289-
} finally {
290-
apiDelete(basepathOrApiName = apiName)
291-
}
258+
}
259+
try {
260+
//Create the API
261+
var rr: RunResult = apiCreate(
262+
basepath = Some(apiName),
263+
relpath = Some(testRelPath),
264+
operation = Some(testUrlOp),
265+
action = Some(actionName),
266+
responsetype = Some("http"))
267+
verifyApiCreated(rr)
268+
269+
//Get the api so we can create the swagger from the returned output
270+
rr = apiGet(basepathOrApiName = Some(apiName))
271+
rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
272+
val swaggerFile = writeSwaggerFile(rr)
273+
274+
//Delete the api so we can re-create it using the swagger
275+
rr = apiDelete(basepathOrApiName = apiName)
276+
verifyApiDeleted(rr)
277+
278+
//Create the api using the swagger file.
279+
rr = apiCreate(swagger = Some(swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT)
280+
verifyApiCreated(rr)
281+
val swaggerApiUrl = getSwaggerUrl(rr).replace("{name}", testUrlName)
282+
283+
//Lets validate that the swagger we get from the create contains the correct info.
284+
rr = apiGet(basepathOrApiName = Some(apiName))
285+
rr.stdout should include regex (s"""target-url.*${actionName}.http${reqPath}""")
286+
287+
val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
288+
params.size should be(1)
289+
validateParameter(params(0).asJsObject, "name", "path", true, "string", "Default description for 'name'")
290+
291+
//Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
292+
val apiToInvoke = s"$swaggerApiUrl"
293+
println(s"Invoking: '${apiToInvoke}'")
294+
val response = whisk.utils.retry({
295+
val response = RestAssured.given().config(getSslConfig()).get(s"$apiToInvoke")
296+
response.statusCode should be(200)
297+
response
298+
}, 6, Some(2.second))
299+
val jsonResponse = response.body.asString.parseJson.asJsObject
300+
301+
jsonResponse.fields("__ow_path").toString should include(testRelPathGet)
302+
} finally {
303+
apiDelete(basepathOrApiName = apiName)
304+
}
292305
}
293306

294307
it should "reject an api commands with an invalid path parameter" in {
@@ -493,7 +506,6 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
493506
}
494507
}
495508

496-
497509
it should "verify get API name " in {
498510
val testName = "CLI_APIGWTEST3"
499511
val testbasepath = "/" + testName + "_bp"

0 commit comments

Comments
 (0)