Skip to content

Commit

Permalink
Updated docs, fixed bug when creating Rule, improved and moved tests …
Browse files Browse the repository at this point in the history
…to WskBasicTests
  • Loading branch information
underwoodb-sd-ibm committed Jun 30, 2017
1 parent 8660575 commit 4848b15
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
19 changes: 11 additions & 8 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ You can create your own namespaces if you're entitled to do so. The `/whisk.syst
### Fully qualified names

The fully qualified name of an entity is
`/namespaceName[/packageName]/entityName`. Notice that `/` is used to delimit namespaces, packages, and entities. Also, namespaces must be prefixed with a `/`.
`/namespaceName[/packageName]/entityName`. Notice that `/` is used to delimit namespaces, packages, and entities.

If the fully qualified name has three parts:
`/namespaceName/packageName/entityName`, then the namespace can be entered without a prefixed `/`; otherwise, namespaces must be prefixed with a `/`.

For convenience, the namespace can be left off if it is the user's *default namespace*.

Expand Down Expand Up @@ -219,23 +222,23 @@ The following packages are available to be used in the Node.js 6.9.1 environment
- [glob v7.1.1](https://www.npmjs.com/package/glob) - Match files using the patterns the shell uses, like stars and stuff.
- [gm v1.23.0](https://www.npmjs.com/package/gm) - GraphicsMagick and ImageMagick for Node.
- [lodash v4.17.2](https://www.npmjs.com/package/lodash) - The Lodash library exported as Node.js modules.
- [log4js v0.6.38](https://www.npmjs.com/package/log4js) - This is a conversion of the log4js framework to work with Node.
- [log4js v0.6.38](https://www.npmjs.com/package/log4js) - This is a conversion of the log4js framework to work with Node.
- [iconv-lite v0.4.15](https://www.npmjs.com/package/iconv-lite) - Pure JS character encoding conversion
- [marked v0.3.6](https://www.npmjs.com/package/marked) - A full-featured markdown parser and compiler, written in JavaScript. Built for speed.
- [merge v1.2.0](https://www.npmjs.com/package/merge) - Merge multiple objects into one, optionally creating a new cloned object.
- [merge v1.2.0](https://www.npmjs.com/package/merge) - Merge multiple objects into one, optionally creating a new cloned object.
- [moment v2.17.0](https://www.npmjs.com/package/moment) - A lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.
- [mongodb v2.2.11](https://www.npmjs.com/package/mongodb) - The official MongoDB driver for Node.js.
- [mustache v2.3.0](https://www.npmjs.com/package/mustache) - mustache.js is an implementation of the mustache template system in JavaScript.
- [nano v6.2.0](https://www.npmjs.com/package/nano) - minimalistic couchdb driver for Node.js.
- [node-uuid v1.4.7](https://www.npmjs.com/package/node-uuid) - Deprecated UUID packaged.
- [node-uuid v1.4.7](https://www.npmjs.com/package/node-uuid) - Deprecated UUID packaged.
- [nodemailer v2.6.4](https://www.npmjs.com/package/nodemailer) - Send e-mails from Node.js – easy as cake!
- [oauth2-server v2.4.1](https://www.npmjs.com/package/oauth2-server) - Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with express in Node.js.
- [openwhisk v3.3.2](https://www.npmjs.com/package/openwhisk) - JavaScript client library for the OpenWhisk platform. Provides a wrapper around the OpenWhisk APIs.
- [pkgcloud v1.4.0](https://www.npmjs.com/package/pkgcloud) - pkgcloud is a standard library for Node.js that abstracts away differences among multiple cloud providers.
- [process v0.11.9](https://www.npmjs.com/package/process) - require('process'); just like any other module.
- [pug v2.0.0-beta6](https://www.npmjs.com/package/pug) - Implements the Pug templating language.
- [redis v2.6.3](https://www.npmjs.com/package/redis) - This is a complete and feature rich Redis client for Node.js.
- [request v2.79.0](https://www.npmjs.com/package/request) - Request is designed to be the simplest way possible to make HTTP calls.
- [redis v2.6.3](https://www.npmjs.com/package/redis) - This is a complete and feature rich Redis client for Node.js.
- [request v2.79.0](https://www.npmjs.com/package/request) - Request is designed to be the simplest way possible to make HTTP calls.
- [request-promise v4.1.1](https://www.npmjs.com/package/request-promise) - The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.
- [rimraf v2.5.4](https://www.npmjs.com/package/rimraf) - The UNIX command rm -rf for node.
- [semver v5.3.0](https://www.npmjs.com/package/semver) - Supports semantic versioning.
Expand All @@ -251,10 +254,10 @@ The following packages are available to be used in the Node.js 6.9.1 environment
- [uuid v3.0.0](https://www.npmjs.com/package/uuid) - Simple, fast generation of RFC4122 UUIDS.
- [validator v6.1.0](https://www.npmjs.com/package/validator) - A library of string validators and sanitizers.
- [watson-developer-cloud v2.29.0](https://www.npmjs.com/package/watson-developer-cloud) - Node.js client library to use the Watson Developer Cloud services, a collection of APIs that use cognitive computing to solve complex problems.
- [when v3.7.7](https://www.npmjs.com/package/when) - When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim.
- [when v3.7.7](https://www.npmjs.com/package/when) - When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim.
- [winston v2.3.0](https://www.npmjs.com/package/winston) - A multi-transport async logging library for node.js. "CHILL WINSTON! ... I put it in the logs."
- [ws v1.1.1](https://www.npmjs.com/package/ws) - ws is a simple to use, blazing fast, and thoroughly tested WebSocket client and server implementation.
- [xml2js v0.4.17](https://www.npmjs.com/package/xml2js) - Simple XML to JavaScript object converter. It supports bi-directional conversion.
- [xml2js v0.4.17](https://www.npmjs.com/package/xml2js) - Simple XML to JavaScript object converter. It supports bi-directional conversion.
- [xmlhttprequest v1.8.0](https://www.npmjs.com/package/xmlhttprequest) - node-XMLHttpRequest is a wrapper for the built-in http client to emulate the browser XMLHttpRequest object.
- [yauzl v2.7.0](https://www.npmjs.com/package/yauzl) - yet another unzip library for node. For zipping.

Expand Down
28 changes: 0 additions & 28 deletions tests/src/test/scala/system/basic/WskActionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.scalatest.junit.JUnitRunner
import common.JsHelpers
import common.TestHelpers
import common.TestUtils
import common.TestUtils._
import common.Wsk
import common.WskProps
import common.WskTestHelpers
Expand All @@ -44,7 +43,6 @@ class WskActionTests
val testString = "this is a test"
val testResult = JsObject("count" -> testString.split(" ").length.toJson)
val guestNamespace = wskprops.namespace
val auth: Seq[String] = Seq("--auth", wskprops.authKey)

behavior of "Whisk actions"

Expand Down Expand Up @@ -357,30 +355,4 @@ class WskActionTests
activation.logs.get.mkString(" ") should include(s"hello $utf8")
}
}

it should "use a 3 part Fully Qualified Name without a leading '/'" in {
val packageName = "packageName"
val actionName = "actionName"
val fullQualifiedName = s"${guestNamespace}/${packageName}/${actionName}"
val file = TestUtils.getTestActionFilename("empty.js")
val validArgs: Seq[Seq[String]] = Seq(
Seq("package", "create", packageName),
Seq("action", "create", fullQualifiedName, file),
Seq("action", "update", fullQualifiedName, file),
Seq("action", "invoke", fullQualifiedName),
Seq("action", "get", fullQualifiedName),
Seq("action", "delete", fullQualifiedName)
)
val deletePkg: Seq[String] = Seq("package", "delete", packageName)
try {
validArgs foreach {
cmd =>
val stderr = wsk.cli(cmd ++ wskprops.overrides ++ auth, expectedExitCode = SUCCESS_EXIT).stderr
stderr shouldBe ""
}
} finally {
wsk.cli(deletePkg ++ wskprops.overrides ++ auth, expectedExitCode = SUCCESS_EXIT)
}
}

}
37 changes: 37 additions & 0 deletions tests/src/test/scala/system/basic/WskBasicTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class WskBasicTests
implicit val wskprops = WskProps()
val wsk = new Wsk
val defaultAction = Some(TestUtils.getTestActionFilename("hello.js"))
val guestNamespace = wskprops.namespace
val auth: Seq[String] = Seq("--auth", wskprops.authKey)

behavior of "Wsk CLI"

Expand Down Expand Up @@ -95,6 +97,41 @@ class WskBasicTests
stderr should include(errormsg)
}

it should "accept a 3 part Fully Qualified Name without a leading '/'" in {
val packageName = "packageName"
val actionName = "actionName"
val triggerName = "triggerName"
val ruleName = "ruleName"
val fullQualifiedName = s"${guestNamespace}/${packageName}/${actionName}"
val validArgs: Seq[Seq[String]] = Seq(
Seq("package", "create", packageName),
Seq("action", "create", fullQualifiedName, defaultAction.get),
Seq("action", "update", fullQualifiedName, defaultAction.get),
Seq("action", "invoke", fullQualifiedName),
Seq("trigger", "create", triggerName),
Seq("action", "get", fullQualifiedName),
Seq("rule", "create", ruleName, triggerName, fullQualifiedName),
Seq("action", "delete", fullQualifiedName)
)
val cleanUp: Seq[Seq[String]] = Seq(
Seq("package", "delete", packageName),
Seq("trigger", "delete", triggerName),
Seq("rule", "delete", ruleName)
)
try {
validArgs foreach {
cmd =>
val stderr = wsk.cli(cmd ++ wskprops.overrides ++ auth, expectedExitCode = SUCCESS_EXIT).stderr
stderr shouldBe ""
}
} finally {
cleanUp foreach {
cmd =>
wsk.cli(cmd ++ wskprops.overrides ++ auth, expectedExitCode = SUCCESS_EXIT)
}
}
}

behavior of "Wsk Package CLI"

it should "create, update, get and list a package" in withAssetCleaner(wskprops) {
Expand Down
20 changes: 15 additions & 5 deletions tools/cli/go-whisk-cli/commands/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ func (qualifiedName QualifiedName) String() string {
return strings.Join(output, "")
}

// replaceMissingLeadSlash(name) returns a (possibly fully qualified) resource name,
// inserting a leading '/' if it is of 3 parts (namespace/packageName/actionName)
// and lacking the leading '/'.
func replaceMissingLeadSlash(name string) string {
parts := strings.Split(name, "/")
if len(parts) == 3 && parts[0] != "" {
name = "/" + name
}
return name
}

/*
Parse a (possibly fully qualified) resource name into namespace and name components. If the given qualified name isNone,
then this is a default qualified name and it is resolved from properties. If the namespace is missing from the qualified
Expand All @@ -80,12 +91,10 @@ func parseQualifiedName(name string) (QualifiedName, error) {
// If name has a preceding delimiter (/), or if it has two delimiters with a leading non-empty string, then
// it contains a namespace. Otherwise the name does not specify a namespace, so default the namespace to the
// namespace value set in the properties file; if that is not set, use "_"
name = replaceMissingLeadSlash(name)
parts := strings.Split(name, "/")
if len(parts) == 3 && parts[0] != "" {
name = "/" + name
}
if strings.HasPrefix(name, "/") {
parts = strings.Split(name, "/")
//parts = strings.Split(name, "/")
qualifiedName.namespace = parts[1]

if len(parts) < 2 || len(parts) > 4 {
Expand Down Expand Up @@ -117,7 +126,7 @@ func parseQualifiedName(name string) (QualifiedName, error) {
return qualifiedName, err
}

parts = strings.Split(name, "/")
//parts = strings.Split(name, "/")
qualifiedName.entity = parts[len(parts)-1]
if len(parts) == 2 {
qualifiedName.packageName = parts[0]
Expand Down Expand Up @@ -155,6 +164,7 @@ Examples:
(/ns/pkg/foo, otherns) => /ns/pkg/foo
*/
func getQualifiedName(name string, namespace string) (string) {
name = replaceMissingLeadSlash(name)
if strings.HasPrefix(name, "/") {
return name
} else if strings.HasPrefix(namespace, "/") {
Expand Down

0 comments on commit 4848b15

Please sign in to comment.