Skip to content

Commit

Permalink
Add the fundamental framework of REST invocation for test cases to re…
Browse files Browse the repository at this point in the history
…place wsk binary

Almost all the test cases in OpenWhisk are currently running based
on the wsk CLI binary. In order to separate the CLI out of OpenWhisk
core repository, we need to call REST API of OpenWhisk to access
OpenWhisk services instead of calling the wsk CLI binary command.

This PR adds the basic REST implementation for all the test cases
to use. One basic principle is to keep the changes to the existing
test cases as few as possible, so we add WskRest.scala as an equivalent
class to Wsk.scala and WskRestTestHelpers.scala as an equivalent file
to WskTestHelpers.scala for REST.

All the replacement of binary with REST will happen in an increamental fashion.
This PR only changes one existing test case in WskActionTests.scala, and
reimplements it in WskRestActionTests.scala. All the other test cases can follow
the same way to change the test cases one by one. New changes may be necessary
to the basic REST implementation as well in future to accommodate the test cases.
  • Loading branch information
Vincent Hou committed Aug 15, 2017
1 parent 4e362a3 commit 3935ef1
Show file tree
Hide file tree
Showing 5 changed files with 1,474 additions and 7 deletions.
1 change: 0 additions & 1 deletion tests/src/test/scala/common/Wsk.scala
Expand Up @@ -643,7 +643,6 @@ class WskPackage()
val params = Seq(noun, "bind", "--auth", wp.authKey, fqn(provider), fqn(name)) ++
{ parameters flatMap { p => Seq("-p", p._1, p._2.compactPrint) } } ++
{ annotations flatMap { p => Seq("-a", p._1, p._2.compactPrint) } }
println("params is " + params)
cli(wp.overrides ++ params, expectedExitCode)
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/src/test/scala/common/WskTestHelpers.scala
Expand Up @@ -160,6 +160,7 @@ trait WskTestHelpers extends Matchers {
totalWait: Duration = 30 seconds)(
check: ActivationResult => Unit)(
implicit wskprops: WskProps): Unit = {
println("check extractActivationId")
val activationId = wsk.extractActivationId(run)

withClue(s"did not find an activation id in '$run'") {
Expand Down Expand Up @@ -243,7 +244,9 @@ trait WskTestHelpers extends Matchers {

def removeCLIHeader(response: String): String = response.substring(response.indexOf("\n"))

def getJSONFromCLIResponse(response: String): JsObject = removeCLIHeader(response).parseJson.asJsObject
def getJSONFromResponse(response: String, isCli: Boolean): JsObject = {
if (isCli) removeCLIHeader(response).parseJson.asJsObject else response.parseJson.asJsObject
}

def getAdditionalTestSubject(newUser: String): WskProps = {
val wskadmin = new RunWskAdminCmd {}
Expand All @@ -259,3 +262,6 @@ trait WskTestHelpers extends Matchers {
}
}
}



0 comments on commit 3935ef1

Please sign in to comment.