Skip to content

Commit

Permalink
Added alphabetized sorting #
Browse files Browse the repository at this point in the history
  • Loading branch information
underwoodb-sd authored and bpoole16 committed Jun 22, 2017
1 parent b2e6a7d commit 751f458
Show file tree
Hide file tree
Showing 22 changed files with 893 additions and 109 deletions.
3 changes: 2 additions & 1 deletion docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,13 @@ You can list all the actions that you have created using:
wsk action list
```

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:
By default, listed actions will be sorted alphabetically, first by namespaces, then [packages](./packages.md), and finally by action name. To filter your list of actions to just the those within a specific pacakge, you can use:

```
wsk action list [PACKAGE NAME]
```

Side Note: Listing works the same way for actions as it does for [packages](./packages.md), [APIs](./apigateway.md), [triggers and rules](./triggers_rules.md).

## Deleting actions

Expand Down
14 changes: 8 additions & 6 deletions docs/apigateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ 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 @@ -141,14 +147,10 @@ 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
```

Side Note: APIs will be sorted alphabetically by default, first by Base path, then by Path (relative path), then by Verb. If we need to sort alphabetically by Action name, we can add the `-n` or `--sort-action` flags to do so.

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
24 changes: 12 additions & 12 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ Several packages are registered with OpenWhisk. You can get a list of packages i
$ wsk package list /whisk.system
```
```
packages
/whisk.system/cloudant shared
/whisk.system/alarms shared
/whisk.system/watson 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
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/utils shared
/whisk.system/watson shared
/whisk.system/weather shared
/whisk.system/websocket shared
```

2. Get a list of entities in the `/whisk.system/cloudant` package.
Expand Down
2 changes: 1 addition & 1 deletion docs/triggers_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ As an example, create a trigger to send user location updates, and manually fire
ok: created trigger locationUpdate
```

2. Check that you created the trigger by listing the set of triggers.
2. Check that you created the trigger by listing the set of triggers. (Side note: triggers and rules will be listed alphabetically when using the `list` command.)

```
$ wsk trigger list
Expand Down
273 changes: 273 additions & 0 deletions tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 @@ -144,6 +276,147 @@ class ApiGwEndToEndTests

behavior of "Wsk api"

it should "return a list of alphabetized api" 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 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(cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())).stdout
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
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) =>

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
Loading

0 comments on commit 751f458

Please sign in to comment.