Skip to content

Commit

Permalink
Allow CLI to sort entities by name (apache#2326)
Browse files Browse the repository at this point in the history
- Created interfaces `Printables` and `Sortables`
- Made Actions, Triggers, Packages, Rules, APIs into Printables and Sortables
- Made Activations into Printables and Sortables, Sort currently undefined
- Made alphabetic sorting default, sort by last update time with --time flag
- Changed sorting default back to last update time, --sort flag for alphabetical sorting
- Updated flag name to "--name-sort"/"-n"
- Updated Docs
- Fixed rule status printing for `wsk list` and `wsk namespace get`
  • Loading branch information
underwoodb-sd-ibm authored and rabbah committed Aug 11, 2017
1 parent 8e6254d commit 9c6c10e
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ class ApiGwTests
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
nameSort: 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, nameSort, expectedExitCode, cliCfgFile)
}

def apiGet(
Expand Down Expand Up @@ -906,4 +907,40 @@ class ApiGwTests
var deleteresult = apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
}
}

it should "list api alphabetically by Base/Rel/Verb" in {
val baseName = "/BaseTestPathApiList"
val actionName = "actionName"
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
try {
// Create Action for apis
var action = wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
println("action creation: " + action.stdout)
// Create apis
for (i <- 1 to 3) {
val base = s"$baseName$i"
var api = apiCreate(
basepath = Some(base),
relpath = Some("/relPath"),
operation = Some("GET"),
action = Some(actionName))
println("api creation: " + api.stdout)
}
val original = apiList(nameSort = Some(true)).stdout
val originalFull = apiList(full = Some(true), nameSort = Some(true)).stdout
val scalaSorted = List(s"${baseName}1" + "/", s"${baseName}2" + "/", s"${baseName}3" + "/")
val regex = s"${baseName}[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
for (i <- 1 to 3) {
val deleteApis = apiDelete(basepathOrApiName = s"${baseName}$i", expectedExitCode = DONTCARE_EXIT)
}
val deleteAction = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
}
}
}
135 changes: 135 additions & 0 deletions tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,141 @@ class WskBasicUsageTests
}, 5, Some(1 second))
}

it should "return a list of alphabetized actions" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
// Declare 4 actions, create them out of alphabetical order
val actionName = "actionAlphaTest"
for (i <- 1 to 3) {
val name = s"$actionName$i"
assetHelper.withCleaner(wsk.action, name) {
(action, name) =>
action.create(name, defaultAction)
}
}
retry({
val original = wsk.action.list(nameSort = Some(true)).stdout
// Create list with action names in correct order
val scalaSorted = List(s"${actionName}1", s"${actionName}2", s"${actionName}3")
// Filter out everything not previously created
val regex = s"${actionName}[1-3]".r
// Retrieve action names into list as found in original
val list = (regex.findAllMatchIn(original)).toList
scalaSorted.toString shouldEqual list.toString
}, 5, Some(1 second))
}

it should "return an alphabetized list with default package actions on top" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
// Declare 4 actions, create them out of alphabetical order
val actionName = "actionPackageAlphaTest"
val packageName = "packageAlphaTest"
assetHelper.withCleaner(wsk.action, actionName) {
(action, actionName) =>
action.create(actionName, defaultAction)
}
assetHelper.withCleaner(wsk.pkg, packageName) {
(pkg, packageName) =>
pkg.create(packageName)
}
for (i <- 1 to 3) {
val name = s"${packageName}/${actionName}$i"
assetHelper.withCleaner(wsk.action, name) {
(action, name) =>
action.create(name, defaultAction)
}
}
retry({
val original = wsk.action.list(nameSort = Some(true)).stdout
// Create list with action names in correct order
val scalaSorted = List(s"$actionName", s"${packageName}/${actionName}1", s"${packageName}/${actionName}2", s"${packageName}/${actionName}3")
// Filter out everything not previously created
val regexNoPackage = s"$actionName".r
val regexWithPackage = s"${packageName}/${actionName}[1-3]".r
// Retrieve action names into list as found in original
val list = regexNoPackage.findFirstIn(original).get :: (regexWithPackage.findAllMatchIn(original)).toList
scalaSorted.toString shouldEqual list.toString
}, 5, Some(1 second))
}

it should "return a list of alphabetized packages" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
// Declare 3 packages, create them out of alphabetical order
val packageName = "pkgAlphaTest"
for (i <- 1 to 3) {
val name = s"$packageName$i"
assetHelper.withCleaner(wsk.pkg, name) {
(pkg, name) =>
pkg.create(name)
}
}
retry({
val original = wsk.pkg.list(nameSort = Some(true)).stdout
// Create list with package names in correct order
val scalaSorted = List(s"${packageName}1", s"${packageName}2", s"${packageName}3")
// Filter out everything not previously created
val regex = s"${packageName}[1-3]".r
// Retrieve package names into list as found in original
val list = (regex.findAllMatchIn(original)).toList
scalaSorted.toString shouldEqual list.toString
}, 5, Some(1 second))
}

it should "return a list of alphabetized triggers" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
// Declare 4 triggers, create them out of alphabetical order
val triggerName = "triggerAlphaTest"
for (i <- 1 to 3) {
val name = s"$triggerName$i"
assetHelper.withCleaner(wsk.trigger, name) {
(trigger, name) =>
trigger.create(name)
}
}
retry({
val original = wsk.trigger.list(nameSort = Some(true)).stdout
// Create list with trigger names in correct order
val scalaSorted = List(s"${triggerName}1", s"${triggerName}2", s"${triggerName}3")
// Filter out everything not previously created
val regex = s"${triggerName}[1-3]".r
// Retrieve trigger names into list as found in original
val list = (regex.findAllMatchIn(original)).toList
scalaSorted.toString shouldEqual list.toString
}, 5, Some(1 second))
}

it should "return a list of alphabetized rules" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
// Declare a trigger and an action for the purposes of creating rules
val triggerName = "listRulesTrigger"
val actionName = "listRulesAction"

assetHelper.withCleaner(wsk.trigger, triggerName) {
(trigger, name) => trigger.create(name)
}
assetHelper.withCleaner(wsk.action, actionName) {
(action, name) => action.create(name, defaultAction)
}
// Declare 3 rules, create them out of alphabetical order
val ruleName = "ruleAlphaTest"
for (i <- 1 to 3) {
val name = s"$ruleName$i"
assetHelper.withCleaner(wsk.rule, name) {
(rule, name) =>
rule.create(name, trigger = triggerName, action = actionName)
}
}
retry({
val original = wsk.rule.list(nameSort = Some(true)).stdout
// Create list with rule names in correct order
val scalaSorted = List(s"${ruleName}1", s"${ruleName}2", s"${ruleName}3")
// Filter out everything not previously created
val regex = s"${ruleName}[1-3]".r
// Retrieve rule names into list as found in original
val list = (regex.findAllMatchIn(original)).toList
scalaSorted.toString shouldEqual list.toString
})
}

behavior of "Wsk params and annotations"

it should "reject commands that are executed with invalid JSON for annotations and parameters" in {
Expand Down

0 comments on commit 9c6c10e

Please sign in to comment.