Skip to content

Commit

Permalink
Added automated testing for API sort, with and without --sort-action …
Browse files Browse the repository at this point in the history
…flag
  • Loading branch information
underwoodb-sd committed Jun 20, 2017
1 parent 73fe512 commit 528a38c
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 32 deletions.
254 changes: 226 additions & 28 deletions tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,138 @@ class ApiGwEndToEndTests

behavior of "Wsk api-experimental"

it should "return a list of alphabetized api-experimental" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>

val actionName1 = "actionName1"
val actionName2 = "actionName2"
val actionName3 = "actionName3"
val base1 = "/BaseTestPath1"
val base2 = "/BaseTestPath2"
val base3 = "/BaseTestPath3"

try {
//Create Actions for apiexperimentals
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create apiexperimentals
println("Create api-experimental: Base Path " + base2)
wsk.apiexperimental.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2)
)
println("Create api-experimental: Base Path " + base1)
wsk.apiexperimental.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1)
)
println("Create api-experimental: Base Path " + base3)
wsk.apiexperimental.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
operation = Some("head"),
action = Some(actionName3)
)
val original = wsk.apiexperimental.list().stdout
val originalFull = wsk.apiexperimental.list(full = Some(true)).stdout
val scalaSorted = List(base1 + "/", base2 + "/", base3 + "/")
val regex = "/BaseTestPath[1-3]/".r
val list = (regex.findAllMatchIn(original)).toList
val listFull = (regex.findAllMatchIn(originalFull)).toList
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up apiexperimentals
println("Delete api-experimental: Base Path " + base1)
wsk.apiexperimental.delete(base1, expectedExitCode = DONTCARE_EXIT)
println("Delete api-experimental: Base Path " + base2)
wsk.apiexperimental.delete(base2, expectedExitCode = DONTCARE_EXIT)
println("Delete api-experimental: Base Path " + base3)
wsk.apiexperimental.delete(base3, expectedExitCode = DONTCARE_EXIT)
}
}

it should "return a list of alphabetized api-experimental by action name" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>

val actionName1 = "actionName1"
val actionName2 = "actionName2"
val actionName3 = "actionName3"
val base1 = "/BaseTestPath1"
val base2 = "/BaseTestPath2"
val base3 = "/BaseTestPath3"

try {
//Create Actions for api-experimentals
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create api-experimentals
println("Create api-experimental: Base Path " + base2)
wsk.apiexperimental.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2)
)
println("Create apiexperimental: Base Path " + base1)
wsk.apiexperimental.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1)
)
println("Create apiexperimental: Base Path " + base3)
wsk.apiexperimental.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
operation = Some("head"),
action = Some(actionName3)
)
val original = wsk.apiexperimental.list(sortAction = Some(true)).stdout
val originalFull = wsk.apiexperimental.list(full = Some(true), sortAction = Some(true)).stdout
val scalaSorted = List(actionName1, actionName2, actionName3)
val regex = "actionName[1-3]".r
val list = (regex.findAllMatchIn(original)).toList
val listFull = (regex.findAllMatchIn(originalFull)).toList
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up apiexperimentals
println("Delete apiexperimental: Base Path " + base1)
wsk.apiexperimental.delete(base1, expectedExitCode = DONTCARE_EXIT)
println("Delete apiexperimental: Base Path " + base2)
wsk.apiexperimental.delete(base2, expectedExitCode = DONTCARE_EXIT)
println("Delete apiexperimental: Base Path " + base3)
wsk.apiexperimental.delete(base3, expectedExitCode = DONTCARE_EXIT)
}
}

it should s"create an API and successfully invoke that API" in {
val testName = "APIGWe_HEALTHTEST1"
val testbasepath = "/" + testName + "_bp"
Expand Down Expand Up @@ -154,70 +286,136 @@ class ApiGwEndToEndTests
val base3 = "/BaseTestPath3"

try {
//Create Actions for Apis
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, annotations = Map("web-export" -> true.toJson))
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, annotations = Map("web-export" -> true.toJson))
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, annotations = Map("web-export" -> true.toJson))
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
/*var rr = wsk.api.create(
basepath = Some(base1),
relpath = Some("/relpathbeta"),
operation = Some("get"),
action = Some(actionName),
apiname = Some(base1),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)*/
//Create Apis
println("Create API: Base Path " + base2)
wsk.api.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2),
apiname = Some(base2),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base1)
wsk.api.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1),
apiname = Some(base1),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base3)
wsk.api.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
operation = Some("head"),
action = Some(actionName3),
apiname = Some(base3),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)

val original = wsk.api.list(cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())).stdout
//Create list with action names in correct order
val scalaSorted = List(base1, base2, base3)
//Filter out everything not previously created
val regex = "BaseTestPath[1-3]".r
//Retrieve action names into list as found in original
val originalFull = wsk.api.list(full = Some(true), cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())).stdout
val scalaSorted = List(base1 + "/", base2 + "/", base3 + "/")
val regex = "/BaseTestPath[1-3]/".r
val list = (regex.findAllMatchIn(original)).toList
println(original)
val listFull = (regex.findAllMatchIn(originalFull)).toList
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up Apis
println("Delete API: Base Path " + base1)
wsk.api.delete(base1, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base2)
wsk.api.delete(base2, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base3)
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
}
}

it should "return a list of alphabetized api by action name" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>

wsk.api.delete(base1, expectedExitCode = DONTCARE_EXIT)
wsk.api.delete(base2, expectedExitCode = DONTCARE_EXIT)
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT)
val actionName1 = "actionName1"
val actionName2 = "actionName2"
val actionName3 = "actionName3"
val base1 = "/BaseTestPath1"
val base2 = "/BaseTestPath2"
val base3 = "/BaseTestPath3"

try {
//Create Actions for Apis
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
println("Create Action: " + actionName1)
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName2)
assetHelper.withCleaner(wsk.action, actionName2) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
println("Create Action: " + actionName3)
assetHelper.withCleaner(wsk.action, actionName3) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
}
//Create Apis
println("Create API: Base Path " + base2)
wsk.api.create(
basepath = Some(base2),
relpath = Some("/relPath1"),
operation = Some("get"),
action = Some(actionName2),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base1)
wsk.api.create(
basepath = Some(base1),
relpath = Some("/relPath2"),
operation = Some("delete"),
action = Some(actionName1),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
println("Create API: Base Path " + base3)
wsk.api.create(
basepath = Some(base3),
relpath = Some("/relPath3"),
operation = Some("head"),
action = Some(actionName3),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
val original = wsk.api.list(sortAction = Some(true),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())).stdout
val originalFull = wsk.api.list(full = Some(true), sortAction = Some(true),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())).stdout
val scalaSorted = List(actionName1, actionName2, actionName3)
val regex = "actionName[1-3]".r
val list = (regex.findAllMatchIn(original)).toList
val listFull = (regex.findAllMatchIn(originalFull)).toList
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up Apis
println("Delete API: Base Path " + base1)
wsk.api.delete(base1, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base2)
wsk.api.delete(base2, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
println("Delete API: Base Path " + base3)
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
}
}


it should s"create an API and successfully invoke that API" in {
val testName = "APIGW_HEALTHTEST1"
val testbasepath = "/" + testName + "_bp"
Expand Down
8 changes: 6 additions & 2 deletions tests/src/test/scala/common/Wsk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ class WskApiExperimental extends RunWskCmd {
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
sortAction: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT)(
implicit wp: WskProps): RunResult = {
val params = Seq(noun, "list", "--auth", wp.authKey) ++
Expand All @@ -799,7 +800,8 @@ class WskApiExperimental extends RunWskCmd {
{ operation map { o => Seq(o) } getOrElse Seq() } ++
{ limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++
{ since map { i => Seq("--since", i.toEpochMilli.toString) } getOrElse Seq() } ++
{ full map { r => Seq("--full") } getOrElse Seq() }
{ full map { r => Seq("--full") } getOrElse Seq() } ++
{ sortAction map{ n => Seq("--sort-action") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode, showCmd = true)
}

Expand Down Expand Up @@ -885,6 +887,7 @@ class WskApi()
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
sortAction: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT,
cliCfgFile: Option[String] = None)(
implicit wp: WskProps): RunResult = {
Expand All @@ -894,7 +897,8 @@ class WskApi()
{ operation map { o => Seq(o) } getOrElse Seq() } ++
{ limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++
{ since map { i => Seq("--since", i.toEpochMilli.toString) } getOrElse Seq() } ++
{ full map { r => Seq("--full") } getOrElse Seq() }
{ full map { r => Seq("--full") } getOrElse Seq() } ++
{ sortAction map { n => Seq("--sort-action") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode, showCmd = true, env=Map("WSK_CONFIG_FILE" -> cliCfgFile.getOrElse("")))
}

Expand Down
6 changes: 4 additions & 2 deletions tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ class ApiGwTests
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
sortAction: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT): RunResult = {

checkThrottle()
wsk.apiexperimental.list(basepathOrApiName, relpath, operation, limit, since, full, expectedExitCode)
wsk.apiexperimental.list(basepathOrApiName, relpath, operation, limit, since, full, sortAction, expectedExitCode)
}

def apiGetExperimental(
Expand Down Expand Up @@ -176,11 +177,12 @@ class ApiGwTests
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
sortAction: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT,
cliCfgFile: Option[String] = Some(cliWskPropsFile.getCanonicalPath())): RunResult = {

checkThrottle()
wsk.api.list(basepathOrApiName, relpath, operation, limit, since, full, expectedExitCode, cliCfgFile)
wsk.api.list(basepathOrApiName, relpath, operation, limit, since, full, sortAction, expectedExitCode, cliCfgFile)
}

def apiGet(
Expand Down

0 comments on commit 528a38c

Please sign in to comment.