Skip to content

Commit

Permalink
(WIP) Reverted sorting back to flag=alpha, !flag=time
Browse files Browse the repository at this point in the history
Changed order to sort

Fixed activations and API listing

Fixed tests

Updated API Test after removal of API-experimental

Update to WskRuleTests

Updated flag name to "--name-sort"/"-n"

Updated Docs
  • Loading branch information
underwoodb-sd-ibm committed Aug 9, 2017
1 parent aade73a commit 1df8acd
Show file tree
Hide file tree
Showing 26 changed files with 210 additions and 199 deletions.
17 changes: 15 additions & 2 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,19 @@ You can list all the actions that you have created using `wsk action list`:
```
wsk action list
actions
/guest/packageB/A private nodejs:6
/guest/C private nodejs:6
/guest/A private nodejs:6
/guest/packageA/B private nodejs:6
/guest/packageA/A private nodejs:6
/guest/B private nodejs:6
```

Here, we see actions listed in order from most to least recently updated. For easier browsing, you can use the flag `--name-sort` or `-n` to sort a list alphabetically:

```
wsk action list --name-sort
actions
/guest/A private nodejs:6
/guest/B private nodejs:6
/guest/C private nodejs:6
Expand All @@ -1035,11 +1048,11 @@ actions
/guest/packageB/A private nodejs:6
```

Here, we see actions listed in alphabetical order from namespace to package name to action name, with the default package (no specified package) listed at the top.
Notice that the list is now sorted alphabetically by namespace, then package name, and finally action name, with the default package (no specified package) listed at the top.

**Note**: The printed list is sorted alphabetically after it is received from the server. Other list flags such as `--limit` and `--skip` will be applied to the block of actions before they are received for sorting. To list actions in order by creation time, use the flag `--time`.

As you write more actions, this list gets longer and it can be helpful to group related actions into [packages](./packages.md). To filter your list of actions to just the those within a specific pacakge, you can use:
As you write more actions, this list gets longer and it can be helpful to group related actions into [packages](./packages.md). To filter your list of actions to just the those within a specific package, you can use:

```
wsk action list [PACKAGE NAME]
Expand Down
16 changes: 7 additions & 9 deletions docs/apigateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ wsk api list -f
```
```
ok: APIs
Action: deleteBooks
API Name: Book Club
Base path: /club
Path: /books
Verb: delete
URL: https://${APIHOST}:9001/api/21ef035/club/books
Action: getBooks
API Name: Book Club
Base path: /club
Expand All @@ -147,10 +141,14 @@ Action: putBooks
Path: /books
Verb: put
URL: https://${APIHOST}:9001/api/21ef035/club/books
Action: deleteBooks
API Name: Book Club
Base path: /club
Path: /books
Verb: delete
URL: https://${APIHOST}:9001/api/21ef035/club/books
```

**Note**: APIs are sorted alphabetically (by order of `Base Path`, then `Path`, and then `Verb`) by default. To sort the list by creation time, you can use the flag `--time`.

Now just for fun let's add a new book `JavaScript: The Good Parts` with a HTTP __POST__
```
curl -X POST -d '{"name":"JavaScript: The Good Parts", "isbn":"978-0596517748"}' https://${APIHOST}:9001/api/21ef035/club/books
Expand Down Expand Up @@ -213,8 +211,8 @@ wsk api list /club
```
ok: apis
Action Verb API Name URL
deleteBooks delete Book Club https://${APIHOST}:9001/api/21ef035/club/books
getBooks get Book Club https://${APIHOST}:9001/api/21ef035/club/books
postBooks post Book Club https://${APIHOST}:9001/api/21ef035/club/books
putBooks put Book Club https://${APIHOST}:9001/api/21ef035/club/books
deleteBooks delete Book Club https://${APIHOST}:9001/api/21ef035/club/books
```
14 changes: 7 additions & 7 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Several packages are registered with OpenWhisk. You can get a list of packages i
```
```
packages
/whisk.system/alarms shared
/whisk.system/cloudant shared
/whisk.system/github shared
/whisk.system/pushnotifications shared
/whisk.system/samples shared
/whisk.system/slack shared
/whisk.system/system shared
/whisk.system/alarms shared
/whisk.system/watson shared
/whisk.system/weather shared
/whisk.system/websocket shared
/whisk.system/weather shared
/whisk.system/system shared
/whisk.system/utils shared
/whisk.system/slack shared
/whisk.system/samples shared
/whisk.system/github shared
/whisk.system/pushnotifications shared
```

2. Get a list of entities in the `/whisk.system/cloudant` package.
Expand Down
20 changes: 10 additions & 10 deletions tests/src/test/scala/common/Wsk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ trait ListOrGetFromCollection extends FullyQualifiedNames {
def list(
namespace: Option[String] = None,
limit: Option[Int] = None,
time: Option[Boolean] = None,
nameSort: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT)(
implicit wp: WskProps): RunResult = {
val params = Seq(noun, "list", resolve(namespace), "--auth", wp.authKey) ++
{ limit map { l => Seq("--limit", l.toString) } getOrElse Seq() } ++
{ time map { t => Seq("--time") } getOrElse Seq() }
{ nameSort map { n => Seq("--name-sort") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode)
}

Expand Down Expand Up @@ -694,10 +694,10 @@ class WskNamespace()
*/
def list(
expectedExitCode: Int = SUCCESS_EXIT,
time: Option[Boolean] = None)(
nameSort: Option[Boolean] = None)(
implicit wp: WskProps): RunResult = {
val params = Seq(noun, "list", "--auth", wp.authKey) ++
{ time map { o => Seq("--time") } getOrElse Seq() }
{ nameSort map { n => Seq("--name-sort") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode)
}

Expand All @@ -724,9 +724,9 @@ class WskNamespace()
def get(
namespace: Option[String] = None,
expectedExitCode: Int,
time: Option[Boolean] = None)(
nameSort: Option[Boolean] = None)(
implicit wp: WskProps): RunResult = {
val params = { time map { t => Seq("--time") } getOrElse Seq() }
val params = { nameSort map { n => Seq("--name-sort") } getOrElse Seq() }
cli(wp.overrides ++ Seq(noun, "get", resolve(namespace), "--auth", wp.authKey) ++ params, expectedExitCode)
}
}
Expand Down Expand Up @@ -825,7 +825,7 @@ class WskApiExperimental extends RunWskCmd {
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
time: Option[Boolean] = None,
nameSort: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT)(
implicit wp: WskProps): RunResult = {
val params = Seq(noun, "list", "--auth", wp.authKey) ++
Expand All @@ -835,7 +835,7 @@ class WskApiExperimental extends RunWskCmd {
{ 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() } ++
{ time map { t => Seq("--time") } getOrElse Seq() }
{ nameSort map { n => Seq("--name-sort") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode, showCmd = true)
}

Expand Down Expand Up @@ -921,7 +921,7 @@ class WskApi()
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
time: Option[Boolean] = None,
nameSort: Option[Boolean] = None,
expectedExitCode: Int = SUCCESS_EXIT,
cliCfgFile: Option[String] = None)(
implicit wp: WskProps): RunResult = {
Expand All @@ -932,7 +932,7 @@ class WskApi()
{ 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() } ++
{ time map { o => Seq("--time") } getOrElse Seq() }
{ nameSort map { n => Seq("--name-sort") } getOrElse Seq() }
cli(wp.overrides ++ params, expectedExitCode, showCmd = true, env = Map("WSK_CONFIG_FILE" -> cliCfgFile.getOrElse("")))
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/system/basic/WskBasicTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class WskBasicTests
pkg.create(name)
}
}
val original = wsk.pkg.list().stdout
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
Expand Down Expand Up @@ -491,7 +491,7 @@ class WskBasicTests
action.create(name, defaultAction)
}
}
val original = wsk.action.list().stdout
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
Expand Down Expand Up @@ -664,7 +664,7 @@ class WskBasicTests
trigger.create(name)
}
}
val original = wsk.trigger.list().stdout
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
Expand Down Expand Up @@ -849,7 +849,7 @@ class WskBasicTests
rule.create(name, trigger = triggerName, action = actionName)
}
}
val original = wsk.rule.list().stdout
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
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/system/basic/WskRuleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ class WskRuleTests

wsk.rule.disable(ruleName)
val listOutput = wsk.rule.list().stdout.lines
listOutput.find(_.contains(ruleName)).get should (include(ruleName) and include("inactive"))
listOutput.find(_.contains(ruleName2)).get should (include(ruleName2) and include("active"))
listOutput.find(_.contains(ruleName)).get should (include(ruleName) and include("inactive"))
wsk.rule.list().stdout should not include ("Unknown")
}

Expand Down
80 changes: 38 additions & 42 deletions tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ class ApiGwTests
limit: Option[Int] = None,
since: Option[Instant] = None,
full: Option[Boolean] = None,
time: 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, time, expectedExitCode, cliCfgFile)
wsk.api.list(basepathOrApiName, relpath, operation, limit, since, full, nameSort, expectedExitCode, cliCfgFile)
}

def apiGet(
Expand All @@ -163,6 +163,42 @@ class ApiGwTests

behavior of "Wsk api"

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)
}
}

it should "reject an api commands with an invalid path parameter" in {
val badpath = "badpath"

Expand Down Expand Up @@ -907,44 +943,4 @@ class ApiGwTests
var deleteresult = apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
}
}

it should "list api alphabetically by Base/Rel/Verb" in {
val actionName = "actionApiListTest"
val baseName = "/BaseTestPathApiList"

try {
// Create Actions for apis
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
for (i <- 1 to 3) {
val name = s"$actionName$i"
wsk.action.create(name = name, artifact = Some(file), web = Some("true"), expectedExitCode = SUCCESS_EXIT)
}
// Create apis
for (i <- 1 to 3) {
val base = s"$baseName$i"
val action = s"$actionName$i"
val api = apiCreate(
basepath = Some(base),
relpath = Some("/relPath"),
operation = Some("GET"),
action = Some(action),
expectedExitCode = SUCCESS_EXIT)
}
val original = apiList().stdout
val originalFull = apiList(full = 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 deleteActions = wsk.action.delete(name = s"$actionName$i", expectedExitCode = DONTCARE_EXIT)
}
}
}
}
6 changes: 3 additions & 3 deletions tools/cli/go-whisk-cli/commands/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ var actionListCmd = &cobra.Command{
return actionListError(qualifiedName.entityName, options, err)
}

orderFlag := flags.common.time
printList(actions, orderFlag)
sortByName := flags.common.nameSort
printList(actions, sortByName)

return nil
},
Expand Down Expand Up @@ -937,7 +937,7 @@ func init() {

actionListCmd.Flags().IntVarP(&flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result"))
actionListCmd.Flags().IntVarP(&flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection"))
actionListCmd.Flags().BoolVarP(&flags.common.time, "time", "t", false, wski18n.T("sorts a list by creation time, from newest to oldest"))
actionListCmd.Flags().BoolVarP(&flags.common.nameSort, "name-sort", "n", false, wski18n.T("sorts a list alphabetically by entity name; only applicable within the limit/skip returned entity block"))

actionCmd.AddCommand(
actionCreateCmd,
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/go-whisk-cli/commands/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var activationListCmd = &cobra.Command{
if options.Docs == true {
printFullActivationList(activations)
} else {
printList(activations, true) // Default sorting for Activations are by creation time, hence orderFlag is always true
printList(activations, false) // Default sorting for Activations are by creation time, hence sortByName is always false
}

return nil
Expand Down
Loading

0 comments on commit 1df8acd

Please sign in to comment.