You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by mr...@apache.org on 2018/02/01 21:35:43 UTC
[incubator-openwhisk-wskdeploy] branch master updated: Go format
source code (#700)
This is an automated email from the ASF dual-hosted git repository.
mrutkowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git
The following commit(s) were added to refs/heads/master by this push:
new ae06ebe Go format source code (#700)
ae06ebe is described below
commit ae06ebeb9eaf821781f90c1f518d2377cac96015
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Thu Feb 1 16:35:41 2018 -0500
Go format source code (#700)
* Go format source code
- Fail Traivs if source code is not formatted properly
* Format source code
---
.travis.yml | 3 +
cmd/add.go | 86 +-
cmd/init.go | 30 +-
cmd/publish.go | 38 +-
cmd/report.go | 16 +-
cmd/root.go | 24 +-
cmd/undeploy.go | 10 +-
cmd/version.go | 4 +-
deployers/deploymentreader.go | 28 +-
deployers/deploymentreader_test.go | 15 +-
deployers/filesystemreader.go | 10 +-
deployers/manifestreader.go | 2 +-
deployers/manifestreader_test.go | 2 +-
deployers/servicedeployer.go | 76 +-
deployers/whiskclient.go | 24 +-
deployers/whiskclient_test.go | 24 +-
parsers/deploy_parser.go | 15 +-
parsers/manifest_parser.go | 71 +-
parsers/manifest_parser_test.go | 2566 ++++++++++----------
parsers/parameters.go | 163 +-
parsers/yamlparser.go | 54 +-
.../owbp-cloudant-trigger_test.go | 13 +-
.../integration/alarmtrigger/alarmtrigger_test.go | 26 +-
.../src/integration/apigateway/apigateway_test.go | 4 +-
tests/src/integration/cloudant/cloudant_test.go | 9 +-
tests/src/integration/common/wskdeploy.go | 10 +-
.../src/integration/dependency/dependency_test.go | 23 +-
tests/src/integration/flagstests/flags_test.go | 28 +-
.../managed-deployment/managed-deployment_test.go | 1 -
.../src/integration/runtimetests/runtimes_test.go | 9 +-
.../integration/triggerrule/triggerrule_test.go | 5 +-
.../validate-action-annotations_test.go | 5 +-
.../validate-application-and-project_test.go | 5 +-
.../validate-bind-inputs-anno_test.go | 4 +-
.../validate-file-extensions_test.go | 13 +-
.../validateSequencesCreation_test.go | 49 +-
tests/src/integration/webaction/webaction_test.go | 1 -
tests/src/integration/zipaction/zipaction_test.go | 22 +-
utils/conversion.go | 4 +-
utils/dependencies.go | 26 +-
utils/fileoperations.go | 38 +-
utils/fileoperations_test.go | 200 +-
utils/flags.go | 10 +-
utils/managedannotations.go | 13 +-
utils/misc_test.go | 12 +-
utils/qualifiedname.go | 2 +-
utils/runtimes.go | 5 +-
utils/validation.go | 2 +-
wskderrors/wskdeployerror.go | 110 +-
wskderrors/wskdeployerror_test.go | 26 +-
wskenv/environment.go | 4 +-
wskenv/environment_test.go | 38 +-
wski18n/detection.go | 24 +-
wski18n/i18n.go | 152 +-
wski18n/i18n_ids.go | 302 +--
wski18n/i18n_ids_test.go | 2 +-
wski18n/i18n_resources.go | 42 +-
wskprint/console.go | 31 +-
58 files changed, 2249 insertions(+), 2282 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index f297d3c..3c24eeb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -13,6 +13,9 @@ install:
- go get -u github.com/golang/lint/golint
- go get -u github.com/stretchr/testify
- go get -u github.com/tools/godep
+before_script:
+- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/)
+- test -z "$(gofmt -s -l $(echo $GO_FILES))"
script:
- echo $TRAVIS
- echo $TRAVIS_PULL_REQUEST
diff --git a/cmd/add.go b/cmd/add.go
index 24eab52..3decdb1 100644
--- a/cmd/add.go
+++ b/cmd/add.go
@@ -19,62 +19,62 @@ package cmd
import (
"bufio"
- "os"
- "github.com/spf13/cobra"
"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "github.com/spf13/cobra"
+ "os"
)
// addCmd represents the add command
var addCmd = &cobra.Command{
- Use: "add",
- SuggestFor: []string {"insert"},
- Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ADD),
+ Use: "add",
+ SuggestFor: []string{"insert"},
+ Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ADD),
}
// action represents the `add action` command
var actionCmd = &cobra.Command{
- Use: "action",
+ Use: "action",
Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ADD_X_key_X,
map[string]interface{}{wski18n.KEY_KEY: parsers.YAML_KEY_ACTION}),
RunE: func(cmd *cobra.Command, args []string) error {
maniyaml, err := parsers.ReadOrCreateManifest()
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
- reader := bufio.NewReader(os.Stdin)
- action := parsers.Action{}
+ reader := bufio.NewReader(os.Stdin)
+ action := parsers.Action{}
- for {
- action.Name = utils.Ask(reader, wski18n.NAME_ACTION, "")
+ for {
+ action.Name = utils.Ask(reader, wski18n.NAME_ACTION, "")
- // Check action name is unique
- if _, ok := maniyaml.Package.Actions[action.Name]; !ok {
- break
- }
+ // Check action name is unique
+ if _, ok := maniyaml.Package.Actions[action.Name]; !ok {
+ break
+ }
- warnMsg := wski18n.T(wski18n.ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X,
- map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_ACTION,
- wski18n.KEY_NAME: action.Name})
- wskprint.PrintOpenWhiskWarning(warnMsg)
- }
+ warnMsg := wski18n.T(wski18n.ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X,
+ map[string]interface{}{
+ wski18n.KEY_KEY: parsers.YAML_KEY_ACTION,
+ wski18n.KEY_NAME: action.Name})
+ wskprint.PrintOpenWhiskWarning(warnMsg)
+ }
- // TODO() use dynamic/programmatic way to get default runtime (not hardcoded)
- // TODO() And List all supported runtime names (values) (via API)
- action.Runtime = utils.Ask(reader, wski18n.NAME_RUNTIME, "nodejs:6")
- maniyaml.Package.Actions[action.Name] = action
+ // TODO() use dynamic/programmatic way to get default runtime (not hardcoded)
+ // TODO() And List all supported runtime names (values) (via API)
+ action.Runtime = utils.Ask(reader, wski18n.NAME_RUNTIME, "nodejs:6")
+ maniyaml.Package.Actions[action.Name] = action
- // Create directory structure before update manifest, as a way
- // to check the action name is a valid path name
- err = os.MkdirAll("actions/"+action.Name, 0777)
+ // Create directory structure before update manifest, as a way
+ // to check the action name is a valid path name
+ err = os.MkdirAll("actions/"+action.Name, 0777)
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
return parsers.Write(maniyaml, utils.ManifestFileNameYaml)
},
@@ -82,14 +82,14 @@ var actionCmd = &cobra.Command{
// trigger represents the `add trigger` command
var triggerCmd = &cobra.Command{
- Use: "trigger",
+ Use: "trigger",
Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ADD_X_key_X,
map[string]interface{}{wski18n.KEY_KEY: parsers.YAML_KEY_TRIGGER}),
RunE: func(cmd *cobra.Command, args []string) error {
maniyaml, err := parsers.ReadOrCreateManifest()
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
reader := bufio.NewReader(os.Stdin)
trigger := parsers.Trigger{}
@@ -104,7 +104,7 @@ var triggerCmd = &cobra.Command{
warnMsg := wski18n.T(wski18n.ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_TRIGGER,
+ wski18n.KEY_KEY: parsers.YAML_KEY_TRIGGER,
wski18n.KEY_NAME: trigger.Name})
wskprint.PrintOpenWhiskWarning(warnMsg)
}
@@ -118,14 +118,14 @@ var triggerCmd = &cobra.Command{
// rule represents the `add rule` command
var ruleCmd = &cobra.Command{
- Use: "rule",
+ Use: "rule",
Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ADD_X_key_X,
map[string]interface{}{wski18n.KEY_KEY: parsers.YAML_KEY_RULE}),
RunE: func(cmd *cobra.Command, args []string) error {
maniyaml, err := parsers.ReadOrCreateManifest()
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
reader := bufio.NewReader(os.Stdin)
rule := parsers.Rule{}
@@ -140,7 +140,7 @@ var ruleCmd = &cobra.Command{
warnMsg := wski18n.T(wski18n.ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_RULE,
+ wski18n.KEY_KEY: parsers.YAML_KEY_RULE,
wski18n.KEY_NAME: rule.Name})
wskprint.PrintOpenWhiskWarning(warnMsg)
}
diff --git a/cmd/init.go b/cmd/init.go
index 871ef1b..21098c2 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -24,18 +24,18 @@ import (
"github.com/spf13/cobra"
"os"
"path/filepath"
- "strings"
+ "strings"
)
var initCmd = &cobra.Command{
- Use: "init",
- SuggestFor: []string {"initialize"},
- Short: "Init helps you create a manifest file on OpenWhisk",
+ Use: "init",
+ SuggestFor: []string{"initialize"},
+ Short: "Init helps you create a manifest file on OpenWhisk",
RunE: func(cmd *cobra.Command, args []string) error {
maniyaml, err := parsers.ReadOrCreateManifest()
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
reader := bufio.NewReader(os.Stdin)
@@ -44,22 +44,22 @@ var initCmd = &cobra.Command{
maniyaml.Package.License = askLicense(reader, maniyaml.Package.License)
err = parsers.Write(maniyaml, utils.ManifestFileNameYaml)
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
// Create directory structure
os.Mkdir("actions", 0777)
- return nil
+ return nil
},
}
func askName(reader *bufio.Reader, def string) string {
if len(def) == 0 {
- path := strings.TrimSpace(utils.Flags.ProjectPath)
- if (len(path) == 0) {
- path = utils.DEFAULT_PROJECT_PATH
- }
+ path := strings.TrimSpace(utils.Flags.ProjectPath)
+ if len(path) == 0 {
+ path = utils.DEFAULT_PROJECT_PATH
+ }
abspath, _ := filepath.Abs(path)
def = filepath.Base(abspath)
}
diff --git a/cmd/publish.go b/cmd/publish.go
index 22020ba..0f8d806 100644
--- a/cmd/publish.go
+++ b/cmd/publish.go
@@ -19,24 +19,24 @@ package cmd
import (
"bufio"
+ "github.com/apache/incubator-openwhisk-wskdeploy/parsers"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "github.com/spf13/cobra"
"net/http"
"net/url"
"os"
"path"
"strings"
- "github.com/spf13/cobra"
- "github.com/apache/incubator-openwhisk-wskdeploy/parsers"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
)
// publishCmd represents the publish command
var publishCmd = &cobra.Command{
- Use: "publish",
- SuggestFor: []string{"publicize"},
- Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_PUBLISH),
- Long: wski18n.T(wski18n.ID_CMD_DESC_LONG_PUBLISH),
+ Use: "publish",
+ SuggestFor: []string{"publicize"},
+ Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_PUBLISH),
+ Long: wski18n.T(wski18n.ID_CMD_DESC_LONG_PUBLISH),
RunE: func(cmd *cobra.Command, args []string) error {
// Get registry location
userHome := utils.GetHomeDirectory()
@@ -52,8 +52,8 @@ var publishCmd = &cobra.Command{
wskprint.PrintOpenWhiskError(
wski18n.T(wski18n.ID_ERR_URL_INVALID_X_urltype_X_url_X_filetype_X,
map[string]interface{}{
- wski18n.KEY_URL_TYPE: wski18n.REGISTRY,
- wski18n.KEY_URL: "",
+ wski18n.KEY_URL_TYPE: wski18n.REGISTRY,
+ wski18n.KEY_URL: "",
wski18n.KEY_FILE_TYPE: wski18n.WHISK_PROPS}))
// TODO() should only read if interactive mode is on
@@ -72,7 +72,7 @@ var publishCmd = &cobra.Command{
wski18n.T(wski18n.ID_ERR_URL_MALFORMED_X_urltype_X_url_X,
map[string]interface{}{
wski18n.KEY_URL_TYPE: wski18n.REGISTRY,
- wski18n.KEY_URL: registry}))
+ wski18n.KEY_URL: registry}))
}
configs["REGISTRY"] = registry
@@ -94,18 +94,18 @@ var publishCmd = &cobra.Command{
wskprint.PrintOpenWhiskError(
wski18n.T(wski18n.ID_ERR_URL_INVALID_X_urltype_X_url_X_filetype_X,
map[string]interface{}{
- wski18n.KEY_URL_TYPE: wski18n.REPOSITORY,
- wski18n.KEY_URL: repoURL,
+ wski18n.KEY_URL_TYPE: wski18n.REPOSITORY,
+ wski18n.KEY_URL: repoURL,
wski18n.KEY_FILE_TYPE: wski18n.MANIFEST}))
return nil
}
- repo := paths[l - 1]
- owner := paths[l - 2]
+ repo := paths[l-1]
+ owner := paths[l-2]
// Send HTTP request
client := &http.Client{}
- request, err := http.NewRequest("PUT", registry + "?owner=" + owner + "&repo=" + repo, nil)
+ request, err := http.NewRequest("PUT", registry+"?owner="+owner+"&repo="+repo, nil)
if err != nil {
return err
}
@@ -118,8 +118,8 @@ var publishCmd = &cobra.Command{
wskprint.PrintOpenWhiskError(
wski18n.T(wski18n.ID_ERR_URL_INVALID_X_urltype_X_url_X_filetype_X,
map[string]interface{}{
- wski18n.KEY_URL_TYPE: wski18n.REPOSITORY,
- wski18n.KEY_URL: "",
+ wski18n.KEY_URL_TYPE: wski18n.REPOSITORY,
+ wski18n.KEY_URL: "",
wski18n.KEY_FILE_TYPE: wski18n.MANIFEST}))
}
return nil
diff --git a/cmd/report.go b/cmd/report.go
index 37a361d..c1159e6 100644
--- a/cmd/report.go
+++ b/cmd/report.go
@@ -19,15 +19,15 @@ package cmd
import (
"fmt"
- "path"
- "sync"
- "os"
- "github.com/spf13/cobra"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "github.com/spf13/cobra"
+ "os"
+ "path"
+ "sync"
)
var wskpropsPath string
@@ -37,9 +37,9 @@ var wg sync.WaitGroup
// reportCmd represents the report command
var reportCmd = &cobra.Command{
- Use: "report",
- SuggestFor: []string{"list"},
- Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_REPORT),
+ Use: "report",
+ SuggestFor: []string{"list"},
+ Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_REPORT),
RunE: func(cmd *cobra.Command, args []string) error {
if wskpropsPath != "" {
config, _ := deployers.NewWhiskConfig(wskpropsPath, utils.Flags.DeploymentPath, utils.Flags.ManifestPath, false)
diff --git a/cmd/root.go b/cmd/root.go
index 1600802..a2da30b 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -21,18 +21,18 @@ import (
"encoding/json"
"errors"
"fmt"
+ "github.com/apache/incubator-openwhisk-client-go/whisk"
+ "github.com/apache/incubator-openwhisk-wskdeploy/deployers"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "github.com/spf13/cobra"
"os"
"path"
"path/filepath"
"regexp"
"strings"
- "github.com/spf13/cobra"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
- "github.com/apache/incubator-openwhisk-client-go/whisk"
- "github.com/apache/incubator-openwhisk-wskdeploy/deployers"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
)
var stderr = ""
@@ -40,11 +40,11 @@ var stdout = ""
// TODO(#683) short and long desc. should be translated for i18n
var RootCmd = &cobra.Command{
- Use: "wskdeploy",
- SilenceErrors: true,
- SilenceUsage: true,
- Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ROOT),
- Long: wski18n.T(wski18n.ID_CMD_DESC_LONG_ROOT),
+ Use: "wskdeploy",
+ SilenceErrors: true,
+ SilenceUsage: true,
+ Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_ROOT),
+ Long: wski18n.T(wski18n.ID_CMD_DESC_LONG_ROOT),
// Uncomment the following line if your bare application
// has an action associated with it:
RunE: RootCmdImp,
diff --git a/cmd/undeploy.go b/cmd/undeploy.go
index e1a962a..c079bcc 100644
--- a/cmd/undeploy.go
+++ b/cmd/undeploy.go
@@ -24,11 +24,11 @@ import (
// undeployCmd represents the undeploy command
var undeployCmd = &cobra.Command{
- Use: "undeploy",
- SuggestFor: []string {"remove"},
- Short: "Undeploy assets from OpenWhisk",
- Long: `Undeploy removes deployed assets from the manifest and deployment files`,
- RunE: UndeployCmdImp,
+ Use: "undeploy",
+ SuggestFor: []string{"remove"},
+ Short: "Undeploy assets from OpenWhisk",
+ Long: `Undeploy removes deployed assets from the manifest and deployment files`,
+ RunE: UndeployCmdImp,
}
func UndeployCmdImp(cmd *cobra.Command, args []string) error {
diff --git a/cmd/version.go b/cmd/version.go
index ef63f79..7ad5bc5 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -19,10 +19,10 @@ package cmd
import (
"fmt"
- "github.com/spf13/cobra"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "github.com/spf13/cobra"
)
func init() {
@@ -32,7 +32,7 @@ func init() {
var versionCmd = &cobra.Command{
Use: "version",
SuggestFor: []string{"edition", "release"},
- Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_VERSION),
+ Short: wski18n.T(wski18n.ID_CMD_DESC_SHORT_VERSION),
Run: func(cmd *cobra.Command, args []string) {
wskprint.PrintlnOpenWhiskOutput(
// Note: no need to translate the following string
diff --git a/deployers/deploymentreader.go b/deployers/deploymentreader.go
index d490865..03c7abc 100644
--- a/deployers/deploymentreader.go
+++ b/deployers/deploymentreader.go
@@ -20,11 +20,11 @@ package deployers
import (
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
- "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
"github.com/apache/incubator-openwhisk-wskdeploy/wskenv"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
)
type DeploymentReader struct {
@@ -79,8 +79,8 @@ func (reader *DeploymentReader) bindPackageInputsAndAnnotations() error {
warningString := wski18n.T(
wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: parsers.YAML_KEY_PACKAGE,
- wski18n.KEY_NEW: parsers.YAML_KEY_PACKAGES,
+ wski18n.KEY_OLD: parsers.YAML_KEY_PACKAGE,
+ wski18n.KEY_NEW: parsers.YAML_KEY_PACKAGES,
wski18n.KEY_FILE_TYPE: wski18n.DEPLOYMENT})
wskprint.PrintlnOpenWhiskWarning(warningString)
} else {
@@ -108,8 +108,8 @@ func (reader *DeploymentReader) bindPackageInputsAndAnnotations() error {
warningString := wski18n.T(
wski18n.ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: wski18n.PACKAGE_NAME,
- wski18n.KEY_NAME: packName })
+ wski18n.KEY_KEY: wski18n.PACKAGE_NAME,
+ wski18n.KEY_NAME: packName})
wskprint.PrintlnOpenWhiskWarning(warningString)
break
}
@@ -161,8 +161,8 @@ func (reader *DeploymentReader) bindPackageInputsAndAnnotations() error {
warningString := wski18n.T(
wski18n.ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
- wski18n.KEY_NAME: name })
+ wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
+ wski18n.KEY_NAME: name})
wskprint.PrintlnOpenWhiskWarning(warningString)
return wskderrors.NewYAMLFileFormatError(reader.DeploymentDescriptor.Filepath, warningString)
}
@@ -255,8 +255,8 @@ func (reader *DeploymentReader) bindActionInputsAndAnnotations() error {
errMsg := wski18n.T(
wski18n.ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
- wski18n.KEY_NAME: name })
+ wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
+ wski18n.KEY_NAME: name})
return wskderrors.NewYAMLFileFormatError(reader.DeploymentDescriptor.Filepath, errMsg)
}
}
@@ -321,7 +321,7 @@ func (reader *DeploymentReader) bindTriggerInputsAndAnnotations() error {
wski18n.ID_DEBUG_KEY_VERIFY_X_name_X_key_X,
map[string]interface{}{
wski18n.KEY_NAME: parsers.YAML_KEY_ANNOTATION,
- wski18n.KEY_KEY: keyVal.Key})
+ wski18n.KEY_KEY: keyVal.Key})
wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, traceMsg)
// TODO() verify logic and add Verbose/trace say "found" or "not found"
@@ -353,8 +353,8 @@ func (reader *DeploymentReader) bindTriggerInputsAndAnnotations() error {
errMsg := wski18n.T(
wski18n.ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
- wski18n.KEY_NAME: name })
+ wski18n.KEY_KEY: parsers.YAML_KEY_ANNOTATION,
+ wski18n.KEY_NAME: name})
return wskderrors.NewYAMLFileFormatError(reader.DeploymentDescriptor.Filepath, errMsg)
}
}
diff --git a/deployers/deploymentreader_test.go b/deployers/deploymentreader_test.go
index 2c2aeb1..ff58544 100644
--- a/deployers/deploymentreader_test.go
+++ b/deployers/deploymentreader_test.go
@@ -22,8 +22,8 @@ package deployers
import (
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/stretchr/testify/assert"
- "testing"
"reflect"
+ "testing"
)
var sd *ServiceDeployer
@@ -171,10 +171,10 @@ func TestDeploymentReader_BindAssets_ActionAnnotations(t *testing.T) {
pkg_name := "packageActionAnnotations"
pkg := dReader.DeploymentDescriptor.Packages[pkg_name]
- assert.NotNil(t, pkg, "Could not find package with name " + pkg_name)
+ assert.NotNil(t, pkg, "Could not find package with name "+pkg_name)
action_name := "helloworld"
action := dReader.DeploymentDescriptor.GetProject().Packages[pkg_name].Actions[action_name]
- assert.NotNil(t, action, "Could not find action with name " + action_name)
+ assert.NotNil(t, action, "Could not find action with name "+action_name)
actual_annotations := action.Annotations
expected_annotations := map[string]interface{}{
"action_annotation_1": "this is annotation 1",
@@ -186,9 +186,9 @@ func TestDeploymentReader_BindAssets_ActionAnnotations(t *testing.T) {
pkg_name = "packageActionAnnotationsWithWebAction"
pkg = dReader.DeploymentDescriptor.Packages[pkg_name]
- assert.NotNil(t, pkg, "Could not find package with name " + pkg_name)
+ assert.NotNil(t, pkg, "Could not find package with name "+pkg_name)
action = dReader.DeploymentDescriptor.GetProject().Packages[pkg_name].Actions[action_name]
- assert.NotNil(t, action, "Could not find action with name " + action_name)
+ assert.NotNil(t, action, "Could not find action with name "+action_name)
actual_annotations = action.Annotations
expected_annotations["web-export"] = true
assert.Equal(t, len(actual_annotations), len(expected_annotations), "Could not find expected number of annotations specified in manifest file")
@@ -197,9 +197,9 @@ func TestDeploymentReader_BindAssets_ActionAnnotations(t *testing.T) {
pkg_name = "packageActionAnnotationsFromDeployment"
pkg = dReader.DeploymentDescriptor.Packages[pkg_name]
- assert.NotNil(t, pkg, "Could not find package with name " + pkg_name)
+ assert.NotNil(t, pkg, "Could not find package with name "+pkg_name)
action = dReader.DeploymentDescriptor.GetProject().Packages[pkg_name].Actions[action_name]
- assert.NotNil(t, action, "Could not find action with name " + action_name)
+ assert.NotNil(t, action, "Could not find action with name "+action_name)
actual_annotations = action.Annotations
expected_annotations = map[string]interface{}{
"action_annotation_1": "this is annotation 1 from deployment",
@@ -209,4 +209,3 @@ func TestDeploymentReader_BindAssets_ActionAnnotations(t *testing.T) {
eq = reflect.DeepEqual(actual_annotations, expected_annotations)
assert.True(t, eq, "Expected list of annotations does not match with actual list, expected annotations: %v actual annotations: %v", expected_annotations, actual_annotations)
}
-
diff --git a/deployers/filesystemreader.go b/deployers/filesystemreader.go
index 05d6137..646d34e 100644
--- a/deployers/filesystemreader.go
+++ b/deployers/filesystemreader.go
@@ -27,8 +27,8 @@ import (
"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
)
// name of directory that can contain source code
@@ -51,7 +51,7 @@ func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.YAML) ([]
dbgMsg := wski18n.T(wski18n.ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X,
map[string]interface{}{
wski18n.KEY_PATH: reader.serviceDeployer.ProjectPath,
- wski18n.KEY_KEY: wski18n.ACTIONS})
+ wski18n.KEY_KEY: wski18n.ACTIONS})
wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, dbgMsg)
projectPathCount, err := reader.getFilePathCount(reader.serviceDeployer.ProjectPath)
@@ -69,7 +69,7 @@ func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.YAML) ([]
}
if !f.IsDir() {
- if pathCount - projectPathCount == 1 || strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath + "/" + FileSystemSourceDirectoryName) {
+ if pathCount-projectPathCount == 1 || strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath+"/"+FileSystemSourceDirectoryName) {
ext := filepath.Ext(fpath)
// TODO(#692) do not hardcoded known extensions here, create a util that associates
@@ -98,12 +98,12 @@ func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.YAML) ([]
actions = append(actions, record)
}
}
- } else if strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath + "/" + FileSystemSourceDirectoryName) {
+ } else if strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath+"/"+FileSystemSourceDirectoryName) {
// Inform user of what reader is doing
dbgMsg := wski18n.T(wski18n.ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X,
map[string]interface{}{
wski18n.KEY_PATH: filepath.Base(fpath),
- wski18n.KEY_KEY: wski18n.ACTION_CODE})
+ wski18n.KEY_KEY: wski18n.ACTION_CODE})
wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, dbgMsg)
// TODO(#694) It appears there is no code to do what the debug message suggests
diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index a8df385..06fbdce 100644
--- a/deployers/manifestreader.go
+++ b/deployers/manifestreader.go
@@ -135,7 +135,7 @@ func (reader *ManifestReader) SetDependencies(deps map[string]utils.DependencyRe
for name, dep := range deps {
n := strings.Split(name, ":")
depName := n[1]
- if (depName == "") {
+ if depName == "" {
return nil
}
if !dep.IsBinding && !reader.IsUndeploy {
diff --git a/deployers/manifestreader_test.go b/deployers/manifestreader_test.go
index 5e5851a..b4cc672 100644
--- a/deployers/manifestreader_test.go
+++ b/deployers/manifestreader_test.go
@@ -20,10 +20,10 @@
package deployers
import (
+ "github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
"github.com/stretchr/testify/assert"
"testing"
- "github.com/apache/incubator-openwhisk-client-go/whisk"
)
var mr *ManifestReader
diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index 72f3540..8861619 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -20,6 +20,13 @@ package deployers
import (
"bufio"
"fmt"
+ "github.com/apache/incubator-openwhisk-client-go/whisk"
+ "github.com/apache/incubator-openwhisk-wskdeploy/parsers"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "net/http"
"os"
"path"
"reflect"
@@ -27,13 +34,6 @@ import (
"strings"
"sync"
"time"
- "net/http"
- "github.com/apache/incubator-openwhisk-client-go/whisk"
- "github.com/apache/incubator-openwhisk-wskdeploy/parsers"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
- "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
)
const (
@@ -181,8 +181,8 @@ func (deployer *ServiceDeployer) ConstructDeploymentPlan() error {
if manifest.Application.Name != "" {
wskprint.PrintOpenWhiskWarning(wski18n.T(wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
- wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
+ wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
wski18n.KEY_FILE_TYPE: wski18n.MANIFEST}))
}
@@ -199,8 +199,8 @@ func (deployer *ServiceDeployer) ConstructDeploymentPlan() error {
if deploymentReader.DeploymentDescriptor.Application.Name != "" {
wskprint.PrintOpenWhiskWarning(wski18n.T(wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
- wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
+ wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
wski18n.KEY_FILE_TYPE: wski18n.DEPLOYMENT}))
}
@@ -210,11 +210,11 @@ func (deployer *ServiceDeployer) ConstructDeploymentPlan() error {
if projectNameDeploy != projectName {
errorString := wski18n.T(wski18n.ID_ERR_NAME_MISMATCH_X_key_X_dname_X_dpath_X_mname_X_moath_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_KEY: parsers.YAML_KEY_PROJECT,
wski18n.KEY_DEPLOYMENT_NAME: projectNameDeploy,
wski18n.KEY_DEPLOYMENT_PATH: deployer.DeploymentPath,
- wski18n.KEY_MANIFEST_NAME: projectName,
- wski18n.KEY_MANIFEST_PATH: deployer.ManifestPath})
+ wski18n.KEY_MANIFEST_NAME: projectName,
+ wski18n.KEY_MANIFEST_PATH: deployer.ManifestPath})
return wskderrors.NewYAMLFileFormatError(manifest.Filepath, errorString)
}
}
@@ -269,8 +269,8 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentProject
if manifest.Application.Name != "" {
wskprint.PrintOpenWhiskWarning(wski18n.T(wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
- wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
+ wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
wski18n.KEY_FILE_TYPE: wski18n.MANIFEST}))
}
@@ -286,8 +286,8 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentProject
if deploymentReader.DeploymentDescriptor.Application.Name != "" {
wskprint.PrintOpenWhiskWarning(wski18n.T(wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
- wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_OLD: parsers.YAML_KEY_APPLICATION,
+ wski18n.KEY_NEW: parsers.YAML_KEY_PROJECT,
wski18n.KEY_FILE_TYPE: wski18n.DEPLOYMENT}))
}
@@ -297,11 +297,11 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentProject
if projectNameDeploy != projectName {
errorString := wski18n.T(wski18n.ID_ERR_NAME_MISMATCH_X_key_X_dname_X_dpath_X_mname_X_moath_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_PROJECT,
+ wski18n.KEY_KEY: parsers.YAML_KEY_PROJECT,
wski18n.KEY_DEPLOYMENT_NAME: projectNameDeploy,
wski18n.KEY_DEPLOYMENT_PATH: deployer.DeploymentPath,
- wski18n.KEY_MANIFEST_NAME: projectName,
- wski18n.KEY_MANIFEST_PATH: deployer.ManifestPath})
+ wski18n.KEY_MANIFEST_NAME: projectName,
+ wski18n.KEY_MANIFEST_PATH: deployer.ManifestPath})
return deployer.Deployment, wskderrors.NewYAMLFileFormatError(manifest.Filepath, errorString)
}
}
@@ -542,8 +542,8 @@ func (deployer *ServiceDeployer) RefreshManagedActions(packageName string, ma ma
output := wski18n.T(wski18n.ID_MSG_MANAGED_FOUND_DELETED_X_key_X_name_X_project_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_ACTION,
- wski18n.KEY_NAME: actionName,
+ wski18n.KEY_KEY: parsers.YAML_KEY_ACTION,
+ wski18n.KEY_NAME: actionName,
wski18n.KEY_PROJECT: aa[utils.OW_PROJECT_NAME]})
wskprint.PrintOpenWhiskWarning(output)
@@ -583,8 +583,8 @@ func (deployer *ServiceDeployer) RefreshManagedTriggers(ma map[string]interface{
// we have found a trigger which was earlier part of the current project
output := wski18n.T(wski18n.ID_MSG_MANAGED_FOUND_DELETED_X_key_X_name_X_project_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_TRIGGER,
- wski18n.KEY_NAME: trigger.Name,
+ wski18n.KEY_KEY: parsers.YAML_KEY_TRIGGER,
+ wski18n.KEY_NAME: trigger.Name,
wski18n.KEY_PROJECT: ma[utils.OW_PROJECT_NAME]})
wskprint.PrintOpenWhiskWarning(output)
@@ -635,8 +635,8 @@ func (deployer *ServiceDeployer) RefreshManagedPackages(ma map[string]interface{
if pa[utils.OW_PROJECT_NAME] == ma[utils.OW_PROJECT_NAME] && pa[utils.OW_PROJECT_HASH] != ma[utils.OW_PROJECT_HASH] {
output := wski18n.T(wski18n.ID_MSG_MANAGED_FOUND_DELETED_X_key_X_name_X_project_X,
map[string]interface{}{
- wski18n.KEY_KEY: parsers.YAML_KEY_PACKAGE,
- wski18n.KEY_NAME: pkg.Name,
+ wski18n.KEY_KEY: parsers.YAML_KEY_PACKAGE,
+ wski18n.KEY_NAME: pkg.Name,
wski18n.KEY_PROJECT: pa[utils.OW_PROJECT_NAME]})
wskprint.PrintOpenWhiskWarning(output)
@@ -1295,7 +1295,7 @@ func retry(attempts int, sleep time.Duration, callback func() error) error {
time.Sleep(sleep)
warningMsg := wski18n.T(wski18n.ID_WARN_COMMAND_RETRY,
map[string]interface{}{
- wski18n.KEY_CMD: strconv.Itoa(i+1),
+ wski18n.KEY_CMD: strconv.Itoa(i + 1),
wski18n.KEY_ERR: err.Error()})
wskprint.PrintlnOpenWhiskWarning(warningMsg)
} else {
@@ -1453,48 +1453,48 @@ func (deployer *ServiceDeployer) getDependentDeployer(depName string, depRecord
return depServiceDeployer, nil
}
-func displayPreprocessingInfo(entity string, name string, onDeploy bool){
+func displayPreprocessingInfo(entity string, name string, onDeploy bool) {
var msgKey string
- if onDeploy{
+ if onDeploy {
msgKey = wski18n.ID_MSG_ENTITY_DEPLOYING_X_key_X_name_X
} else {
msgKey = wski18n.ID_MSG_ENTITY_UNDEPLOYING_X_key_X_name_X
}
msg := wski18n.T(msgKey,
map[string]interface{}{
- wski18n.KEY_KEY: entity,
+ wski18n.KEY_KEY: entity,
wski18n.KEY_NAME: name})
wskprint.PrintlnOpenWhiskInfo(msg)
}
-func displayPostprocessingInfo(entity string, name string, onDeploy bool){
+func displayPostprocessingInfo(entity string, name string, onDeploy bool) {
var msgKey string
- if onDeploy{
+ if onDeploy {
msgKey = wski18n.ID_MSG_ENTITY_DEPLOYED_SUCCESS_X_key_X_name_X
} else {
msgKey = wski18n.ID_MSG_ENTITY_UNDEPLOYED_SUCCESS_X_key_X_name_X
}
msg := wski18n.T(msgKey,
map[string]interface{}{
- wski18n.KEY_KEY: entity,
+ wski18n.KEY_KEY: entity,
wski18n.KEY_NAME: name})
wskprint.PrintlnOpenWhiskInfo(msg)
}
-func createWhiskClientError(err *whisk.WskError, response *http.Response, entity string, onCreate bool)(*wskderrors.WhiskClientError){
+func createWhiskClientError(err *whisk.WskError, response *http.Response, entity string, onCreate bool) *wskderrors.WhiskClientError {
var msgKey string
- if onCreate{
+ if onCreate {
msgKey = wski18n.ID_ERR_ENTITY_CREATE_X_key_X_err_X_code_X
} else {
msgKey = wski18n.ID_ERR_ENTITY_DELETE_X_key_X_err_X_code_X
}
errString := wski18n.T(msgKey,
map[string]interface{}{
- wski18n.KEY_KEY: entity,
- wski18n.KEY_ERR: err.Error(),
+ wski18n.KEY_KEY: entity,
+ wski18n.KEY_ERR: err.Error(),
wski18n.KEY_CODE: strconv.Itoa(err.ExitCode)})
wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, errString)
diff --git a/deployers/whiskclient.go b/deployers/whiskclient.go
index 715750c..83d2380 100644
--- a/deployers/whiskclient.go
+++ b/deployers/whiskclient.go
@@ -29,17 +29,17 @@ import (
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
)
// Possible sources for config info (e.g., API Host, Auth Key, Namespace)
const (
- SOURCE_WSKPROPS = ".wskprops"
- SOURCE_WHISK_PROPERTIES = "whisk.properties"
- SOURCE_INTERACTIVE_INPUT = "interactve input" // TODO() i18n?
- SOURCE_DEFAULT_VALUE = "wskdeploy default" // TODO() i18n?
+ SOURCE_WSKPROPS = ".wskprops"
+ SOURCE_WHISK_PROPERTIES = "whisk.properties"
+ SOURCE_INTERACTIVE_INPUT = "interactve input" // TODO() i18n?
+ SOURCE_DEFAULT_VALUE = "wskdeploy default" // TODO() i18n?
)
type PropertyValue struct {
@@ -97,8 +97,8 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
cert = GetPropertyValue(cert, certfile, wski18n.COMMAND_LINE)
// TODO() i18n
- // Print all flags / values if verbose
- wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, wski18n.CONFIGURATION + ":\n" + utils.Flags.Format())
+ // Print all flags / values if verbose
+ wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, wski18n.CONFIGURATION+":\n"+utils.Flags.Format())
// TODO() split this logic into its own function
// TODO() merge with the same logic used against manifest file (below)
@@ -236,15 +236,15 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
}
mode := true
- if (len(cert.Value) != 0 && len(key.Value) != 0) {
+ if len(cert.Value) != 0 && len(key.Value) != 0 {
mode = false
}
clientConfig = &whisk.Config{
AuthToken: credential.Value, //Authtoken
- Namespace: namespace.Value, //Namespace
+ Namespace: namespace.Value, //Namespace
Host: apiHost.Value,
- Version: "v1", // TODO() should not be hardcoded, should prompt/warn user of default
+ Version: "v1", // TODO() should not be hardcoded, should prompt/warn user of default
Cert: cert.Value,
Key: key.Value,
Insecure: mode, // true if you want to ignore certificate signing
@@ -255,7 +255,7 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string,
return clientConfig, err
}
-func validateClientConfig(credential PropertyValue, apiHost PropertyValue, namespace PropertyValue) (error) {
+func validateClientConfig(credential PropertyValue, apiHost PropertyValue, namespace PropertyValue) error {
// Display error message based upon which config value was missing
if len(credential.Value) == 0 || len(apiHost.Value) == 0 || len(namespace.Value) == 0 {
@@ -292,7 +292,7 @@ func validateClientConfig(credential PropertyValue, apiHost PropertyValue, names
}
// TODO() perhaps move into its own package "wskread" and add support for passing in default value
-var promptForValue = func(msg string) (string) {
+var promptForValue = func(msg string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(msg)
diff --git a/deployers/whiskclient_test.go b/deployers/whiskclient_test.go
index 5f81e03..1de6d2b 100644
--- a/deployers/whiskclient_test.go
+++ b/deployers/whiskclient_test.go
@@ -20,30 +20,30 @@
package deployers
import (
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-client-go/whisk"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/stretchr/testify/assert"
+ "testing"
)
const (
- DEPLOYMENT_HOST = "sample.deployment.openwhisk.org"
- DEPLOYMENT_AUTH = "sample-deployment-credential"
+ DEPLOYMENT_HOST = "sample.deployment.openwhisk.org"
+ DEPLOYMENT_AUTH = "sample-deployment-credential"
DEPLOYMENT_NAMESPACE = "sample-deployment-namespace"
- MANIFEST_HOST = "sample.manifest.openwhisk.org"
- MANIFEST_AUTH = "sample-manifest-credential"
+ MANIFEST_HOST = "sample.manifest.openwhisk.org"
+ MANIFEST_AUTH = "sample-manifest-credential"
MANIFEST_NAMESPACE = "sample-manifest-namespace"
- CLI_HOST = "sample.cli.openwhisk.org"
- CLI_AUTH = "sample-cli-credential"
+ CLI_HOST = "sample.cli.openwhisk.org"
+ CLI_AUTH = "sample-cli-credential"
CLI_NAMESPACE = "sample-cli-namespace"
- WSKPROPS_HOST = "openwhisk.ng.bluemix.net"
- WSKPROPS_AUTH = "a4f8c502:123zO3xZCLrMN6v2BKK"
+ WSKPROPS_HOST = "openwhisk.ng.bluemix.net"
+ WSKPROPS_AUTH = "a4f8c502:123zO3xZCLrMN6v2BKK"
WSKPROPS_NAMESPACE = "guest"
- WSKPROPS_KEY = "test_key_file"
+ WSKPROPS_KEY = "test_key_file"
WSKPROPS_CERT = "test_cert_file"
)
diff --git a/parsers/deploy_parser.go b/parsers/deploy_parser.go
index 88c5265..8f985fe 100644
--- a/parsers/deploy_parser.go
+++ b/parsers/deploy_parser.go
@@ -19,8 +19,8 @@ package parsers
import (
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "gopkg.in/yaml.v2"
"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
+ "gopkg.in/yaml.v2"
)
func (dm *YAMLParser) unmarshalDeployment(input []byte, deploy *YAML) error {
@@ -35,22 +35,21 @@ func (dm *YAMLParser) ParseDeployment(deploymentPath string) (*YAML, error) {
dplyyaml := YAML{}
content, err := new(utils.ContentReader).LocalReader.ReadLocal(deploymentPath)
- if err != nil {
- return &dplyyaml, wskderrors.NewFileReadError(deploymentPath, err.Error())
- }
+ if err != nil {
+ return &dplyyaml, wskderrors.NewFileReadError(deploymentPath, err.Error())
+ }
err = dm.unmarshalDeployment(content, &dplyyaml)
if err != nil {
- return &dplyyaml, wskderrors.NewYAMLParserErr(deploymentPath, err)
- }
+ return &dplyyaml, wskderrors.NewYAMLParserErr(deploymentPath, err)
+ }
dplyyaml.Filepath = deploymentPath
- dplyyamlEnvVar := ReadEnvVariable(&dplyyaml)
+ dplyyamlEnvVar := ReadEnvVariable(&dplyyaml)
return dplyyamlEnvVar, nil
}
-
//********************Project functions*************************//
//This is for parse the deployment yaml file.
func (app *Project) GetPackageList() []Package {
diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index 37d318e..d913c1c 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -18,20 +18,20 @@
package parsers
import (
+ "encoding/base64"
"errors"
+ "fmt"
+ "gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path"
"strings"
- "encoding/base64"
- "fmt"
- "gopkg.in/yaml.v2"
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
"github.com/apache/incubator-openwhisk-wskdeploy/wskenv"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
)
@@ -245,7 +245,7 @@ func (dm *YAMLParser) ComposePackage(pkg Package, packageName string, filePath s
warningString := wski18n.T(
wski18n.ID_WARN_KEY_MISSING_X_key_X_value_X,
map[string]interface{}{
- wski18n.KEY_KEY: wski18n.PACKAGE_VERSION,
+ wski18n.KEY_KEY: wski18n.PACKAGE_VERSION,
wski18n.KEY_VALUE: DEFAULT_PACKAGE_VERSION})
wskprint.PrintOpenWhiskWarning(warningString)
@@ -265,7 +265,7 @@ func (dm *YAMLParser) ComposePackage(pkg Package, packageName string, filePath s
warningString := wski18n.T(
wski18n.ID_WARN_KEY_MISSING_X_key_X_value_X,
map[string]interface{}{
- wski18n.KEY_KEY: wski18n.PACKAGE_LICENSE,
+ wski18n.KEY_KEY: wski18n.PACKAGE_LICENSE,
wski18n.KEY_VALUE: DEFAULT_PACKAGE_LICENSE})
wskprint.PrintOpenWhiskWarning(warningString)
@@ -359,7 +359,7 @@ func (dm *YAMLParser) ComposeSequences(namespace string, sequences map[string]Se
var components []string
for _, a := range actionList {
act := strings.TrimSpace(a)
- if !strings.ContainsRune(act, '/') && !strings.HasPrefix(act, packageName +"/") {
+ if !strings.ContainsRune(act, '/') && !strings.HasPrefix(act, packageName+"/") {
act = path.Join(packageName, act)
}
components = append(components, path.Join("/"+namespace, act))
@@ -435,8 +435,8 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
wskaction.Exec = new(whisk.Exec)
/*
- * Action.Function
- */
+ * Action.Function
+ */
//set action.Function to action.Location
//because Location is deprecated in Action entity
if action.Function == "" && action.Location != "" {
@@ -480,9 +480,9 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
if len(kind) == 0 && len(action.Runtime) == 0 && ext != utils.ZIP_FILE_EXTENSION {
errMessage := wski18n.T(wski18n.ID_ERR_RUNTIME_MISMATCH_X_runtime_X_ext_X_action_X,
map[string]interface{}{
- wski18n.KEY_RUNTIME: action.Runtime,
+ wski18n.KEY_RUNTIME: action.Runtime,
wski18n.KEY_EXTENTION: ext,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
return nil, wskderrors.NewInvalidRuntimeError(errMessage,
splitFilePath[len(splitFilePath)-1], action.Name,
action.Runtime,
@@ -504,7 +504,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
errMessage := wski18n.T(wski18n.ID_ERR_RUNTIME_INVALID_X_runtime_X_action_X,
map[string]interface{}{
wski18n.KEY_RUNTIME: action.Runtime,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
return nil, wskderrors.NewInvalidRuntimeError(errMessage,
splitFilePath[len(splitFilePath)-1],
action.Name,
@@ -517,12 +517,12 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
}
/*
- * Action.Runtime
- * Perform few checks if action runtime is specified in manifest YAML file
- * (1) Check if specified runtime is one of the supported runtimes by OpenWhisk server
- * (2) Check if specified runtime is consistent with action source file extensions
- * Set the action runtime to match with the source file extension, if wskdeploy is not invoked in strict mode
- */
+ * Action.Runtime
+ * Perform few checks if action runtime is specified in manifest YAML file
+ * (1) Check if specified runtime is one of the supported runtimes by OpenWhisk server
+ * (2) Check if specified runtime is consistent with action source file extensions
+ * Set the action runtime to match with the source file extension, if wskdeploy is not invoked in strict mode
+ */
if action.Runtime != "" {
if utils.CheckExistRuntime(action.Runtime, utils.SupportedRunTimes) {
// for zip actions, rely on the runtimes from the manifest file as it can not be derived from the action source file extension
@@ -535,9 +535,9 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
} else {
warnStr := wski18n.T(wski18n.ID_ERR_RUNTIME_MISMATCH_X_runtime_X_ext_X_action_X,
map[string]interface{}{
- wski18n.KEY_RUNTIME: action.Runtime,
+ wski18n.KEY_RUNTIME: action.Runtime,
wski18n.KEY_EXTENTION: ext,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
wskprint.PrintOpenWhiskWarning(warnStr)
// even if runtime is not consistent with file extension, deploy action with specified runtime in strict mode
@@ -547,7 +547,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
warnStr := wski18n.T(wski18n.ID_WARN_RUNTIME_CHANGED_X_runtime_X_action_X,
map[string]interface{}{
wski18n.KEY_RUNTIME: wskaction.Exec.Kind,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
wskprint.PrintOpenWhiskWarning(warnStr)
}
}
@@ -556,7 +556,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
warnStr := wski18n.T(wski18n.ID_ERR_RUNTIME_INVALID_X_runtime_X_action_X,
map[string]interface{}{
wski18n.KEY_RUNTIME: action.Runtime,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
wskprint.PrintOpenWhiskWarning(warnStr)
if ext == utils.ZIP_FILE_EXTENSION {
@@ -571,7 +571,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
warnStr := wski18n.T(wski18n.ID_WARN_RUNTIME_CHANGED_X_runtime_X_action_X,
map[string]interface{}{
wski18n.KEY_RUNTIME: wskaction.Exec.Kind,
- wski18n.KEY_ACTION: action.Name})
+ wski18n.KEY_ACTION: action.Name})
wskprint.PrintOpenWhiskWarning(warnStr)
}
@@ -607,7 +607,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
}
/*
- * Action.Outputs
+ * Action.Outputs
*/
keyValArr = make(whisk.KeyValueArr, 0)
for name, param := range action.Outputs {
@@ -632,8 +632,8 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
}
/*
- * Action.Annotations
- */
+ * Action.Annotations
+ */
listOfAnnotations := make(whisk.KeyValueArr, 0)
for name, value := range action.Annotations {
var keyVal whisk.KeyValue
@@ -650,8 +650,8 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
}
/*
- * Web Export
- */
+ * Web Export
+ */
// TODO() add boolean value const
if action.Webexport == "true" {
wskaction.Annotations, errorParser = utils.WebAction("yes", listOfAnnotations, false)
@@ -661,10 +661,10 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
}
/*
- * Action.Limits
- */
- if action.Limits!=nil {
- wsklimits := new(whisk.Limits)
+ * Action.Limits
+ */
+ if action.Limits != nil {
+ wsklimits := new(whisk.Limits)
// TODO() use LIMITS_SUPPORTED in yamlparser to enumerata through instead of hardcoding
// perhaps change into a tuple
@@ -689,7 +689,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
map[string]interface{}{wski18n.KEY_LIMIT: LIMIT_VALUE_LOG_SIZE})
wskprint.PrintOpenWhiskWarning(warningString)
}
- if wsklimits.Timeout!=nil || wsklimits.Memory!=nil || wsklimits.Logsize!=nil {
+ if wsklimits.Timeout != nil || wsklimits.Memory != nil || wsklimits.Logsize != nil {
wskaction.Limits = wsklimits
}
@@ -753,8 +753,8 @@ func (dm *YAMLParser) ComposeTriggers(filePath string, pkg Package, ma whisk.Key
warningString := wski18n.T(
wski18n.ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X,
map[string]interface{}{
- wski18n.KEY_OLD: YAML_KEY_SOURCE,
- wski18n.KEY_NEW: YAML_KEY_FEED,
+ wski18n.KEY_OLD: YAML_KEY_SOURCE,
+ wski18n.KEY_NEW: YAML_KEY_FEED,
wski18n.KEY_FILE_TYPE: wski18n.MANIFEST})
wskprint.PrintOpenWhiskWarning(warningString)
}
@@ -840,7 +840,6 @@ func (dm *YAMLParser) ComposeRulesFromAllPackages(manifest *YAML) ([]*whisk.Rule
return rules, nil
}
-
func (dm *YAMLParser) ComposeRules(pkg Package, packageName string) ([]*whisk.Rule, error) {
var r1 []*whisk.Rule = make([]*whisk.Rule, 0)
diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index dde8866..5b45dc1 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -20,195 +20,194 @@
package parsers
import (
- "github.com/stretchr/testify/assert"
- "io/ioutil"
- "os"
- "testing"
- "fmt"
- "path/filepath"
- "reflect"
- "strconv"
- "strings"
- "github.com/apache/incubator-openwhisk-client-go/whisk"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "fmt"
+ "github.com/apache/incubator-openwhisk-client-go/whisk"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "reflect"
+ "strconv"
+ "strings"
+ "testing"
)
const (
- // local test assert messages
- TEST_MSG_PACKAGE_NAME_MISSING = "Package named [%s] missing."
- TEST_MSG_PACKAGE_NAME_MISMATCH = "Package name mismatched."
- TEST_MSG_ACTION_NUMBER_MISMATCH = "Number of Actions mismatched."
- TEST_MSG_ACTION_NAME_MISSING = "Action named [%s] does not exist."
- TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH = "Action function path mismatched."
- TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH = "Action function runtime mismatched."
- TEST_MSG_ACTION_FUNCTION_MAIN_MISMATCH = "Action function main name mismatch."
- TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH = "Action parameter [%s] had a type mismatch."
- TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH = "Action parameter [%s] had a value mismatch."
- TEST_MSG_PARAMETER_NUMBER_MISMATCH = "Number of Paramaters mismatched."
- TEST_MSG_MANIFEST_UNMARSHALL_ERROR_EXPECTED = "Manifest [%s]: Expected Unmarshal error."
- TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED = "Manifest [%s]: Expected runtime error."
-
- // local error messages
- TEST_ERROR_MANIFEST_PARSE_FAILURE = "Manifest [%s]: Failed to parse."
- TEST_ERROR_MANIFEST_READ_FAILURE = "Manifest [%s]: Failed to ReadFile()."
- TEST_ERROR_MANIFEST_DATA_UNMARSHALL = "Manifest [%s]: Failed to Unmarshall manifest."
+ // local test assert messages
+ TEST_MSG_PACKAGE_NAME_MISSING = "Package named [%s] missing."
+ TEST_MSG_PACKAGE_NAME_MISMATCH = "Package name mismatched."
+ TEST_MSG_ACTION_NUMBER_MISMATCH = "Number of Actions mismatched."
+ TEST_MSG_ACTION_NAME_MISSING = "Action named [%s] does not exist."
+ TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH = "Action function path mismatched."
+ TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH = "Action function runtime mismatched."
+ TEST_MSG_ACTION_FUNCTION_MAIN_MISMATCH = "Action function main name mismatch."
+ TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH = "Action parameter [%s] had a type mismatch."
+ TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH = "Action parameter [%s] had a value mismatch."
+ TEST_MSG_PARAMETER_NUMBER_MISMATCH = "Number of Paramaters mismatched."
+ TEST_MSG_MANIFEST_UNMARSHALL_ERROR_EXPECTED = "Manifest [%s]: Expected Unmarshal error."
+ TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED = "Manifest [%s]: Expected runtime error."
+
+ // local error messages
+ TEST_ERROR_MANIFEST_PARSE_FAILURE = "Manifest [%s]: Failed to parse."
+ TEST_ERROR_MANIFEST_READ_FAILURE = "Manifest [%s]: Failed to ReadFile()."
+ TEST_ERROR_MANIFEST_DATA_UNMARSHALL = "Manifest [%s]: Failed to Unmarshall manifest."
)
func init() {
- op, error := utils.ParseOpenWhisk("")
- if error == nil {
- utils.SupportedRunTimes = utils.ConvertToMap(op)
- utils.DefaultRunTimes = utils.DefaultRuntimes(op)
- utils.FileExtensionRuntimeKindMap = utils.FileExtensionRuntimes(op)
- }
+ op, error := utils.ParseOpenWhisk("")
+ if error == nil {
+ utils.SupportedRunTimes = utils.ConvertToMap(op)
+ utils.DefaultRunTimes = utils.DefaultRuntimes(op)
+ utils.FileExtensionRuntimeKindMap = utils.FileExtensionRuntimes(op)
+ }
}
-func testReadAndUnmarshalManifest(t *testing.T, pathManifest string)(YAML, error){
- // Init YAML struct and attempt to Unmarshal YAML byte[] data
- m := YAML{}
+func testReadAndUnmarshalManifest(t *testing.T, pathManifest string) (YAML, error) {
+ // Init YAML struct and attempt to Unmarshal YAML byte[] data
+ m := YAML{}
- // read raw bytes of manifest.yaml file
- data, err := ioutil.ReadFile(pathManifest)
+ // read raw bytes of manifest.yaml file
+ data, err := ioutil.ReadFile(pathManifest)
- if err != nil{
- t.Error(fmt.Sprintf(TEST_ERROR_MANIFEST_READ_FAILURE, pathManifest))
- return m, err
- }
+ if err != nil {
+ t.Error(fmt.Sprintf(TEST_ERROR_MANIFEST_READ_FAILURE, pathManifest))
+ return m, err
+ }
- err = NewYAMLParser().Unmarshal([]byte(data), &m)
- return m, err
+ err = NewYAMLParser().Unmarshal([]byte(data), &m)
+ return m, err
}
-
/*
- testUnmarshalManifestAndActionBasic
+ testUnmarshalManifestAndActionBasic
- This function validates basic Manifest Package and Action keys including
- - Package name mismatch (single "package" only)
- - Number of Actions mismatch
- - Action Function path mismatch
- - Action runtime (name) mismatch
+ This function validates basic Manifest Package and Action keys including
+ - Package name mismatch (single "package" only)
+ - Number of Actions mismatch
+ - Action Function path mismatch
+ - Action runtime (name) mismatch
- and optionally,
- = Action function "main" name mismatch
+ and optionally,
+ = Action function "main" name mismatch
- Returns:
- - N/A
- */
+ Returns:
+ - N/A
+*/
func testUnmarshalManifestAndActionBasic(t *testing.T,
- pathManifest string,
- namePackage string,
- numActions int,
- nameAction string,
- pathFunction string,
- nameRuntime string,
- nameMain string) (YAML, error){
-
- // Test that we are able to read the manifest file and unmarshall into YAML struct
- m, err := testReadAndUnmarshalManifest(t, pathManifest)
-
- // nothing to test if Unmarshal returns an err
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_DATA_UNMARSHALL, pathManifest))
- } else {
- // test package name
- actualResult := m.Package.Packagename
- assert.Equal(t, namePackage, actualResult, TEST_MSG_PACKAGE_NAME_MISMATCH)
-
- // test # of actions in manifest
- if numActions >0 {
- actualResult = string(len(m.Package.Actions))
- assert.Equal(t, string(numActions), actualResult, TEST_MSG_ACTION_NUMBER_MISMATCH)
- }
-
- // get an action from map of actions where key is action name and value is Action struct
- if action, ok := m.Package.Actions[nameAction]; ok {
-
- // test action's function path
- assert.Equal(t, pathFunction, action.Function, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
-
- // test action's runtime
- assert.Equal(t, nameRuntime, action.Runtime, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
-
- // test action's "Main" function
- if nameMain != "" {
- assert.Equal(t, nameMain, action.Main, TEST_MSG_ACTION_FUNCTION_MAIN_MISMATCH)
- }
-
- } else {
- t.Error(fmt.Sprintf(TEST_MSG_ACTION_NAME_MISSING, nameAction))
- }
- }
- return m, nil
+ pathManifest string,
+ namePackage string,
+ numActions int,
+ nameAction string,
+ pathFunction string,
+ nameRuntime string,
+ nameMain string) (YAML, error) {
+
+ // Test that we are able to read the manifest file and unmarshall into YAML struct
+ m, err := testReadAndUnmarshalManifest(t, pathManifest)
+
+ // nothing to test if Unmarshal returns an err
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_DATA_UNMARSHALL, pathManifest))
+ } else {
+ // test package name
+ actualResult := m.Package.Packagename
+ assert.Equal(t, namePackage, actualResult, TEST_MSG_PACKAGE_NAME_MISMATCH)
+
+ // test # of actions in manifest
+ if numActions > 0 {
+ actualResult = string(len(m.Package.Actions))
+ assert.Equal(t, string(numActions), actualResult, TEST_MSG_ACTION_NUMBER_MISMATCH)
+ }
+
+ // get an action from map of actions where key is action name and value is Action struct
+ if action, ok := m.Package.Actions[nameAction]; ok {
+
+ // test action's function path
+ assert.Equal(t, pathFunction, action.Function, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
+
+ // test action's runtime
+ assert.Equal(t, nameRuntime, action.Runtime, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+
+ // test action's "Main" function
+ if nameMain != "" {
+ assert.Equal(t, nameMain, action.Main, TEST_MSG_ACTION_FUNCTION_MAIN_MISMATCH)
+ }
+
+ } else {
+ t.Error(fmt.Sprintf(TEST_MSG_ACTION_NAME_MISSING, nameAction))
+ }
+ }
+ return m, nil
}
-func testUnmarshalTemporaryFile (data []byte, filename string) (p *YAMLParser, m *YAML, t string) {
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, filename)
- if err == nil {
- defer os.Remove(tmpfile.Name()) // clean up
- if _, err := tmpfile.Write(data); err == nil {
- // read and parse manifest.yaml file
- p = NewYAMLParser()
- m, _ = p.ParseManifest(tmpfile.Name())
- }
- }
- t = tmpfile.Name()
- tmpfile.Close()
- return
+func testUnmarshalTemporaryFile(data []byte, filename string) (p *YAMLParser, m *YAML, t string) {
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, filename)
+ if err == nil {
+ defer os.Remove(tmpfile.Name()) // clean up
+ if _, err := tmpfile.Write(data); err == nil {
+ // read and parse manifest.yaml file
+ p = NewYAMLParser()
+ m, _ = p.ParseManifest(tmpfile.Name())
+ }
+ }
+ t = tmpfile.Name()
+ tmpfile.Close()
+ return
}
// Test 1: validate manifest_parser:Unmarshal() method with a sample manifest in NodeJS
// validate that manifest_parser is able to read and parse the manifest data
func TestUnmarshalForHelloNodeJS(t *testing.T) {
- testUnmarshalManifestAndActionBasic(t,
- "../tests/dat/manifest_hello_nodejs.yaml", // Manifest path
- "helloworld", // Package name
- 1, // # of Actions
- "helloNodejs", // Action name
- "actions/hello.js", // Function path
- "nodejs:6", // "Runtime
- "") // "Main" function name
+ testUnmarshalManifestAndActionBasic(t,
+ "../tests/dat/manifest_hello_nodejs.yaml", // Manifest path
+ "helloworld", // Package name
+ 1, // # of Actions
+ "helloNodejs", // Action name
+ "actions/hello.js", // Function path
+ "nodejs:6", // "Runtime
+ "") // "Main" function name
}
// Test 2: validate manifest_parser:Unmarshal() method with a sample manifest in Java
// validate that manifest_parser is able to read and parse the manifest data
func TestUnmarshalForHelloJava(t *testing.T) {
- testUnmarshalManifestAndActionBasic(t,
- "../tests/dat/manifest_hello_java_jar.yaml", // Manifest path
- "helloworld", // Package name
- 1, // # of Actions
- "helloJava", // Action name
- "actions/hello.jar", // Function path
- "java", // "Runtime
- "Hello") // "Main" function name
+ testUnmarshalManifestAndActionBasic(t,
+ "../tests/dat/manifest_hello_java_jar.yaml", // Manifest path
+ "helloworld", // Package name
+ 1, // # of Actions
+ "helloJava", // Action name
+ "actions/hello.jar", // Function path
+ "java", // "Runtime
+ "Hello") // "Main" function name
}
// Test 3: validate manifest_parser:Unmarshal() method with a sample manifest in Python
// validate that manifest_parser is able to read and parse the manifest data
func TestUnmarshalForHelloPython(t *testing.T) {
- testUnmarshalManifestAndActionBasic(t,
- "../tests/dat/manifest_hello_python.yaml", // Manifest path
- "helloworld", // Package name
- 1, // # of Actions
- "helloPython", // Action name
- "actions/hello.py", // Function path
- "python", // "Runtime
- "") // "Main" function name
+ testUnmarshalManifestAndActionBasic(t,
+ "../tests/dat/manifest_hello_python.yaml", // Manifest path
+ "helloworld", // Package name
+ 1, // # of Actions
+ "helloPython", // Action name
+ "actions/hello.py", // Function path
+ "python", // "Runtime
+ "") // "Main" function name
}
// Test 4: validate manifest_parser:Unmarshal() method with a sample manifest in Swift
// validate that manifest_parser is able to read and parse the manifest data
func TestUnmarshalForHelloSwift(t *testing.T) {
- testUnmarshalManifestAndActionBasic(t,
- "../tests/dat/manifest_hello_swift.yaml", // Manifest path
- "helloworld", // Package name
- 1, // # of Actions
- "helloSwift", // Action name
- "actions/hello.swift", // Function path
- "swift", // "Runtime
- "") // "Main" function name
+ testUnmarshalManifestAndActionBasic(t,
+ "../tests/dat/manifest_hello_swift.yaml", // Manifest path
+ "helloworld", // Package name
+ 1, // # of Actions
+ "helloSwift", // Action name
+ "actions/hello.swift", // Function path
+ "swift", // "Runtime
+ "") // "Main" function name
}
// Test 5: validate manifest_parser:Unmarshal() method for an action with parameters
@@ -216,44 +215,44 @@ func TestUnmarshalForHelloSwift(t *testing.T) {
// validate two input parameters and their values
func TestUnmarshalForHelloWithParams(t *testing.T) {
- TEST_ACTION_NAME := "helloWithParams"
- TEST_PARAM_NAME_1 := "name"
- TEST_PARAM_VALUE_1 := "Amy"
- TEST_PARAM_NAME_2 := "place"
- TEST_PARAM_VALUE_2 := "Paris"
-
- m, err := testUnmarshalManifestAndActionBasic(t,
- "../tests/dat/manifest_hello_nodejs_with_params.yaml", // Manifest path
- "helloworld", // Package name
- 1, // # of Actions
- TEST_ACTION_NAME, // Action name
- "actions/hello-with-params.js", // Function path
- "nodejs:6", // "Runtime
- "") // "Main" function name
-
- if err != nil {
- if action, ok := m.Package.Actions[TEST_ACTION_NAME]; ok {
-
- // test action parameters
- actualResult := action.Inputs[TEST_PARAM_NAME_1].Value.(string)
- assert.Equal(t, TEST_PARAM_VALUE_1, actualResult,
- fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, TEST_PARAM_NAME_1))
-
- actualResult = action.Inputs[TEST_PARAM_NAME_2].Value.(string)
- assert.Equal(t, TEST_PARAM_VALUE_2, actualResult,
- fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, TEST_PARAM_NAME_2))
-
- }
- }
+ TEST_ACTION_NAME := "helloWithParams"
+ TEST_PARAM_NAME_1 := "name"
+ TEST_PARAM_VALUE_1 := "Amy"
+ TEST_PARAM_NAME_2 := "place"
+ TEST_PARAM_VALUE_2 := "Paris"
+
+ m, err := testUnmarshalManifestAndActionBasic(t,
+ "../tests/dat/manifest_hello_nodejs_with_params.yaml", // Manifest path
+ "helloworld", // Package name
+ 1, // # of Actions
+ TEST_ACTION_NAME, // Action name
+ "actions/hello-with-params.js", // Function path
+ "nodejs:6", // "Runtime
+ "") // "Main" function name
+
+ if err != nil {
+ if action, ok := m.Package.Actions[TEST_ACTION_NAME]; ok {
+
+ // test action parameters
+ actualResult := action.Inputs[TEST_PARAM_NAME_1].Value.(string)
+ assert.Equal(t, TEST_PARAM_VALUE_1, actualResult,
+ fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, TEST_PARAM_NAME_1))
+
+ actualResult = action.Inputs[TEST_PARAM_NAME_2].Value.(string)
+ assert.Equal(t, TEST_PARAM_VALUE_2, actualResult,
+ fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, TEST_PARAM_NAME_2))
+
+ }
+ }
}
// Test 6: validate manifest_parser:Unmarshal() method for an invalid manifest
// manifest_parser should report an error when a package section is missing
func TestUnmarshalForMissingPackage(t *testing.T) {
- TEST_MANIFEST := "../tests/dat/manifest_invalid_package_missing.yaml"
+ TEST_MANIFEST := "../tests/dat/manifest_invalid_package_missing.yaml"
- _, err := testReadAndUnmarshalManifest(t, TEST_MANIFEST)
- assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_MANIFEST_UNMARSHALL_ERROR_EXPECTED, TEST_MANIFEST))
+ _, err := testReadAndUnmarshalManifest(t, TEST_MANIFEST)
+ assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_MANIFEST_UNMARSHALL_ERROR_EXPECTED, TEST_MANIFEST))
}
/*
@@ -262,237 +261,237 @@ func TestUnmarshalForMissingPackage(t *testing.T) {
inputs section.
*/
func TestParseManifestForMultiLineParams(t *testing.T) {
- // manifest file is located under ../tests folder
- manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
- // read and parse manifest.yaml file
- m, err := NewYAMLParser().ParseManifest(manifestFile)
-
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
- }
-
- // validate package name should be "validate"
- packageName := "validate"
-
- // validate this package contains one action
- expectedActionsCount := 1
- actualActionsCount := len(m.Packages[packageName].Actions)
- assert.Equal(t, expectedActionsCount, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
-
- // here Package.Actions holds a map of map[string]Action
- // where string is the action name so in case you create two actions with
- // same name, will go unnoticed
- // also, the Action struct does not have name field set it to action name
- actionName := "validate_multiline_params"
-
- if action, ok := m.Packages[packageName].Actions[actionName]; ok {
- // test action function's path
- expectedResult := "actions/dump_params.js"
- actualResult := action.Function
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
-
- // test action's runtime
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
-
- // test # input params
- expectedResult = strconv.FormatInt(10, 10)
- actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
-
- // validate inputs to this action
- for input, param := range action.Inputs {
- switch input {
- case "param_string_value_only":
- expectedResult = "foo"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_int_value_only":
- expectedResult = strconv.FormatInt(123, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_float_value_only":
- expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_string_type_and_value_only":
- expectedResult = "foo"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_string_type_only":
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_integer_type_only":
- expectedResult = "integer"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_float_type_only":
- expectedResult = "float"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_string_with_default":
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- expectedResult = "bar"
- actualResult = param.Default.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_integer_with_default":
- expectedResult = "integer"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(param.Default.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_float_with_default":
- expectedResult = "float"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
- expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Default.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- }
- }
-
- // validate Outputs from this action
- for output, param := range action.Outputs {
- switch output {
- case "payload":
- expectedType := "string"
- actualType := param.Type
- assert.Equal(t, expectedType, actualType, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
- expectedDesc := "parameter dump"
- actualDesc := param.Description
- assert.Equal(t, expectedDesc, actualDesc, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
-
- }
- }
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
+ // read and parse manifest.yaml file
+ m, err := NewYAMLParser().ParseManifest(manifestFile)
+
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
+ }
+
+ // validate package name should be "validate"
+ packageName := "validate"
+
+ // validate this package contains one action
+ expectedActionsCount := 1
+ actualActionsCount := len(m.Packages[packageName].Actions)
+ assert.Equal(t, expectedActionsCount, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
+
+ // here Package.Actions holds a map of map[string]Action
+ // where string is the action name so in case you create two actions with
+ // same name, will go unnoticed
+ // also, the Action struct does not have name field set it to action name
+ actionName := "validate_multiline_params"
+
+ if action, ok := m.Packages[packageName].Actions[actionName]; ok {
+ // test action function's path
+ expectedResult := "actions/dump_params.js"
+ actualResult := action.Function
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
+
+ // test action's runtime
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+
+ // test # input params
+ expectedResult = strconv.FormatInt(10, 10)
+ actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
+
+ // validate inputs to this action
+ for input, param := range action.Inputs {
+ switch input {
+ case "param_string_value_only":
+ expectedResult = "foo"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_int_value_only":
+ expectedResult = strconv.FormatInt(123, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_float_value_only":
+ expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_string_type_and_value_only":
+ expectedResult = "foo"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_string_type_only":
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_integer_type_only":
+ expectedResult = "integer"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_float_type_only":
+ expectedResult = "float"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_string_with_default":
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ expectedResult = "bar"
+ actualResult = param.Default.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_integer_with_default":
+ expectedResult = "integer"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(param.Default.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_float_with_default":
+ expectedResult = "float"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
+ expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Default.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ }
+ }
+
+ // validate Outputs from this action
+ for output, param := range action.Outputs {
+ switch output {
+ case "payload":
+ expectedType := "string"
+ actualType := param.Type
+ assert.Equal(t, expectedType, actualType, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
+ expectedDesc := "parameter dump"
+ actualDesc := param.Description
+ assert.Equal(t, expectedDesc, actualDesc, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+
+ }
+ }
+ }
}
// Test 8: validate manifest_parser:ParseManifest() method for single line parameters
// manifest_parser should be able to parse input section with different types of values
func TestParseManifestForSingleLineParams(t *testing.T) {
- // manifest file is located under ../tests folder
- manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
-
- // read and parse manifest.yaml file
- m, err := NewYAMLParser().ParseManifest(manifestFile)
-
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
- }
-
- // validate package name should be "validate"
- packageName := "validate"
-
- // validate this package contains one action
- expectedActionsCount := 1
- actualActionsCount := len(m.Packages[packageName].Actions)
- assert.Equal(t, expectedActionsCount, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
-
- actionName := "validate_singleline_params"
- if action, ok := m.Packages[packageName].Actions[actionName]; ok {
- // test Action function's path
- expectedResult := "actions/dump_params.js"
- actualResult := action.Function
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
-
- // test Action runtime
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
-
- // test # of inputs
- expectedResult = strconv.FormatInt(22, 10)
- actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
-
- // validate Inputs to this action
- for input, param := range action.Inputs {
- switch input {
- case "param_simple_string":
- expectedResult = "foo"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_integer_1":
- expectedResult = strconv.FormatInt(1, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_integer_2":
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_integer_3":
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_integer_4":
- expectedResult = strconv.FormatInt(99999, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_integer_5":
- expectedResult = strconv.FormatInt(-99999, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_float_1":
- expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_float_2":
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_float_3":
- expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_env_var_1":
- expectedResult = "$GOPATH"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_invalid_env_var":
- expectedResult = "$DollarSignNotInEnv"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- case "param_simple_implied_empty":
- assert.Nil(t, param.Value, "Expected nil")
- case "param_simple_explicit_empty_1":
- actualResult = param.Value.(string)
- assert.Empty(t, actualResult)
- case "param_simple_explicit_empty_2":
- actualResult = param.Value.(string)
- assert.Empty(t, actualResult)
- }
- }
-
- // validate Outputs from this action
- for output, param := range action.Outputs {
- switch output {
- case "payload":
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
-
- expectedResult = "parameter dump"
- actualResult = param.Description
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
- }
- }
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
+
+ // read and parse manifest.yaml file
+ m, err := NewYAMLParser().ParseManifest(manifestFile)
+
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
+ }
+
+ // validate package name should be "validate"
+ packageName := "validate"
+
+ // validate this package contains one action
+ expectedActionsCount := 1
+ actualActionsCount := len(m.Packages[packageName].Actions)
+ assert.Equal(t, expectedActionsCount, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
+
+ actionName := "validate_singleline_params"
+ if action, ok := m.Packages[packageName].Actions[actionName]; ok {
+ // test Action function's path
+ expectedResult := "actions/dump_params.js"
+ actualResult := action.Function
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
+
+ // test Action runtime
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+
+ // test # of inputs
+ expectedResult = strconv.FormatInt(22, 10)
+ actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
+
+ // validate Inputs to this action
+ for input, param := range action.Inputs {
+ switch input {
+ case "param_simple_string":
+ expectedResult = "foo"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_integer_1":
+ expectedResult = strconv.FormatInt(1, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_integer_2":
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_integer_3":
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_integer_4":
+ expectedResult = strconv.FormatInt(99999, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_integer_5":
+ expectedResult = strconv.FormatInt(-99999, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_float_1":
+ expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_float_2":
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_float_3":
+ expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Value.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_env_var_1":
+ expectedResult = "$GOPATH"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_invalid_env_var":
+ expectedResult = "$DollarSignNotInEnv"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ case "param_simple_implied_empty":
+ assert.Nil(t, param.Value, "Expected nil")
+ case "param_simple_explicit_empty_1":
+ actualResult = param.Value.(string)
+ assert.Empty(t, actualResult)
+ case "param_simple_explicit_empty_2":
+ actualResult = param.Value.(string)
+ assert.Empty(t, actualResult)
+ }
+ }
+
+ // validate Outputs from this action
+ for output, param := range action.Outputs {
+ switch output {
+ case "payload":
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, param))
+
+ expectedResult = "parameter dump"
+ actualResult = param.Description
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, param))
+ }
+ }
+ }
}
// Test 9: validate manifest_parser.ComposeActions() method for implicit runtimes
// when a runtime of an action is not provided, manifest_parser determines the runtime
// based on the file extension of an action file
func TestComposeActionsForImplicitRuntimes(t *testing.T) {
- data :=
- `package:
+ data :=
+ `package:
name: helloworld
actions:
helloNodejs:
@@ -504,403 +503,402 @@ func TestComposeActionsForImplicitRuntimes(t *testing.T) {
function: ../tests/src/integration/helloworld/actions/hello.py
helloSwift:
function: ../tests/src/integration/helloworld/actions/hello.swift`
- p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
- actions, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
- var expectedResult string
- if err == nil {
- for i := 0; i < len(actions); i++ {
- if actions[i].Action.Name == "helloNodejs" {
- expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["js"]]
- } else if actions[i].Action.Name == "helloJava" {
- expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["jar"]]
- } else if actions[i].Action.Name == "helloPython" {
- expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["py"]]
- } else if actions[i].Action.Name == "helloSwift" {
- expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["swift"]]
- }
- actualResult := actions[i].Action.Exec.Kind
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+ p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
+ actions, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
+ var expectedResult string
+ if err == nil {
+ for i := 0; i < len(actions); i++ {
+ if actions[i].Action.Name == "helloNodejs" {
+ expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["js"]]
+ } else if actions[i].Action.Name == "helloJava" {
+ expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["jar"]]
+ } else if actions[i].Action.Name == "helloPython" {
+ expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["py"]]
+ } else if actions[i].Action.Name == "helloSwift" {
+ expectedResult = utils.DefaultRunTimes[utils.FileExtensionRuntimeKindMap["swift"]]
+ }
+ actualResult := actions[i].Action.Exec.Kind
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+ }
}
- }
}
-
// Test 10(1): validate manifest_parser.ComposeActions() method for invalid runtimes
// when the action has a source file written in unsupported runtimes, manifest_parser should
// report an error for that action
func TestComposeActionsForInvalidRuntime_1(t *testing.T) {
- data := `packages:
+ data := `packages:
helloworld:
actions:
helloInvalidRuntime:
function: ../tests/src/integration/common/wskdeploy.go`
- p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
- _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
- assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
+ p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
+ _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
+ assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
}
// Test 10(2): validate manifest_parser.ComposeActions() method for invalid runtimes
// when a runtime of an action is missing for zip action, manifest_parser should
// report an error for that action
func TestComposeActionsForInvalidRuntime_2(t *testing.T) {
- data := `packages:
+ data := `packages:
helloworld:
actions:
helloInvalidRuntime:
function: ../tests/src/integration/runtimetests/src/helloworld/`
- p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
- _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
- assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
+ p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
+ _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
+ assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
}
// Test 10(3): validate manifest_parser.ComposeActions() method for invalid runtimes
// when a runtime of an action is missing for zip action, manifest_parser should
// report an error for that action
func TestComposeActionsForInvalidRuntime_3(t *testing.T) {
- data := `packages:
+ data := `packages:
helloworld:
actions:
helloInvalidRuntime:
function: ../tests/src/integration/runtimetests/src/helloworld/helloworld.zip`
- p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
- _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
- assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
+ p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
+ _, err := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
+ assert.NotNil(t, err, fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_ERROR_EXPECTED, tmpfile))
}
// Test 10(3): validate manifest_parser.ComposeActions() method for valid runtimes with zip action
// when a runtime of a zip action is set to one of the supported runtimes, manifest_parser should
// return a valid actionRecord with specified runtime
func TestComposeActionsForValidRuntime_ZipAction(t *testing.T) {
- data := `packages:
+ data := `packages:
helloworld:
actions:
hello:
function: ../tests/src/integration/runtimetests/src/helloworld/helloworld.zip
runtime: nodejs:6`
- p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
- actions, _ := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
- for _, action := range actions {
- if action.Action.Name == "hello" {
- assert.Equal(t, action.Action.Exec.Kind, "nodejs:6", fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH, action))
- }
-
- }
+ p, m, tmpfile := testUnmarshalTemporaryFile([]byte(data), "manifest_parser_validate_runtime_")
+ actions, _ := p.ComposeActionsFromAllPackages(m, tmpfile, whisk.KeyValue{})
+ for _, action := range actions {
+ if action.Action.Name == "hello" {
+ assert.Equal(t, action.Action.Exec.Kind, "nodejs:6", fmt.Sprintf(TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH, action))
+ }
+
+ }
}
// Test 11: validate manifest_parser.ComposeActions() method for single line parameters
// manifest_parser should be able to parse input section with different types of values
func TestComposeActionsForSingleLineParams(t *testing.T) {
- // manifest file is located under ../tests folder
- manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
-
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, err := p.ParseManifest(manifestFile)
-
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
- }
-
- // Call the method we are testing
- actions, err := p.ComposeActionsFromAllPackages(m, manifestFile, whisk.KeyValue{})
-
- if err == nil {
- // test # actions
- assert.Equal(t, 1, len(actions), TEST_MSG_ACTION_NUMBER_MISMATCH)
-
- action := actions[0]
-
- /*
- * Simple 'string' value tests
- */
-
- // param_simple_string should value "foo"
- paramName := "param_simple_string"
- expectedResult := "foo"
- actualResult := action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Simple 'integer' value tests
- */
-
- // param_simple_integer_1 should have value 1
- paramName = "param_simple_integer_1"
- expectedResult = strconv.FormatInt(1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_integer_2 should have value 0
- paramName = "param_simple_integer_2"
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_integer_3 should have value -1
- paramName = "param_simple_integer_3"
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_integer_4 should have value 99999
- paramName = "param_simple_integer_4"
- expectedResult = strconv.FormatInt(99999, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_integer_5 should have value -99999
- paramName = "param_simple_integer_5"
- expectedResult = strconv.FormatInt(-99999, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Simple 'float' value tests
- */
-
- // param_simple_float_1 should have value 1.1
- paramName = "param_simple_float_1"
- expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult,fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_float_2 should have value 0.0
- paramName = "param_simple_float_2"
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_float_3 should have value -1.1
- paramName = "param_simple_float_3"
- expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Environment Variable / dollar ($) notation tests
- */
-
- // param_simple_env_var_1 should have value of env. variable $GOPATH
- paramName = "param_simple_env_var_1"
- expectedResult = os.Getenv("GOPATH")
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_env_var_2 should have value of env. variable $GOPATH
- paramName = "param_simple_env_var_2"
- expectedResult = os.Getenv("GOPATH")
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_env_var_3 should have value of env. variable "${}"
- paramName = "param_simple_env_var_3"
- expectedResult = "${}"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_invalid_env_var should have value of ""
- paramName = "param_simple_invalid_env_var"
- expectedResult = ""
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Environment Variable concatenation tests
- */
-
- // param_simple_env_var_concat_1 should have value of env. variable "$GOPTH/test" empty string
- paramName = "param_simple_env_var_concat_1"
- expectedResult = os.Getenv("GOPATH") + "/test"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_env_var_concat_2 should have value of env. variable "" empty string
- // as the "/test" is treated as part of the environment var. and not concatenated.
- paramName = "param_simple_env_var_concat_2"
- expectedResult = ""
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_env_var_concat_3 should have value of env. variable "" empty string
- paramName = "param_simple_env_var_concat_3"
- expectedResult = "ddd.ccc." + os.Getenv("GOPATH")
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Empty string tests
- */
-
- // param_simple_implied_empty should be ""
- paramName = "param_simple_implied_empty"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_explicit_empty_1 should be ""
- paramName = "param_simple_explicit_empty_1"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_explicit_empty_2 should be ""
- paramName = "param_simple_explicit_empty_2"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- /*
- * Test values that contain "Type names" (e.g., "string", "integer", "float, etc.)
- */
-
- // param_simple_type_string should be "" when value set to "string"
- paramName = "param_simple_type_string"
- expectedResult = ""
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_type_integer should be 0.0 when value set to "integer"
- paramName = "param_simple_type_integer"
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_simple_type_float should be 0 when value set to "float"
- paramName = "param_simple_type_float"
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
+
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, err := p.ParseManifest(manifestFile)
+
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
+ }
+
+ // Call the method we are testing
+ actions, err := p.ComposeActionsFromAllPackages(m, manifestFile, whisk.KeyValue{})
+
+ if err == nil {
+ // test # actions
+ assert.Equal(t, 1, len(actions), TEST_MSG_ACTION_NUMBER_MISMATCH)
+
+ action := actions[0]
+
+ /*
+ * Simple 'string' value tests
+ */
+
+ // param_simple_string should value "foo"
+ paramName := "param_simple_string"
+ expectedResult := "foo"
+ actualResult := action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Simple 'integer' value tests
+ */
+
+ // param_simple_integer_1 should have value 1
+ paramName = "param_simple_integer_1"
+ expectedResult = strconv.FormatInt(1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_integer_2 should have value 0
+ paramName = "param_simple_integer_2"
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_integer_3 should have value -1
+ paramName = "param_simple_integer_3"
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_integer_4 should have value 99999
+ paramName = "param_simple_integer_4"
+ expectedResult = strconv.FormatInt(99999, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_integer_5 should have value -99999
+ paramName = "param_simple_integer_5"
+ expectedResult = strconv.FormatInt(-99999, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Simple 'float' value tests
+ */
+
+ // param_simple_float_1 should have value 1.1
+ paramName = "param_simple_float_1"
+ expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_float_2 should have value 0.0
+ paramName = "param_simple_float_2"
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_float_3 should have value -1.1
+ paramName = "param_simple_float_3"
+ expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Environment Variable / dollar ($) notation tests
+ */
+
+ // param_simple_env_var_1 should have value of env. variable $GOPATH
+ paramName = "param_simple_env_var_1"
+ expectedResult = os.Getenv("GOPATH")
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_env_var_2 should have value of env. variable $GOPATH
+ paramName = "param_simple_env_var_2"
+ expectedResult = os.Getenv("GOPATH")
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_env_var_3 should have value of env. variable "${}"
+ paramName = "param_simple_env_var_3"
+ expectedResult = "${}"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_invalid_env_var should have value of ""
+ paramName = "param_simple_invalid_env_var"
+ expectedResult = ""
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Environment Variable concatenation tests
+ */
+
+ // param_simple_env_var_concat_1 should have value of env. variable "$GOPTH/test" empty string
+ paramName = "param_simple_env_var_concat_1"
+ expectedResult = os.Getenv("GOPATH") + "/test"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_env_var_concat_2 should have value of env. variable "" empty string
+ // as the "/test" is treated as part of the environment var. and not concatenated.
+ paramName = "param_simple_env_var_concat_2"
+ expectedResult = ""
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_env_var_concat_3 should have value of env. variable "" empty string
+ paramName = "param_simple_env_var_concat_3"
+ expectedResult = "ddd.ccc." + os.Getenv("GOPATH")
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Empty string tests
+ */
+
+ // param_simple_implied_empty should be ""
+ paramName = "param_simple_implied_empty"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_explicit_empty_1 should be ""
+ paramName = "param_simple_explicit_empty_1"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_explicit_empty_2 should be ""
+ paramName = "param_simple_explicit_empty_2"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ /*
+ * Test values that contain "Type names" (e.g., "string", "integer", "float, etc.)
+ */
+
+ // param_simple_type_string should be "" when value set to "string"
+ paramName = "param_simple_type_string"
+ expectedResult = ""
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_type_integer should be 0.0 when value set to "integer"
+ paramName = "param_simple_type_integer"
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_simple_type_float should be 0 when value set to "float"
+ paramName = "param_simple_type_float"
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ }
}
// Test 12: validate manifest_parser.ComposeActions() method for multi line parameters
// manifest_parser should be able to parse input section with different types of values
func TestComposeActionsForMultiLineParams(t *testing.T) {
- // manifest file is located under ../tests folder
- manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
-
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, err := p.ParseManifest(manifestFile)
-
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
- }
-
- // call the method we are testing
- actions, err := p.ComposeActionsFromAllPackages(m, manifestFile, whisk.KeyValue{})
-
- if err == nil {
- // test # actions
- assert.Equal(t, 1, len(actions), TEST_MSG_ACTION_NUMBER_MISMATCH)
-
- action := actions[0]
-
- // param_string_value_only should be "foo"
- paramName := "param_string_value_only"
- expectedResult := "foo"
- actualResult := action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_int_value_only should be 123
- paramName = "param_int_value_only"
- expectedResult = strconv.FormatInt(123, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_float_value_only should be 3.14
- paramName = "param_float_value_only"
- expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_string_type_and_value_only should be foo
- paramName = "param_string_type_and_value_only"
- expectedResult = "foo"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_string_type_only should be ""
- paramName = "param_string_type_only"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_integer_type_only should be 0
- paramName = "param_integer_type_only"
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_float_type_only should be 0
- paramName = "param_float_type_only"
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_string_with_default should be "bar"
- paramName = "param_string_with_default"
- expectedResult = "bar"
- actualResult = action.Action.Parameters.GetValue(paramName).(string)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_integer_with_default should be -1
- paramName = "param_integer_with_default"
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
-
- // param_float_with_default should be 2.9
- paramName = "param_float_with_default"
- expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
+
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, err := p.ParseManifest(manifestFile)
+
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
+ }
+
+ // call the method we are testing
+ actions, err := p.ComposeActionsFromAllPackages(m, manifestFile, whisk.KeyValue{})
+
+ if err == nil {
+ // test # actions
+ assert.Equal(t, 1, len(actions), TEST_MSG_ACTION_NUMBER_MISMATCH)
+
+ action := actions[0]
+
+ // param_string_value_only should be "foo"
+ paramName := "param_string_value_only"
+ expectedResult := "foo"
+ actualResult := action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_int_value_only should be 123
+ paramName = "param_int_value_only"
+ expectedResult = strconv.FormatInt(123, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_float_value_only should be 3.14
+ paramName = "param_float_value_only"
+ expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_string_type_and_value_only should be foo
+ paramName = "param_string_type_and_value_only"
+ expectedResult = "foo"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_string_type_only should be ""
+ paramName = "param_string_type_only"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Empty(t, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_integer_type_only should be 0
+ paramName = "param_integer_type_only"
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_float_type_only should be 0
+ paramName = "param_float_type_only"
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_string_with_default should be "bar"
+ paramName = "param_string_with_default"
+ expectedResult = "bar"
+ actualResult = action.Action.Parameters.GetValue(paramName).(string)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_integer_with_default should be -1
+ paramName = "param_integer_with_default"
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue(paramName).(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+
+ // param_float_with_default should be 2.9
+ paramName = "param_float_with_default"
+ expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue(paramName).(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+ }
}
// Test 13: validate manifest_parser.ComposeActions() method
func TestComposeActionsForFunction(t *testing.T) {
- data :=
- `package:
+ data :=
+ `package:
name: helloworld
actions:
hello1:
function: ../tests/src/integration/helloworld/actions/hello.js`
- // (TODO) uncomment this after we add support for action file content from URL
- // hello2:
- // function: https://raw.githubusercontent.com/apache/incubator-openwhisk-wskdeploy/master/tests/isrc/integration/helloworld/manifest.yaml`
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_locations_")
- if err == nil {
- defer os.Remove(tmpfile.Name()) // clean up
- if _, err := tmpfile.Write([]byte(data)); err == nil {
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
- var expectedResult, actualResult string
- if err == nil {
- for i := 0; i < len(actions); i++ {
- if actions[i].Action.Name == "hello1" {
- expectedResult, _ = filepath.Abs("../tests/src/integration/helloworld/actions/hello.js")
- actualResult, _ = filepath.Abs(actions[i].Filepath)
- assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
- // (TODO) Uncomment the following condition, hello2
- // (TODO) after issue # 311 is fixed
- //} else if actions[i].Action.Name == "hello2" {
- // assert.NotNil(t, actions[i].Action.Exec.Code, "Expected source code from an action file but found it empty")
- }
- }
- }
-
- }
- tmpfile.Close()
- }
+ // (TODO) uncomment this after we add support for action file content from URL
+ // hello2:
+ // function: https://raw.githubusercontent.com/apache/incubator-openwhisk-wskdeploy/master/tests/isrc/integration/helloworld/manifest.yaml`
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_locations_")
+ if err == nil {
+ defer os.Remove(tmpfile.Name()) // clean up
+ if _, err := tmpfile.Write([]byte(data)); err == nil {
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
+ var expectedResult, actualResult string
+ if err == nil {
+ for i := 0; i < len(actions); i++ {
+ if actions[i].Action.Name == "hello1" {
+ expectedResult, _ = filepath.Abs("../tests/src/integration/helloworld/actions/hello.js")
+ actualResult, _ = filepath.Abs(actions[i].Filepath)
+ assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
+ // (TODO) Uncomment the following condition, hello2
+ // (TODO) after issue # 311 is fixed
+ //} else if actions[i].Action.Name == "hello2" {
+ // assert.NotNil(t, actions[i].Action.Exec.Code, "Expected source code from an action file but found it empty")
+ }
+ }
+ }
+
+ }
+ tmpfile.Close()
+ }
}
// Test 14: validate manifest_parser.ComposeActions() method
-func TestComposeActionsForLimits (t *testing.T) {
- data :=
-`package:
+func TestComposeActionsForLimits(t *testing.T) {
+ data :=
+ `package:
name: helloworld
actions:
hello1:
@@ -917,319 +915,319 @@ func TestComposeActionsForLimits (t *testing.T) {
userInvocationRate: 50
codeSize: 1024
parameterSize: 128`
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_limits_")
- if err == nil {
- defer os.Remove(tmpfile.Name()) // clean up
- if _, err := tmpfile.Write([]byte(data)); err == nil {
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
- //var expectedResult, actualResult string
- if err == nil {
- for i:=0; i<len(actions); i++ {
- if actions[i].Action.Name == "hello1" {
- assert.Nil(t, actions[i].Action.Limits, "Expected limit section to be empty but got %s", actions[i].Action.Limits)
- } else if actions[i].Action.Name == "hello2" {
- assert.NotNil(t, actions[i].Action.Limits, "Expected limit section to be not empty but found it empty")
- assert.Equal(t, 180, *actions[i].Action.Limits.Timeout, "Failed to get Timeout")
- assert.Equal(t, 128, *actions[i].Action.Limits.Memory, "Failed to get Memory")
- assert.Equal(t, 1, *actions[i].Action.Limits.Logsize, "Failed to get Logsize")
- }
- }
- }
-
- }
- tmpfile.Close()
- }
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_limits_")
+ if err == nil {
+ defer os.Remove(tmpfile.Name()) // clean up
+ if _, err := tmpfile.Write([]byte(data)); err == nil {
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
+ //var expectedResult, actualResult string
+ if err == nil {
+ for i := 0; i < len(actions); i++ {
+ if actions[i].Action.Name == "hello1" {
+ assert.Nil(t, actions[i].Action.Limits, "Expected limit section to be empty but got %s", actions[i].Action.Limits)
+ } else if actions[i].Action.Name == "hello2" {
+ assert.NotNil(t, actions[i].Action.Limits, "Expected limit section to be not empty but found it empty")
+ assert.Equal(t, 180, *actions[i].Action.Limits.Timeout, "Failed to get Timeout")
+ assert.Equal(t, 128, *actions[i].Action.Limits.Memory, "Failed to get Memory")
+ assert.Equal(t, 1, *actions[i].Action.Limits.Logsize, "Failed to get Logsize")
+ }
+ }
+ }
+
+ }
+ tmpfile.Close()
+ }
}
// Test 15: validate manifest_parser.ComposeActions() method
func TestComposeActionsForWebActions(t *testing.T) {
- data :=
- `package:
+ data :=
+ `package:
name: helloworld
actions:
hello:
function: ../tests/src/integration/helloworld/actions/hello.js
web-export: true`
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_web_actions_")
- if err == nil {
- defer os.Remove(tmpfile.Name()) // clean up
- if _, err := tmpfile.Write([]byte(data)); err == nil {
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
- if err == nil {
- for i := 0; i < len(actions); i++ {
- if actions[i].Action.Name == "hello" {
- for _, a := range actions[i].Action.Annotations {
- switch a.Key {
- case "web-export":
- assert.Equal(t, true, a.Value, "Expected true for web-export but got " + strconv.FormatBool(a.Value.(bool)))
- case "raw-http":
- assert.Equal(t, false, a.Value, "Expected false for raw-http but got " + strconv.FormatBool(a.Value.(bool)))
- case "final":
- assert.Equal(t, true, a.Value, "Expected true for final but got " + strconv.FormatBool(a.Value.(bool)))
- }
- }
- }
- }
- }
-
- }
- tmpfile.Close()
- }
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_web_actions_")
+ if err == nil {
+ defer os.Remove(tmpfile.Name()) // clean up
+ if _, err := tmpfile.Write([]byte(data)); err == nil {
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ actions, err := p.ComposeActionsFromAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
+ if err == nil {
+ for i := 0; i < len(actions); i++ {
+ if actions[i].Action.Name == "hello" {
+ for _, a := range actions[i].Action.Annotations {
+ switch a.Key {
+ case "web-export":
+ assert.Equal(t, true, a.Value, "Expected true for web-export but got "+strconv.FormatBool(a.Value.(bool)))
+ case "raw-http":
+ assert.Equal(t, false, a.Value, "Expected false for raw-http but got "+strconv.FormatBool(a.Value.(bool)))
+ case "final":
+ assert.Equal(t, true, a.Value, "Expected true for final but got "+strconv.FormatBool(a.Value.(bool)))
+ }
+ }
+ }
+ }
+ }
+
+ }
+ tmpfile.Close()
+ }
}
// Test 16: validate manifest_parser.ResolveParameter() method
func TestResolveParameterForMultiLineParams(t *testing.T) {
- paramName := "name"
- v := "foo"
- y := reflect.TypeOf(v).Name() // y := string
- d := "default_name"
-
- // type string - value only param
- param1 := Parameter{Value: v, multiline: true}
- r1, _ := ResolveParameter(paramName, ¶m1, "")
- assert.Equal(t, v, r1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH,paramName))
- assert.IsType(t, v, r1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH,paramName))
-
- // type string - type and value only param
- param2 := Parameter{Type: y, Value: v, multiline: true}
- r2, _ := ResolveParameter(paramName, ¶m2, "")
- assert.Equal(t, v, r2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH,paramName))
- assert.IsType(t, v, r2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH,paramName))
-
- // type string - type, no value, but default value param
- param3 := Parameter{Type: y, Default: d, multiline: true}
- r3, _ := ResolveParameter(paramName, ¶m3, "")
- assert.Equal(t, d, r3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH,paramName))
- assert.IsType(t, d, r3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH,paramName))
-
- // type string - type and value only param
- // type is "string" and value is of type "int"
- // ResolveParameter matches specified type with the type of the specified value
- // it fails if both types don't match
- // ResolveParameter determines type from the specified value
- // in this case, ResolveParameter returns value of type int
- v1 := 11
- param4 := Parameter{Type: y, Value: v1, multiline: true}
- r4, _ := ResolveParameter(paramName, ¶m4, "")
- assert.Equal(t, v1, r4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH,paramName))
- assert.IsType(t, v1, r4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH,paramName))
-
- // type invalid - type only param
- param5 := Parameter{Type: "invalid", multiline: true}
- _, err := ResolveParameter(paramName, ¶m5, "")
- assert.NotNil(t, err, "Expected error saying Invalid type for parameter")
- switch errorType := err.(type) {
- default:
- assert.Fail(t, "Wrong error type received: We are expecting ParserErr.")
- case *wskderrors.YAMLParserError:
- assert.Equal(t, "Parameter [name] has an invalid Type. [invalid]", errorType.Message)
- }
-
- // type none - param without type, without value, and without default value
- param6 := Parameter{multiline: true}
- paramName = "none"
- r6, _ := ResolveParameter(paramName, ¶m6, "")
- assert.Empty(t, r6, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH,paramName))
+ paramName := "name"
+ v := "foo"
+ y := reflect.TypeOf(v).Name() // y := string
+ d := "default_name"
+
+ // type string - value only param
+ param1 := Parameter{Value: v, multiline: true}
+ r1, _ := ResolveParameter(paramName, ¶m1, "")
+ assert.Equal(t, v, r1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+ assert.IsType(t, v, r1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, paramName))
+
+ // type string - type and value only param
+ param2 := Parameter{Type: y, Value: v, multiline: true}
+ r2, _ := ResolveParameter(paramName, ¶m2, "")
+ assert.Equal(t, v, r2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+ assert.IsType(t, v, r2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, paramName))
+
+ // type string - type, no value, but default value param
+ param3 := Parameter{Type: y, Default: d, multiline: true}
+ r3, _ := ResolveParameter(paramName, ¶m3, "")
+ assert.Equal(t, d, r3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+ assert.IsType(t, d, r3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, paramName))
+
+ // type string - type and value only param
+ // type is "string" and value is of type "int"
+ // ResolveParameter matches specified type with the type of the specified value
+ // it fails if both types don't match
+ // ResolveParameter determines type from the specified value
+ // in this case, ResolveParameter returns value of type int
+ v1 := 11
+ param4 := Parameter{Type: y, Value: v1, multiline: true}
+ r4, _ := ResolveParameter(paramName, ¶m4, "")
+ assert.Equal(t, v1, r4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
+ assert.IsType(t, v1, r4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, paramName))
+
+ // type invalid - type only param
+ param5 := Parameter{Type: "invalid", multiline: true}
+ _, err := ResolveParameter(paramName, ¶m5, "")
+ assert.NotNil(t, err, "Expected error saying Invalid type for parameter")
+ switch errorType := err.(type) {
+ default:
+ assert.Fail(t, "Wrong error type received: We are expecting ParserErr.")
+ case *wskderrors.YAMLParserError:
+ assert.Equal(t, "Parameter [name] has an invalid Type. [invalid]", errorType.Message)
+ }
+
+ // type none - param without type, without value, and without default value
+ param6 := Parameter{multiline: true}
+ paramName = "none"
+ r6, _ := ResolveParameter(paramName, ¶m6, "")
+ assert.Empty(t, r6, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, paramName))
}
// Test 17: validate JSON parameters
func TestParseManifestForJSONParams(t *testing.T) {
- // manifest file is located under ../tests folder
- manifestFile := "../tests/dat/manifest_validate_json_params.yaml"
- // read and parse manifest.yaml file
- m, err := NewYAMLParser().ParseManifest(manifestFile)
-
- if err != nil {
- assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
- }
-
- // validate package name should be "validate"
- packageName := "validate_json"
- actionName := "validate_json_params"
-
- // validate this package contains one action
- actualActionsCount := len(m.Packages[packageName].Actions)
- assert.Equal(t, 1, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
-
- if action, ok := m.Packages[packageName].Actions[actionName]; ok {
- // test Action function's path
- expectedResult := "actions/dump_params.js"
- actualResult := action.Function
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
-
- // validate runtime of an action to be "nodejs:6"
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
-
- // validate the number of inputs to this action
- expectedResult = strconv.FormatInt(6, 10)
- actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
- assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
-
- // validate inputs to this action
- for input, param := range action.Inputs {
- // Trace to help debug complex values:
- // utils.PrintTypeInfo(input, param.Value)
- switch input {
- case "member1":
- actualResult1 := param.Value.(string)
- expectedResult1 := "{ \"name\": \"Sam\", \"place\": \"Shire\" }"
- assert.Equal(t, expectedResult1, actualResult1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- case "member2":
- actualResult2 := param.Value.(map[interface{}]interface{})
- expectedResult2 := map[interface{}]interface{}{"name": "Sam", "place": "Shire"}
- assert.Equal(t, expectedResult2, actualResult2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- case "member3":
- actualResult3 := param.Value.(map[interface{}]interface{})
- expectedResult3 := map[interface{}]interface{}{"name": "Elrond", "place": "Rivendell"}
- assert.Equal(t, expectedResult3, actualResult3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- case "member4":
- actualResult4 := param.Value.(map[interface{}]interface{})
- expectedResult4 := map[interface{}]interface{}{"name": "Gimli", "place": "Gondor", "age": 139, "children": map[interface{}]interface{}{ "<none>": "<none>" }}
- assert.Equal(t, expectedResult4, actualResult4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- case "member5":
- actualResult5 := param.Value.(map[interface{}]interface{})
- expectedResult5 := map[interface{}]interface{}{"name": "Gloin", "place": "Gondor", "age": 235, "children": map[interface{}]interface{}{ "Gimli": "Son" }}
- assert.Equal(t, expectedResult5, actualResult5, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- case "member6":
- actualResult6 := param.Value.(map[interface{}]interface{})
- expectedResult6 := map[interface{}]interface{}{"name": "Frodo", "place": "Undying Lands", "items": []interface{}{"Sting", "Mithril mail"}}
- assert.Equal(t, expectedResult6, actualResult6, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
- }
- }
-
- // validate Outputs from this action
- for output, param := range action.Outputs {
- switch output {
- case "fellowship":
- expectedType := "json"
- actualType := param.Type
- assert.Equal(t, expectedType, actualType, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, output))
- }
- }
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_json_params.yaml"
+ // read and parse manifest.yaml file
+ m, err := NewYAMLParser().ParseManifest(manifestFile)
+
+ if err != nil {
+ assert.Fail(t, fmt.Sprintf(TEST_ERROR_MANIFEST_PARSE_FAILURE, manifestFile))
+ }
+
+ // validate package name should be "validate"
+ packageName := "validate_json"
+ actionName := "validate_json_params"
+
+ // validate this package contains one action
+ actualActionsCount := len(m.Packages[packageName].Actions)
+ assert.Equal(t, 1, actualActionsCount, TEST_MSG_ACTION_NUMBER_MISMATCH)
+
+ if action, ok := m.Packages[packageName].Actions[actionName]; ok {
+ // test Action function's path
+ expectedResult := "actions/dump_params.js"
+ actualResult := action.Function
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_PATH_MISMATCH)
+
+ // validate runtime of an action to be "nodejs:6"
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+
+ // validate the number of inputs to this action
+ expectedResult = strconv.FormatInt(6, 10)
+ actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
+ assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
+
+ // validate inputs to this action
+ for input, param := range action.Inputs {
+ // Trace to help debug complex values:
+ // utils.PrintTypeInfo(input, param.Value)
+ switch input {
+ case "member1":
+ actualResult1 := param.Value.(string)
+ expectedResult1 := "{ \"name\": \"Sam\", \"place\": \"Shire\" }"
+ assert.Equal(t, expectedResult1, actualResult1, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ case "member2":
+ actualResult2 := param.Value.(map[interface{}]interface{})
+ expectedResult2 := map[interface{}]interface{}{"name": "Sam", "place": "Shire"}
+ assert.Equal(t, expectedResult2, actualResult2, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ case "member3":
+ actualResult3 := param.Value.(map[interface{}]interface{})
+ expectedResult3 := map[interface{}]interface{}{"name": "Elrond", "place": "Rivendell"}
+ assert.Equal(t, expectedResult3, actualResult3, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ case "member4":
+ actualResult4 := param.Value.(map[interface{}]interface{})
+ expectedResult4 := map[interface{}]interface{}{"name": "Gimli", "place": "Gondor", "age": 139, "children": map[interface{}]interface{}{"<none>": "<none>"}}
+ assert.Equal(t, expectedResult4, actualResult4, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ case "member5":
+ actualResult5 := param.Value.(map[interface{}]interface{})
+ expectedResult5 := map[interface{}]interface{}{"name": "Gloin", "place": "Gondor", "age": 235, "children": map[interface{}]interface{}{"Gimli": "Son"}}
+ assert.Equal(t, expectedResult5, actualResult5, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ case "member6":
+ actualResult6 := param.Value.(map[interface{}]interface{})
+ expectedResult6 := map[interface{}]interface{}{"name": "Frodo", "place": "Undying Lands", "items": []interface{}{"Sting", "Mithril mail"}}
+ assert.Equal(t, expectedResult6, actualResult6, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+ }
+ }
+
+ // validate Outputs from this action
+ for output, param := range action.Outputs {
+ switch output {
+ case "fellowship":
+ expectedType := "json"
+ actualType := param.Type
+ assert.Equal(t, expectedType, actualType, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_TYPE_MISMATCH, output))
+ }
+ }
+ }
}
func _createTmpfile(data string, filename string) (f *os.File, err error) {
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, filename)
- if err != nil {
- return nil, err
- }
- _, err = tmpfile.Write([]byte(data))
- if err != nil {
- return tmpfile, err
- }
- return tmpfile, nil
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, filename)
+ if err != nil {
+ return nil, err
+ }
+ _, err = tmpfile.Write([]byte(data))
+ if err != nil {
+ return tmpfile, err
+ }
+ return tmpfile, nil
}
func TestComposePackage(t *testing.T) {
- data := `package:
+ data := `package:
name: helloworld
namespace: default`
- tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
- if err != nil {
- assert.Fail(t, "Failed to create temp file")
- }
- defer func() {
- tmpfile.Close()
- os.Remove(tmpfile.Name())
- }()
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- pkg, err := p.ComposeAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
- if err == nil {
- n := "helloworld"
- assert.NotNil(t, pkg[n], "Failed to get the whole package")
- assert.Equal(t, n, pkg[n].Name, "Failed to get package name")
- assert.Equal(t, "default", pkg[n].Namespace, "Failed to get package namespace")
- } else {
- assert.Fail(t, "Failed to compose package")
- }
+ tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ pkg, err := p.ComposeAllPackages(m, tmpfile.Name(), whisk.KeyValue{})
+ if err == nil {
+ n := "helloworld"
+ assert.NotNil(t, pkg[n], "Failed to get the whole package")
+ assert.Equal(t, n, pkg[n].Name, "Failed to get package name")
+ assert.Equal(t, "default", pkg[n].Namespace, "Failed to get package namespace")
+ } else {
+ assert.Fail(t, "Failed to compose package")
+ }
}
func TestComposeSequences(t *testing.T) {
- data := `package:
+ data := `package:
name: helloworld
sequences:
sequence1:
actions: action1, action2
sequence2:
actions: action3, action4, action5`
- tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
- if err != nil {
- assert.Fail(t, "Failed to create temp file")
- }
- defer func() {
- tmpfile.Close()
- os.Remove(tmpfile.Name())
- }()
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- seqList, err := p.ComposeSequencesFromAllPackages("", m, whisk.KeyValue{})
- if err != nil {
- assert.Fail(t, "Failed to compose sequences")
- }
- assert.Equal(t, 2, len(seqList), "Failed to get sequences")
- for _, seq := range seqList {
- wsk_action := seq.Action
- switch wsk_action.Name {
- case "sequence1":
- assert.Equal(t, "sequence", wsk_action.Exec.Kind, "Failed to set sequence exec kind")
- assert.Equal(t, 2, len(wsk_action.Exec.Components), "Failed to set sequence exec components")
- assert.Equal(t, "/helloworld/action1", wsk_action.Exec.Components[0], "Failed to set sequence 1st exec components")
- assert.Equal(t, "/helloworld/action2", wsk_action.Exec.Components[1], "Failed to set sequence 2nd exec components")
- case "sequence2":
- assert.Equal(t, "sequence", wsk_action.Exec.Kind, "Failed to set sequence exec kind")
- assert.Equal(t, 3, len(wsk_action.Exec.Components), "Failed to set sequence exec components")
- assert.Equal(t, "/helloworld/action3", wsk_action.Exec.Components[0], "Failed to set sequence 1st exec components")
- assert.Equal(t, "/helloworld/action4", wsk_action.Exec.Components[1], "Failed to set sequence 2nd exec components")
- assert.Equal(t, "/helloworld/action5", wsk_action.Exec.Components[2], "Failed to set sequence 3rd exec components")
- }
- }
+ tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ seqList, err := p.ComposeSequencesFromAllPackages("", m, whisk.KeyValue{})
+ if err != nil {
+ assert.Fail(t, "Failed to compose sequences")
+ }
+ assert.Equal(t, 2, len(seqList), "Failed to get sequences")
+ for _, seq := range seqList {
+ wsk_action := seq.Action
+ switch wsk_action.Name {
+ case "sequence1":
+ assert.Equal(t, "sequence", wsk_action.Exec.Kind, "Failed to set sequence exec kind")
+ assert.Equal(t, 2, len(wsk_action.Exec.Components), "Failed to set sequence exec components")
+ assert.Equal(t, "/helloworld/action1", wsk_action.Exec.Components[0], "Failed to set sequence 1st exec components")
+ assert.Equal(t, "/helloworld/action2", wsk_action.Exec.Components[1], "Failed to set sequence 2nd exec components")
+ case "sequence2":
+ assert.Equal(t, "sequence", wsk_action.Exec.Kind, "Failed to set sequence exec kind")
+ assert.Equal(t, 3, len(wsk_action.Exec.Components), "Failed to set sequence exec components")
+ assert.Equal(t, "/helloworld/action3", wsk_action.Exec.Components[0], "Failed to set sequence 1st exec components")
+ assert.Equal(t, "/helloworld/action4", wsk_action.Exec.Components[1], "Failed to set sequence 2nd exec components")
+ assert.Equal(t, "/helloworld/action5", wsk_action.Exec.Components[2], "Failed to set sequence 3rd exec components")
+ }
+ }
}
func TestComposeTriggers(t *testing.T) {
- // read and parse manifest.yaml file located under ../tests folder
- manifestFile := "../tests/dat/manifest_data_compose_triggers.yaml"
- p := NewYAMLParser()
- m, err := p.ParseManifest(manifestFile)
- if err != nil {
- assert.Fail(t, "Failed to parse manifest: " + manifestFile )
- }
-
- triggerList, err := p.ComposeTriggersFromAllPackages(m, manifestFile, whisk.KeyValue{})
- if err != nil {
- assert.Fail(t, "Failed to compose trigger")
- }
-
- assert.Equal(t, 2, len(triggerList), "Failed to get trigger list")
- for _, trigger := range triggerList {
- switch trigger.Name {
- case "trigger1":
- assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters")
- case "trigger2":
- assert.Equal(t, "feed", trigger.Annotations[0].Key, "Failed to set trigger annotation")
- assert.Equal(t, "myfeed", trigger.Annotations[0].Value, "Failed to set trigger annotation")
- assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters")
- }
- }
+ // read and parse manifest.yaml file located under ../tests folder
+ manifestFile := "../tests/dat/manifest_data_compose_triggers.yaml"
+ p := NewYAMLParser()
+ m, err := p.ParseManifest(manifestFile)
+ if err != nil {
+ assert.Fail(t, "Failed to parse manifest: "+manifestFile)
+ }
+
+ triggerList, err := p.ComposeTriggersFromAllPackages(m, manifestFile, whisk.KeyValue{})
+ if err != nil {
+ assert.Fail(t, "Failed to compose trigger")
+ }
+
+ assert.Equal(t, 2, len(triggerList), "Failed to get trigger list")
+ for _, trigger := range triggerList {
+ switch trigger.Name {
+ case "trigger1":
+ assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters")
+ case "trigger2":
+ assert.Equal(t, "feed", trigger.Annotations[0].Key, "Failed to set trigger annotation")
+ assert.Equal(t, "myfeed", trigger.Annotations[0].Value, "Failed to set trigger annotation")
+ assert.Equal(t, 2, len(trigger.Parameters), "Failed to set trigger parameters")
+ }
+ }
}
func TestComposeRules(t *testing.T) {
- data := `package:
+ data := `package:
name: helloworld
rules:
rule1:
@@ -1238,36 +1236,36 @@ func TestComposeRules(t *testing.T) {
rule2:
trigger: trigger1
action: action1`
- tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
- if err != nil {
- assert.Fail(t, "Failed to create temp file")
- }
- defer func() {
- tmpfile.Close()
- os.Remove(tmpfile.Name())
- }()
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- ruleList, err := p.ComposeRulesFromAllPackages(m)
- if err != nil {
- assert.Fail(t, "Failed to compose rules")
- }
- assert.Equal(t, 2, len(ruleList), "Failed to get rules")
- for _, rule := range ruleList {
- switch rule.Name {
- case "rule1":
- assert.Equal(t, "locationUpdate", rule.Trigger, "Failed to set rule trigger")
- assert.Equal(t, "helloworld/greeting", rule.Action, "Failed to set rule action")
- case "rule2":
- assert.Equal(t, "trigger1", rule.Trigger, "Failed to set rule trigger")
- assert.Equal(t, "helloworld/action1", rule.Action, "Failed to set rule action")
- }
- }
+ tmpfile, err := _createTmpfile(data, "manifest_parser_test_compose_package_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ ruleList, err := p.ComposeRulesFromAllPackages(m)
+ if err != nil {
+ assert.Fail(t, "Failed to compose rules")
+ }
+ assert.Equal(t, 2, len(ruleList), "Failed to get rules")
+ for _, rule := range ruleList {
+ switch rule.Name {
+ case "rule1":
+ assert.Equal(t, "locationUpdate", rule.Trigger, "Failed to set rule trigger")
+ assert.Equal(t, "helloworld/greeting", rule.Action, "Failed to set rule action")
+ case "rule2":
+ assert.Equal(t, "trigger1", rule.Trigger, "Failed to set rule trigger")
+ assert.Equal(t, "helloworld/action1", rule.Action, "Failed to set rule action")
+ }
+ }
}
func TestComposeApiRecords(t *testing.T) {
- data := `package:
+ data := `package:
name: helloworld
apis:
book-club:
@@ -1284,64 +1282,64 @@ func TestComposeApiRecords(t *testing.T) {
postBooks2: post
members2:
listMembers2: get`
- tmpfile, err := _createTmpfile(data, "manifest_parser_test_")
- if err != nil {
- assert.Fail(t, "Failed to create temp file")
- }
- defer func() {
- tmpfile.Close()
- os.Remove(tmpfile.Name())
- }()
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- apiList, err := p.ComposeApiRecordsFromAllPackages(m)
- if err != nil {
- assert.Fail(t, "Failed to compose api records")
- }
- assert.Equal(t, 6, len(apiList), "Failed to get api records")
- for _, apiRecord := range apiList {
- apiDoc := apiRecord.ApiDoc
- action := apiDoc.Action
- switch action.Name {
- case "putBooks":
- assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "books", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "put", action.BackendMethod, "Failed to set api backend method")
- case "deleteBooks":
- assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "books", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "delete", action.BackendMethod, "Failed to set api backend method")
- case "listMembers":
- assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "members", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
- case "getBooks2":
- assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "books2", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
- case "postBooks2":
- assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "books2", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "post", action.BackendMethod, "Failed to set api backend method")
- case "listMembers2":
- assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
- assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
- assert.Equal(t, "members2", apiDoc.GatewayRelPath, "Failed to set api rel path")
- assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
- default:
- assert.Fail(t, "Failed to get api action name")
- }
- }
+ tmpfile, err := _createTmpfile(data, "manifest_parser_test_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ apiList, err := p.ComposeApiRecordsFromAllPackages(m)
+ if err != nil {
+ assert.Fail(t, "Failed to compose api records")
+ }
+ assert.Equal(t, 6, len(apiList), "Failed to get api records")
+ for _, apiRecord := range apiList {
+ apiDoc := apiRecord.ApiDoc
+ action := apiDoc.Action
+ switch action.Name {
+ case "putBooks":
+ assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "books", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "put", action.BackendMethod, "Failed to set api backend method")
+ case "deleteBooks":
+ assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "books", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "delete", action.BackendMethod, "Failed to set api backend method")
+ case "listMembers":
+ assert.Equal(t, "book-club", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "members", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
+ case "getBooks2":
+ assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "books2", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
+ case "postBooks2":
+ assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "books2", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "post", action.BackendMethod, "Failed to set api backend method")
+ case "listMembers2":
+ assert.Equal(t, "book-club2", apiDoc.ApiName, "Failed to set api name")
+ assert.Equal(t, "club2", apiDoc.GatewayBasePath, "Failed to set api base path")
+ assert.Equal(t, "members2", apiDoc.GatewayRelPath, "Failed to set api rel path")
+ assert.Equal(t, "get", action.BackendMethod, "Failed to set api backend method")
+ default:
+ assert.Fail(t, "Failed to get api action name")
+ }
+ }
}
func TestComposeDependencies(t *testing.T) {
- data := `package:
+ data := `package:
name: helloworld
dependencies:
myhelloworld:
@@ -1352,90 +1350,90 @@ func TestComposeDependencies(t *testing.T) {
dbname: myGreatDB
annotations:
myAnnotation: Here it is`
- tmpfile, err := _createTmpfile(data, "manifest_parser_test_")
- if err != nil {
- assert.Fail(t, "Failed to create temp file")
- }
- defer func() {
- tmpfile.Close()
- os.Remove(tmpfile.Name())
- }()
- // read and parse manifest.yaml file
- p := NewYAMLParser()
- m, _ := p.ParseManifest(tmpfile.Name())
- depdList, err := p.ComposeDependenciesFromAllPackages(m, "/project_folder", tmpfile.Name())
- if err != nil {
- assert.Fail(t, "Failed to compose rules")
- }
- assert.Equal(t, 2, len(depdList), "Failed to get rules")
- for depdy_name, depdy := range depdList {
- assert.Equal(t, "helloworld", depdy.Packagename, "Failed to set dependecy isbinding")
- assert.Equal(t, "/project_folder/Packages", depdy.ProjectPath, "Failed to set dependecy isbinding")
- d := strings.Split(depdy_name, ":")
- assert.NotEqual(t, d[1], "", "Failed to get dependency name")
- switch d[1] {
- case "myhelloworld":
- assert.Equal(t, "https://github.com/user/repo/folder", depdy.Location, "Failed to set dependecy location")
- assert.Equal(t, false, depdy.IsBinding, "Failed to set dependecy isbinding")
- assert.Equal(t, "https://github.com/user/repo", depdy.BaseRepo, "Failed to set dependecy base repo url")
- assert.Equal(t, "/folder", depdy.SubFolder, "Failed to set dependecy sub folder")
- case "myCloudant":
- assert.Equal(t, "/whisk.system/cloudant", depdy.Location, "Failed to set rule trigger")
- assert.Equal(t, true, depdy.IsBinding, "Failed to set dependecy isbinding")
- assert.Equal(t, 1, len(depdy.Parameters), "Failed to set dependecy parameter")
- assert.Equal(t, 1, len(depdy.Annotations), "Failed to set dependecy annotation")
- assert.Equal(t, "myAnnotation", depdy.Annotations[0].Key, "Failed to set dependecy parameter key")
- assert.Equal(t, "Here it is", depdy.Annotations[0].Value, "Failed to set dependecy parameter value")
- assert.Equal(t, "dbname", depdy.Parameters[0].Key, "Failed to set dependecy annotation key")
- assert.Equal(t, "myGreatDB", depdy.Parameters[0].Value, "Failed to set dependecy annotation value")
- default:
- assert.Fail(t, "Failed to get dependency name")
- }
- }
+ tmpfile, err := _createTmpfile(data, "manifest_parser_test_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(tmpfile.Name())
+ depdList, err := p.ComposeDependenciesFromAllPackages(m, "/project_folder", tmpfile.Name())
+ if err != nil {
+ assert.Fail(t, "Failed to compose rules")
+ }
+ assert.Equal(t, 2, len(depdList), "Failed to get rules")
+ for depdy_name, depdy := range depdList {
+ assert.Equal(t, "helloworld", depdy.Packagename, "Failed to set dependecy isbinding")
+ assert.Equal(t, "/project_folder/Packages", depdy.ProjectPath, "Failed to set dependecy isbinding")
+ d := strings.Split(depdy_name, ":")
+ assert.NotEqual(t, d[1], "", "Failed to get dependency name")
+ switch d[1] {
+ case "myhelloworld":
+ assert.Equal(t, "https://github.com/user/repo/folder", depdy.Location, "Failed to set dependecy location")
+ assert.Equal(t, false, depdy.IsBinding, "Failed to set dependecy isbinding")
+ assert.Equal(t, "https://github.com/user/repo", depdy.BaseRepo, "Failed to set dependecy base repo url")
+ assert.Equal(t, "/folder", depdy.SubFolder, "Failed to set dependecy sub folder")
+ case "myCloudant":
+ assert.Equal(t, "/whisk.system/cloudant", depdy.Location, "Failed to set rule trigger")
+ assert.Equal(t, true, depdy.IsBinding, "Failed to set dependecy isbinding")
+ assert.Equal(t, 1, len(depdy.Parameters), "Failed to set dependecy parameter")
+ assert.Equal(t, 1, len(depdy.Annotations), "Failed to set dependecy annotation")
+ assert.Equal(t, "myAnnotation", depdy.Annotations[0].Key, "Failed to set dependecy parameter key")
+ assert.Equal(t, "Here it is", depdy.Annotations[0].Value, "Failed to set dependecy parameter value")
+ assert.Equal(t, "dbname", depdy.Parameters[0].Key, "Failed to set dependecy annotation key")
+ assert.Equal(t, "myGreatDB", depdy.Parameters[0].Value, "Failed to set dependecy annotation value")
+ default:
+ assert.Fail(t, "Failed to get dependency name")
+ }
+ }
}
func TestBadYAMLInvalidPackageKeyInManifest(t *testing.T) {
- // read and parse manifest.yaml file located under ../tests folder
- p := NewYAMLParser()
- _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_package_key.yaml")
+ // read and parse manifest.yaml file located under ../tests folder
+ p := NewYAMLParser()
+ _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_package_key.yaml")
- assert.NotNil(t, err)
- // NOTE: go-yaml/yaml gets the line # wrong; testing only for the invalid key message
- assert.Contains(t, err.Error(), "field invalidKey not found in struct parsers.Package")
+ assert.NotNil(t, err)
+ // NOTE: go-yaml/yaml gets the line # wrong; testing only for the invalid key message
+ assert.Contains(t, err.Error(), "field invalidKey not found in struct parsers.Package")
}
func TestBadYAMLInvalidKeyMappingValueInManifest(t *testing.T) {
- // read and parse manifest.yaml file located under ../tests folder
- p := NewYAMLParser()
- _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_key_mapping_value.yaml")
+ // read and parse manifest.yaml file located under ../tests folder
+ p := NewYAMLParser()
+ _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_key_mapping_value.yaml")
- assert.NotNil(t, err)
- // go-yaml/yaml prints the wrong line number for mapping values. It should be 5.
- assert.Contains(t, err.Error(), "line 4: mapping values are not allowed in this context")
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 5.
+ assert.Contains(t, err.Error(), "line 4: mapping values are not allowed in this context")
}
func TestBadYAMLMissingRootKeyInManifest(t *testing.T) {
- // read and parse manifest.yaml file located under ../tests folder
- p := NewYAMLParser()
- _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_missing_root_key.yaml")
+ // read and parse manifest.yaml file located under ../tests folder
+ p := NewYAMLParser()
+ _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_missing_root_key.yaml")
- assert.NotNil(t, err)
- assert.Contains(t, err.Error(), "line 1: field actions not found in struct parsers.YAML")
+ assert.NotNil(t, err)
+ assert.Contains(t, err.Error(), "line 1: field actions not found in struct parsers.YAML")
}
func TestBadYAMLInvalidCommentInManifest(t *testing.T) {
- // read and parse manifest.yaml file located under ../tests folder
- p := NewYAMLParser()
- _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_comment.yaml")
+ // read and parse manifest.yaml file located under ../tests folder
+ p := NewYAMLParser()
+ _, err := p.ParseManifest("../tests/dat/manifest_bad_yaml_invalid_comment.yaml")
- assert.NotNil(t, err)
- assert.Contains(t, err.Error(), "line 13: could not find expected ':'")
+ assert.NotNil(t, err)
+ assert.Contains(t, err.Error(), "line 13: could not find expected ':'")
}
// validate manifest_parser:Unmarshal() method for package in manifest YAML
// validate that manifest_parser is able to read and parse the manifest data
func TestUnmarshalForPackages(t *testing.T) {
- data := `
+ data := `
packages:
package1:
actions:
@@ -1447,62 +1445,62 @@ packages:
helloPython:
function: actions/hello.py
runtime: python`
- // set the zero value of struct YAML
- m := YAML{}
- // Unmarshal reads/parses manifest data and sets the values of YAML
- // And returns an error if parsing a manifest data fails
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- if err == nil {
- expectedResult := string(2)
- actualResult := string(len(m.Packages))
- assert.Equal(t, expectedResult, actualResult, "Expected 2 packages but got " + actualResult)
- // we have two packages
- // package name should be "helloNodejs" and "helloPython"
- for k, v := range m.Packages {
- switch k {
- case "package1":
- assert.Equal(t, "package1", k, "Expected package name package1 but got " + k)
- expectedResult = string(1)
- actualResult = string(len(v.Actions))
- assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
- // get the action payload from the map of actions which is stored in
- // YAML.Package.Actions with the type of map[string]Action
- actionName := "helloNodejs"
- if action, ok := v.Actions[actionName]; ok {
- // location/function of an action should be "actions/hello.js"
- expectedResult = "actions/hello.js"
- actualResult = action.Function
- assert.Equal(t, expectedResult, actualResult, "Expected action function " + expectedResult + " but got " + actualResult)
- // runtime of an action should be "nodejs:6"
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
- } else {
- t.Error("Action named " + actionName + " does not exist.")
- }
- case "package2":
- assert.Equal(t, "package2", k, "Expected package name package2 but got " + k)
- expectedResult = string(1)
- actualResult = string(len(v.Actions))
- assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
- // get the action payload from the map of actions which is stored in
- // YAML.Package.Actions with the type of map[string]Action
- actionName := "helloPython"
- if action, ok := v.Actions[actionName]; ok {
- // location/function of an action should be "actions/hello.js"
- expectedResult = "actions/hello.py"
- actualResult = action.Function
- assert.Equal(t, expectedResult, actualResult, "Expected action function " + expectedResult + " but got " + actualResult)
- // runtime of an action should be "python"
- expectedResult = "python"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
- } else {
- t.Error("Action named " + actionName + " does not exist.")
- }
- }
- }
- }
+ // set the zero value of struct YAML
+ m := YAML{}
+ // Unmarshal reads/parses manifest data and sets the values of YAML
+ // And returns an error if parsing a manifest data fails
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ if err == nil {
+ expectedResult := string(2)
+ actualResult := string(len(m.Packages))
+ assert.Equal(t, expectedResult, actualResult, "Expected 2 packages but got "+actualResult)
+ // we have two packages
+ // package name should be "helloNodejs" and "helloPython"
+ for k, v := range m.Packages {
+ switch k {
+ case "package1":
+ assert.Equal(t, "package1", k, "Expected package name package1 but got "+k)
+ expectedResult = string(1)
+ actualResult = string(len(v.Actions))
+ assert.Equal(t, expectedResult, actualResult, "Expected 1 but got "+actualResult)
+ // get the action payload from the map of actions which is stored in
+ // YAML.Package.Actions with the type of map[string]Action
+ actionName := "helloNodejs"
+ if action, ok := v.Actions[actionName]; ok {
+ // location/function of an action should be "actions/hello.js"
+ expectedResult = "actions/hello.js"
+ actualResult = action.Function
+ assert.Equal(t, expectedResult, actualResult, "Expected action function "+expectedResult+" but got "+actualResult)
+ // runtime of an action should be "nodejs:6"
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
+ } else {
+ t.Error("Action named " + actionName + " does not exist.")
+ }
+ case "package2":
+ assert.Equal(t, "package2", k, "Expected package name package2 but got "+k)
+ expectedResult = string(1)
+ actualResult = string(len(v.Actions))
+ assert.Equal(t, expectedResult, actualResult, "Expected 1 but got "+actualResult)
+ // get the action payload from the map of actions which is stored in
+ // YAML.Package.Actions with the type of map[string]Action
+ actionName := "helloPython"
+ if action, ok := v.Actions[actionName]; ok {
+ // location/function of an action should be "actions/hello.js"
+ expectedResult = "actions/hello.py"
+ actualResult = action.Function
+ assert.Equal(t, expectedResult, actualResult, "Expected action function "+expectedResult+" but got "+actualResult)
+ // runtime of an action should be "python"
+ expectedResult = "python"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
+ } else {
+ t.Error("Action named " + actionName + " does not exist.")
+ }
+ }
+ }
+ }
}
func TestParseYAML_trigger(t *testing.T) {
@@ -1517,7 +1515,7 @@ func TestParseYAML_trigger(t *testing.T) {
panic(err)
}
- packageName := "manifest3"
+ packageName := "manifest3"
assert.Equal(t, 2, len(manifest.Packages[packageName].Triggers), "Get trigger list failed.")
for trigger_name := range manifest.Packages[packageName].Triggers {
@@ -1544,7 +1542,7 @@ func TestParseYAML_rule(t *testing.T) {
panic(err)
}
- packageName := "manifest4"
+ packageName := "manifest4"
assert.Equal(t, 1, len(manifest.Packages[packageName].Rules), "Get trigger list failed.")
for rule_name := range manifest.Packages[packageName].Rules {
@@ -1572,7 +1570,7 @@ func TestParseYAML_feed(t *testing.T) {
panic(err)
}
- packageName := "manifest5"
+ packageName := "manifest5"
assert.Equal(t, 1, len(manifest.Packages[packageName].Feeds), "Get feed list failed.")
for feed_name := range manifest.Packages[packageName].Feeds {
@@ -1608,7 +1606,7 @@ func TestParseYAML_param(t *testing.T) {
panic(err)
}
- packageName := "validateParams"
+ packageName := "validateParams"
assert.Equal(t, 1, len(manifest.Packages[packageName].Actions), "Get action list failed.")
for action_name := range manifest.Packages[packageName].Actions {
@@ -1667,84 +1665,84 @@ func TestParseYAML_param(t *testing.T) {
}
func TestPackageName_Env_Var(t *testing.T) {
- testPackage := "test_package"
- os.Setenv("package_name", testPackage)
- testPackageSec := "test_package_second"
- os.Setenv("package_name_second", testPackageSec)
- mm := NewYAMLParser()
- manifestfile := "../tests/dat/manifest_validate_package_grammar_env_var.yaml"
- manifest, _ := mm.ParseManifest(manifestfile)
- assert.Equal(t, 4, len(manifest.Packages), "Get package list failed.")
- expectedPackages := [4]string{testPackage, testPackageSec, testPackage + "suffix", testPackage+ "-" + testPackageSec}
- for _, pkg_name := range expectedPackages {
- var pkg = manifest.Packages[pkg_name]
- assert.Equal(t, "1.0", pkg.Version, "Get the wrong package version.")
- assert.Equal(t, "Apache-2.0", pkg.License, "Get the wrong license.")
- }
+ testPackage := "test_package"
+ os.Setenv("package_name", testPackage)
+ testPackageSec := "test_package_second"
+ os.Setenv("package_name_second", testPackageSec)
+ mm := NewYAMLParser()
+ manifestfile := "../tests/dat/manifest_validate_package_grammar_env_var.yaml"
+ manifest, _ := mm.ParseManifest(manifestfile)
+ assert.Equal(t, 4, len(manifest.Packages), "Get package list failed.")
+ expectedPackages := [4]string{testPackage, testPackageSec, testPackage + "suffix", testPackage + "-" + testPackageSec}
+ for _, pkg_name := range expectedPackages {
+ var pkg = manifest.Packages[pkg_name]
+ assert.Equal(t, "1.0", pkg.Version, "Get the wrong package version.")
+ assert.Equal(t, "Apache-2.0", pkg.License, "Get the wrong license.")
+ }
}
func TestRuleName_Env_Var(t *testing.T) {
- // read and parse manifest file with env var for rule name, and rule trigger and action
- testRule := "test_rule"
- os.Setenv("rule_name", testRule)
- testTrigger := "test_trigger"
- os.Setenv("trigger_name", testTrigger)
- testAction := "test_actions"
- os.Setenv("action_name", testAction);
- mm := NewYAMLParser()
- manifestfile := "../tests/dat/manifest_data_rule_env_var.yaml"
- manifest, _ := mm.ParseManifest(manifestfile)
- rules, err := mm.ComposeRulesFromAllPackages(manifest)
- if err != nil {
- assert.Fail(t, "Failed to compose rules")
- }
- packageName := "manifest1"
-
- assert.Equal(t, 1, len(manifest.Packages[packageName].Rules), "Get rule list failed.")
- for _, rule := range rules {
- fmt.Print("ruleName: ")
- fmt.Print(rule)
- //var rule = manifest.Packages[packageName].Rules[rule_name]
- switch rule.Name {
- case testRule:
- assert.Equal(t, "test_trigger", rule.Trigger, "Get trigger name failed.")
- assert.Equal(t, packageName + "/" + testAction, rule.Action, "Get action name failed.")
- //assert.Equal(t, "true", rule.Rule, "Get rule expression failed.")
- default:
- t.Error("Get rule name failed")
- }
- }
+ // read and parse manifest file with env var for rule name, and rule trigger and action
+ testRule := "test_rule"
+ os.Setenv("rule_name", testRule)
+ testTrigger := "test_trigger"
+ os.Setenv("trigger_name", testTrigger)
+ testAction := "test_actions"
+ os.Setenv("action_name", testAction)
+ mm := NewYAMLParser()
+ manifestfile := "../tests/dat/manifest_data_rule_env_var.yaml"
+ manifest, _ := mm.ParseManifest(manifestfile)
+ rules, err := mm.ComposeRulesFromAllPackages(manifest)
+ if err != nil {
+ assert.Fail(t, "Failed to compose rules")
+ }
+ packageName := "manifest1"
+
+ assert.Equal(t, 1, len(manifest.Packages[packageName].Rules), "Get rule list failed.")
+ for _, rule := range rules {
+ fmt.Print("ruleName: ")
+ fmt.Print(rule)
+ //var rule = manifest.Packages[packageName].Rules[rule_name]
+ switch rule.Name {
+ case testRule:
+ assert.Equal(t, "test_trigger", rule.Trigger, "Get trigger name failed.")
+ assert.Equal(t, packageName+"/"+testAction, rule.Action, "Get action name failed.")
+ //assert.Equal(t, "true", rule.Rule, "Get rule expression failed.")
+ default:
+ t.Error("Get rule name failed")
+ }
+ }
}
func TestComposeActionForAnnotations(t *testing.T) {
- manifestFile := "../tests/dat/manifest_validate_action_annotations.yaml"
- mm := NewYAMLParser()
- manifest, _ := mm.ParseManifest(manifestFile)
- pkg_name := "packageActionAnnotations"
- pkg := manifest.Packages[pkg_name]
- assert.NotNil(t, pkg, "Could not find package with name " + pkg_name)
- action_name := "helloworld"
- action := pkg.Actions[action_name]
- assert.NotNil(t, action, "Could not find action with name " + action_name)
- actual_annotations := action.Annotations
- expected_annotations := map[string]interface{} {
- "action_annotation_1": "this is annotation 1",
- "action_annotation_2": "this is annotation 2",
- "action_annotation_3": "this is annotation 3",
- "action_annotation_4": "this is annotation 4",
- }
- assert.Equal(t, len(actual_annotations), len(expected_annotations), "Could not find expected number of annotations specified in manifest file")
- eq := reflect.DeepEqual(actual_annotations, expected_annotations)
- assert.True(t, eq, "Expected list of annotations does not match with actual list, expected annotations: %v actual annotations: %v", expected_annotations, actual_annotations)
-
- pkg_name = "packageActionAnnotationsWithWebAction"
- pkg = manifest.Packages[pkg_name]
- assert.NotNil(t, pkg, "Could not find package with name " + pkg_name)
- action = pkg.Actions[action_name]
- assert.NotNil(t, action, "Could not find action with name " + action_name)
- actual_annotations = action.Annotations
- expected_annotations["web-export"] = true
- assert.Equal(t, len(actual_annotations), len(expected_annotations), "Could not find expected number of annotations specified in manifest file")
- eq = reflect.DeepEqual(actual_annotations, expected_annotations)
- assert.True(t, eq, "Expected list of annotations does not match with actual list, expected annotations: %v actual annotations: %v", expected_annotations, actual_annotations)
+ manifestFile := "../tests/dat/manifest_validate_action_annotations.yaml"
+ mm := NewYAMLParser()
+ manifest, _ := mm.ParseManifest(manifestFile)
+ pkg_name := "packageActionAnnotations"
+ pkg := manifest.Packages[pkg_name]
+ assert.NotNil(t, pkg, "Could not find package with name "+pkg_name)
+ action_name := "helloworld"
+ action := pkg.Actions[action_name]
+ assert.NotNil(t, action, "Could not find action with name "+action_name)
+ actual_annotations := action.Annotations
+ expected_annotations := map[string]interface{}{
+ "action_annotation_1": "this is annotation 1",
+ "action_annotation_2": "this is annotation 2",
+ "action_annotation_3": "this is annotation 3",
+ "action_annotation_4": "this is annotation 4",
+ }
+ assert.Equal(t, len(actual_annotations), len(expected_annotations), "Could not find expected number of annotations specified in manifest file")
+ eq := reflect.DeepEqual(actual_annotations, expected_annotations)
+ assert.True(t, eq, "Expected list of annotations does not match with actual list, expected annotations: %v actual annotations: %v", expected_annotations, actual_annotations)
+
+ pkg_name = "packageActionAnnotationsWithWebAction"
+ pkg = manifest.Packages[pkg_name]
+ assert.NotNil(t, pkg, "Could not find package with name "+pkg_name)
+ action = pkg.Actions[action_name]
+ assert.NotNil(t, action, "Could not find action with name "+action_name)
+ actual_annotations = action.Annotations
+ expected_annotations["web-export"] = true
+ assert.Equal(t, len(actual_annotations), len(expected_annotations), "Could not find expected number of annotations specified in manifest file")
+ eq = reflect.DeepEqual(actual_annotations, expected_annotations)
+ assert.True(t, eq, "Expected list of annotations does not match with actual list, expected annotations: %v actual annotations: %v", expected_annotations, actual_annotations)
}
diff --git a/parsers/parameters.go b/parsers/parameters.go
index 01d5fff..bd05201 100644
--- a/parsers/parameters.go
+++ b/parsers/parameters.go
@@ -17,12 +17,12 @@
package parsers
import (
- "fmt"
- "reflect"
"encoding/json"
+ "fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
"github.com/apache/incubator-openwhisk-wskdeploy/wskenv"
+ "reflect"
)
// TODO(): Support other valid Package Manifest types
@@ -30,11 +30,11 @@ import (
// TODO(): Support JSON schema validation for type: json
// TODO(): Support OpenAPI schema validation
const (
- STRING string = "string"
- INTEGER string = "integer"
- FLOAT string = "float"
- BOOLEAN string = "boolean"
- JSON string = "json"
+ STRING string = "string"
+ INTEGER string = "integer"
+ FLOAT string = "float"
+ BOOLEAN string = "boolean"
+ JSON string = "json"
)
var validParameterNameMap = map[string]string{
@@ -50,7 +50,7 @@ var validParameterNameMap = map[string]string{
"int64": INTEGER,
"float32": FLOAT,
"float64": FLOAT,
- JSON: JSON,
+ JSON: JSON,
"map": JSON,
}
@@ -88,18 +88,17 @@ func getTypeDefaultValue(typeName string) interface{} {
return nil
}
-
/*
- ResolveParamTypeFromValue Resolves the Parameter's data type from its actual value.
+ ResolveParamTypeFromValue Resolves the Parameter's data type from its actual value.
- Inputs:
- - paramName: name of the parameter for error reporting
- - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
- - value: the parameter value to resolve
+ Inputs:
+ - paramName: name of the parameter for error reporting
+ - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
+ - value: the parameter value to resolve
- Returns:
- - (string) parameter type name as a string
- */
+ Returns:
+ - (string) parameter type name as a string
+*/
func ResolveParamTypeFromValue(paramName string, value interface{}, filePath string) (string, error) {
// Note: 'string' is the default type if not specified and not resolvable.
var paramType string = "string"
@@ -121,24 +120,23 @@ func ResolveParamTypeFromValue(paramName string, value interface{}, filePath str
return paramType, err
}
-
/*
- resolveSingleLineParameter assures that a Parameter's Type is correctly identified and set from its Value.
+ resolveSingleLineParameter assures that a Parameter's Type is correctly identified and set from its Value.
- Additionally, this function:
+ Additionally, this function:
- - detects if the parameter value contains the name of a valid OpenWhisk parameter types. if so, the
- - param.Type is set to detected OpenWhisk parameter type.
- - param.Value is set to the zero (default) value for that OpenWhisk parameter type.
+ - detects if the parameter value contains the name of a valid OpenWhisk parameter types. if so, the
+ - param.Type is set to detected OpenWhisk parameter type.
+ - param.Value is set to the zero (default) value for that OpenWhisk parameter type.
- Inputs:
- - filePath: the path, including name, of the YAML file which contained the parameter for error reporting
- - paramName: name of the parameter for error reporting
- - param: pointer to Parameter structure being resolved
+ Inputs:
+ - filePath: the path, including name, of the YAML file which contained the parameter for error reporting
+ - paramName: name of the parameter for error reporting
+ - param: pointer to Parameter structure being resolved
- Returns:
- - (interface{}) the parameter's resolved value
- */
+ Returns:
+ - (interface{}) the parameter's resolved value
+*/
func resolveSingleLineParameter(filePath string, paramName string, param *Parameter) (interface{}, error) {
var errorParser error
@@ -162,28 +160,28 @@ func resolveSingleLineParameter(filePath string, paramName string, param *Parame
} else {
// TODO() - move string to i18n
return param.Value, wskderrors.NewYAMLParserErr(filePath,
- "Parameter [" + paramName + "] is not single-line format.")
+ "Parameter ["+paramName+"] is not single-line format.")
}
return param.Value, errorParser
}
/*
- resolveMultiLineParameter assures that the values for Parameter Type and Value are properly set and are valid.
+ resolveMultiLineParameter assures that the values for Parameter Type and Value are properly set and are valid.
- Additionally, this function:
- - uses param.Default as param.Value if param.Value is not provided
- - uses the actual param.Value data type for param.type if param.Type is not provided
+ Additionally, this function:
+ - uses param.Default as param.Value if param.Value is not provided
+ - uses the actual param.Value data type for param.type if param.Type is not provided
- Inputs:
- - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
- - paramName: name of the parameter for error reporting
- - param: pointer to Parameter structure being resolved
+ Inputs:
+ - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
+ - paramName: name of the parameter for error reporting
+ - param: pointer to Parameter structure being resolved
- Returns:
- - (interface{}) the parameter's resolved value
+ Returns:
+ - (interface{}) the parameter's resolved value
- */
+*/
func resolveMultiLineParameter(filePath string, paramName string, param *Parameter) (interface{}, error) {
var errorParser error
@@ -203,7 +201,7 @@ func resolveMultiLineParameter(filePath string, paramName string, param *Paramet
if !isValidParameterType(param.Type) {
// TODO() - move string to i18n
return param.Value, wskderrors.NewYAMLParserErr(filePath,
- "Parameter [" + paramName + "] has an invalid Type. [" + param.Type + "]")
+ "Parameter ["+paramName+"] has an invalid Type. ["+param.Type+"]")
}
} else {
// if we do not have a value for the Parameter Type, use the Parameter Value's Type
@@ -217,30 +215,28 @@ func resolveMultiLineParameter(filePath string, paramName string, param *Paramet
} else {
// TODO() - move string to i18n
return param.Value, wskderrors.NewYAMLParserErr(filePath,
- "Parameter [" + paramName + "] is not multiline format.")
+ "Parameter ["+paramName+"] is not multiline format.")
}
-
return param.Value, errorParser
}
-
/*
- resolveJSONParameter assure JSON data is converted to a map[string]{interface*} type.
+ resolveJSONParameter assure JSON data is converted to a map[string]{interface*} type.
- This function handles the forms JSON data appears in:
- 1) a string containing JSON, which needs to be parsed into map[string]interface{}
- 2) is a map of JSON (but not a map[string]interface{}
+ This function handles the forms JSON data appears in:
+ 1) a string containing JSON, which needs to be parsed into map[string]interface{}
+ 2) is a map of JSON (but not a map[string]interface{}
- Inputs:
- - paramName: name of the parameter for error reporting
- - filePath: the path, including name, of the YAML file which contained the parameter for error reporting
- - param: pointer to Parameter structure being resolved
- - value: the current actual value of the parameter being resolved
+ Inputs:
+ - paramName: name of the parameter for error reporting
+ - filePath: the path, including name, of the YAML file which contained the parameter for error reporting
+ - param: pointer to Parameter structure being resolved
+ - value: the current actual value of the parameter being resolved
- Returns:
- - (interface{}) the parameter's resolved value
- */
+ Returns:
+ - (interface{}) the parameter's resolved value
+*/
func resolveJSONParameter(filePath string, paramName string, param *Parameter, value interface{}) (interface{}, error) {
var errorParser error
@@ -259,46 +255,45 @@ func resolveJSONParameter(filePath string, paramName string, param *Parameter, v
// Case 2: value contains a map of JSON
// We must make sure the map type is map[string]interface{}; otherwise we cannot
// marshall it later on to serialize in the body of an HTTP request.
- if( param.Value != nil && reflect.TypeOf(param.Value).Kind() == reflect.Map ) {
+ if param.Value != nil && reflect.TypeOf(param.Value).Kind() == reflect.Map {
if _, ok := param.Value.(map[interface{}]interface{}); ok {
- var temp map[string]interface{} =
- utils.ConvertInterfaceMap(param.Value.(map[interface{}]interface{}))
+ var temp map[string]interface{} = utils.ConvertInterfaceMap(param.Value.(map[interface{}]interface{}))
//fmt.Printf("EXIT: Parameter [%s] type=[%v] value=[%v]\n", paramName, param.Type, temp)
return temp, errorParser
}
- } else{
+ } else {
errorParser = wskderrors.NewParameterTypeMismatchError(filePath, paramName, JSON, param.Type)
}
} else {
// TODO() - move string to i18n
- errorParser = wskderrors.NewYAMLParserErr(filePath, "Parameter [" + paramName + "] is not JSON format.")
+ errorParser = wskderrors.NewYAMLParserErr(filePath, "Parameter ["+paramName+"] is not JSON format.")
}
return param.Value, errorParser
}
/*
- ResolveParameter assures that the Parameter structure's values are correctly filled out for
- further processing. This includes special processing for
-
- - single-line format parameters
- - deriving missing param.Type from param.Value
- - resolving case where param.Value contains a valid Parameter type name
- - multi-line format parameters:
- - assures that param.Value is set while taking into account param.Default
- - validating param.Type
-
- Note: parameter values may set later (overridden) by an (optional) Deployment file
-
- Inputs:
- - paramName: name of the parameter for error reporting
- - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
- - param: pointer to Parameter structure being resolved
-
- Returns:
- - (interface{}) the parameter's resolved value
- */
+ ResolveParameter assures that the Parameter structure's values are correctly filled out for
+ further processing. This includes special processing for
+
+ - single-line format parameters
+ - deriving missing param.Type from param.Value
+ - resolving case where param.Value contains a valid Parameter type name
+ - multi-line format parameters:
+ - assures that param.Value is set while taking into account param.Default
+ - validating param.Type
+
+ Note: parameter values may set later (overridden) by an (optional) Deployment file
+
+ Inputs:
+ - paramName: name of the parameter for error reporting
+ - filepath: the path, including name, of the YAML file which contained the parameter for error reporting
+ - param: pointer to Parameter structure being resolved
+
+ Returns:
+ - (interface{}) the parameter's resolved value
+*/
func ResolveParameter(paramName string, param *Parameter, filePath string) (interface{}, error) {
var errorParser error
@@ -321,7 +316,7 @@ func ResolveParameter(paramName string, param *Parameter, filePath string) (inte
// See if we have any Environment Variable replacement within the parameter's value
// Make sure the parameter's value is a valid, non-empty string
- if ( param.Value != nil && param.Type == "string") {
+ if param.Value != nil && param.Type == "string" {
// perform $ notation replacement on string if any exist
value = wskenv.GetEnvVar(param.Value)
}
diff --git a/parsers/yamlparser.go b/parsers/yamlparser.go
index 6bcee66..b0b35fe 100644
--- a/parsers/yamlparser.go
+++ b/parsers/yamlparser.go
@@ -24,44 +24,44 @@ import (
// YAML schema key names
// DO NOT translate
-const(
- YAML_KEY_ACTION = "action"
- YAML_KEY_ANNOTATION = "annotoation"
- YAML_KEY_API = "api"
- YAML_KEY_FEED = "feed"
- YAML_KEY_NAMESPACE = "namespace"
- YAML_KEY_PACKAGES = "packages"
- YAML_KEY_PROJECT = "project"
- YAML_KEY_RULE = "rule"
- YAML_KEY_SEQUENCE = "sequence"
- YAML_KEY_TRIGGER = "trigger"
- YAML_KEY_APPLICATION = "application" // deprecated
- YAML_KEY_PACKAGE = "package" // deprecated
- YAML_KEY_SOURCE = "source" // deprecated
+const (
+ YAML_KEY_ACTION = "action"
+ YAML_KEY_ANNOTATION = "annotoation"
+ YAML_KEY_API = "api"
+ YAML_KEY_FEED = "feed"
+ YAML_KEY_NAMESPACE = "namespace"
+ YAML_KEY_PACKAGES = "packages"
+ YAML_KEY_PROJECT = "project"
+ YAML_KEY_RULE = "rule"
+ YAML_KEY_SEQUENCE = "sequence"
+ YAML_KEY_TRIGGER = "trigger"
+ YAML_KEY_APPLICATION = "application" // deprecated
+ YAML_KEY_PACKAGE = "package" // deprecated
+ YAML_KEY_SOURCE = "source" // deprecated
)
// YAML schema key values
-const(
- YAML_VALUE_BRANCH_MASTER = "master"
+const (
+ YAML_VALUE_BRANCH_MASTER = "master"
)
// default values
-const(
- DEFAULT_PACKAGE_LICENSE = "unlicensed"
- DEFAULT_PACKAGE_VERSION = "0.0.1"
+const (
+ DEFAULT_PACKAGE_LICENSE = "unlicensed"
+ DEFAULT_PACKAGE_VERSION = "0.0.1"
)
// Known Limit values
-const(
+const (
// supported
- LIMIT_VALUE_TIMEOUT = "timeout"
- LIMIT_VALUE_MEMORY_SIZE = "memorySize"
- LIMIT_VALUE_LOG_SIZE = "logSize"
+ LIMIT_VALUE_TIMEOUT = "timeout"
+ LIMIT_VALUE_MEMORY_SIZE = "memorySize"
+ LIMIT_VALUE_LOG_SIZE = "logSize"
// unsupported
- LIMIT_VALUE_CONCURRENT_ACTIVATIONS = "concurrentActivations"
- LIMIT_VALUE_USER_INVOCATION_RATE = "userInvocationRate"
- LIMIT_VALUE_CODE_SIZE = "codeSize"
- LIMIT_VALUE_PARAMETER_SIZE = "parameterSize"
+ LIMIT_VALUE_CONCURRENT_ACTIVATIONS = "concurrentActivations"
+ LIMIT_VALUE_USER_INVOCATION_RATE = "userInvocationRate"
+ LIMIT_VALUE_CODE_SIZE = "codeSize"
+ LIMIT_VALUE_PARAMETER_SIZE = "parameterSize"
)
var LIMITS_SUPPORTED = [](string){
diff --git a/tests/apps/owbp-cloudant-trigger/owbp-cloudant-trigger_test.go b/tests/apps/owbp-cloudant-trigger/owbp-cloudant-trigger_test.go
index 557ac85..b88062b 100644
--- a/tests/apps/owbp-cloudant-trigger/owbp-cloudant-trigger_test.go
+++ b/tests/apps/owbp-cloudant-trigger/owbp-cloudant-trigger_test.go
@@ -20,17 +20,17 @@
package tests
import (
- "testing"
+ "fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
- "fmt"
+ "testing"
)
var projectPath = "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/apps/owbp-cloudant-trigger/runtimes/"
func TestCloudantTriggerNode(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "node/manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "node/manifest.yaml"
deploymentPath := ""
os.Setenv("CLOUDANT_DATABASE", "testdb")
wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
@@ -48,7 +48,7 @@ func TestCloudantTriggerNode(t *testing.T) {
}
func TestCloudantTriggerPhp(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "php/manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "php/manifest.yaml"
deploymentPath := ""
os.Setenv("CLOUDANT_DATABASE", "testdb")
wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
@@ -66,7 +66,7 @@ func TestCloudantTriggerPhp(t *testing.T) {
}
func TestCloudantTriggerPython(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "python/manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "python/manifest.yaml"
deploymentPath := ""
os.Setenv("CLOUDANT_DATABASE", "testdb")
wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
@@ -84,7 +84,7 @@ func TestCloudantTriggerPython(t *testing.T) {
}
func TestCloudantTriggerSwift(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "swift/manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "swift/manifest.yaml"
deploymentPath := ""
os.Setenv("CLOUDANT_DATABASE", "testdb")
wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
@@ -100,4 +100,3 @@ func TestCloudantTriggerSwift(t *testing.T) {
assert.Equal(t, nil, err, "Failed to undeploy the manifest file.")
}
}
-
diff --git a/tests/src/integration/alarmtrigger/alarmtrigger_test.go b/tests/src/integration/alarmtrigger/alarmtrigger_test.go
index ff4ba29..6bf080d 100644
--- a/tests/src/integration/alarmtrigger/alarmtrigger_test.go
+++ b/tests/src/integration/alarmtrigger/alarmtrigger_test.go
@@ -20,11 +20,11 @@
package tests
import (
+ "fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
"testing"
- "fmt"
)
/* *
@@ -32,18 +32,18 @@ import (
* integration test.
*/
func TestAlarmTrigger(t *testing.T) {
- wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
- err := common.ValidateWskprops(wskprops)
- if err != nil {
- fmt.Println(err.Error())
- fmt.Println("Wsk properties are not properly configured, so tests are skipped.")
- } else {
- wskdeploy := common.NewWskdeploy()
- _, err := wskdeploy.DeployWithCredentials(manifestPath, deploymentPath, wskprops)
- assert.Equal(t, nil, err, "Failed to deploy the manifest file.")
- _, err = wskdeploy.UndeployWithCredentials(manifestPath, deploymentPath, wskprops)
- assert.Equal(t, nil, err, "Failed to undeploy the manifest file.")
- }
+ wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
+ err := common.ValidateWskprops(wskprops)
+ if err != nil {
+ fmt.Println(err.Error())
+ fmt.Println("Wsk properties are not properly configured, so tests are skipped.")
+ } else {
+ wskdeploy := common.NewWskdeploy()
+ _, err := wskdeploy.DeployWithCredentials(manifestPath, deploymentPath, wskprops)
+ assert.Equal(t, nil, err, "Failed to deploy the manifest file.")
+ _, err = wskdeploy.UndeployWithCredentials(manifestPath, deploymentPath, wskprops)
+ assert.Equal(t, nil, err, "Failed to undeploy the manifest file.")
+ }
}
var (
diff --git a/tests/src/integration/apigateway/apigateway_test.go b/tests/src/integration/apigateway/apigateway_test.go
index 7723b15..6bc3355 100644
--- a/tests/src/integration/apigateway/apigateway_test.go
+++ b/tests/src/integration/apigateway/apigateway_test.go
@@ -20,10 +20,10 @@
package tests
import (
- "testing"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
+ "testing"
)
// TODO: write the integration against openwhisk
@@ -35,5 +35,3 @@ func TestTriggerRule(t *testing.T) {
_, err = wskdeploy.UndeployManifestPathOnly(manifestPath)
assert.Equal(t, nil, err, "Failed to undeploy based on the manifest file.")
}
-
-
diff --git a/tests/src/integration/cloudant/cloudant_test.go b/tests/src/integration/cloudant/cloudant_test.go
index a9e0452..b8eeea1 100644
--- a/tests/src/integration/cloudant/cloudant_test.go
+++ b/tests/src/integration/cloudant/cloudant_test.go
@@ -20,17 +20,17 @@
package tests
import (
- "testing"
+ "fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
- "fmt"
+ "testing"
)
func TestCloudant(t *testing.T) {
os.Setenv("CLOUDANT_DATABASE", "testdb")
wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
- err := common.ValidateWskprops(wskprops)
+ err := common.ValidateWskprops(wskprops)
if err != nil {
fmt.Println(err.Error())
fmt.Println("Wsk properties are not properly configured, so tests are skipped.")
@@ -44,7 +44,6 @@ func TestCloudant(t *testing.T) {
}
var (
- manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/cloudant/manifest.yaml"
+ manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/cloudant/manifest.yaml"
deploymentPath = ""
)
-
diff --git a/tests/src/integration/common/wskdeploy.go b/tests/src/integration/common/wskdeploy.go
index 7551c27..eff1920 100644
--- a/tests/src/integration/common/wskdeploy.go
+++ b/tests/src/integration/common/wskdeploy.go
@@ -22,16 +22,16 @@ import (
"errors"
"fmt"
"github.com/apache/incubator-openwhisk-client-go/whisk"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
"os"
"os/exec"
- "strings"
- "path/filepath"
"path"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
+ "path/filepath"
+ "strings"
)
const (
@@ -205,7 +205,7 @@ func (wskdeploy *Wskdeploy) GetDeploymentObjects(manifestPath string, deployment
//invoke ConstructDeploymentPlan to create the in memory objects for deployment
err = deployer.ConstructDeploymentPlan()
if err != nil {
- return nil,err
+ return nil, err
}
//return the deployment objects
return deployer.Deployment, nil
diff --git a/tests/src/integration/dependency/dependency_test.go b/tests/src/integration/dependency/dependency_test.go
index e5ca7cc..eda7b1d 100644
--- a/tests/src/integration/dependency/dependency_test.go
+++ b/tests/src/integration/dependency/dependency_test.go
@@ -20,25 +20,24 @@
package tests
import (
- "github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
- "github.com/stretchr/testify/assert"
- "os"
- "testing"
+ "github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
+ "github.com/stretchr/testify/assert"
+ "os"
+ "testing"
)
-
var wskprops = common.GetWskprops()
// TODO: write the integration against openwhisk
func TestDependency(t *testing.T) {
- wskdeploy := common.NewWskdeploy()
- _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
- assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
- _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
+ wskdeploy := common.NewWskdeploy()
+ _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
+ _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
}
var (
- manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/dependency/manifest.yaml"
- deploymentPath = ""
+ manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/dependency/manifest.yaml"
+ deploymentPath = ""
)
diff --git a/tests/src/integration/flagstests/flags_test.go b/tests/src/integration/flagstests/flags_test.go
index 675504e..3c492f0 100644
--- a/tests/src/integration/flagstests/flags_test.go
+++ b/tests/src/integration/flagstests/flags_test.go
@@ -34,8 +34,8 @@ func TestSupportProjectPath(t *testing.T) {
projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests"
_, err := wskdeploy.DeployProjectPathOnly(projectPath)
assert.Equal(t, nil, err, "Failed to deploy based on the projectpath")
- _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the projectpath")
+ _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the projectpath")
}
// support only projectpath with trailing slash
@@ -44,8 +44,8 @@ func TestSupportProjectPathTrailingSlash(t *testing.T) {
projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests" + "/"
_, err := wskdeploy.DeployProjectPathOnly(projectPath)
assert.Equal(t, nil, err, "Failed to deploy based on the projectpath")
- _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the projectpath")
+ _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the projectpath")
}
// only a yaml manifest
@@ -54,8 +54,8 @@ func TestSupportManifestYamlPath(t *testing.T) {
manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yaml"
_, err := wskdeploy.DeployManifestPathOnly(manifestPath)
assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath")
- _, err = wskdeploy.UndeployManifestPathOnly(manifestPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath")
+ _, err = wskdeploy.UndeployManifestPathOnly(manifestPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath")
}
// only a yml manifest
@@ -64,8 +64,8 @@ func TestSupportManifestYmlPath(t *testing.T) {
manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yml"
_, err := wskdeploy.DeployManifestPathOnly(manifestPath)
assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath")
- _, err = wskdeploy.UndeployManifestPathOnly(manifestPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath")
+ _, err = wskdeploy.UndeployManifestPathOnly(manifestPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath")
}
// manifest yaml and deployment yaml
@@ -73,10 +73,10 @@ func TestSupportManifestYamlDeployment(t *testing.T) {
wskdeploy := common.NewWskdeploy()
manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/deployment.yml"
- _, err := wskdeploy.Deploy(manifestPath,deploymentPath)
+ _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath and deploymentpath.")
- _, err = wskdeploy.Undeploy(manifestPath,deploymentPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath and deploymentpath.")
+ _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath and deploymentpath.")
}
// manifest yml and deployment yaml
@@ -84,8 +84,8 @@ func TestSupportManifestYmlDeployment(t *testing.T) {
wskdeploy := common.NewWskdeploy()
manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yml"
deploymentPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/deployment.yml"
- _, err := wskdeploy.Deploy(manifestPath,deploymentPath)
+ _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath and deploymentpath.")
- _, err = wskdeploy.Undeploy(manifestPath,deploymentPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath and deploymentpath.")
+ _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifestpath and deploymentpath.")
}
diff --git a/tests/src/integration/managed-deployment/managed-deployment_test.go b/tests/src/integration/managed-deployment/managed-deployment_test.go
index 10e8aa8..c3bf5d6 100644
--- a/tests/src/integration/managed-deployment/managed-deployment_test.go
+++ b/tests/src/integration/managed-deployment/managed-deployment_test.go
@@ -59,4 +59,3 @@ func TestManagedDeployment(t *testing.T) {
_, err = wskdeploy.ManagedDeployment(manifestPath, deploymentPath)
assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
}
-
diff --git a/tests/src/integration/runtimetests/runtimes_test.go b/tests/src/integration/runtimetests/runtimes_test.go
index 340c992..c488eb0 100644
--- a/tests/src/integration/runtimetests/runtimes_test.go
+++ b/tests/src/integration/runtimetests/runtimes_test.go
@@ -28,10 +28,9 @@ import (
func TestExplicitRuntimes(t *testing.T) {
wskdeploy := common.NewWskdeploy()
- projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/runtimetests"
- _, err := wskdeploy.DeployProjectPathOnly(projectPath)
+ projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/runtimetests"
+ _, err := wskdeploy.DeployProjectPathOnly(projectPath)
assert.Equal(t, nil, err, "Failed to deploy based on the project path")
- _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the project path")
+ _, err = wskdeploy.UndeployProjectPathOnly(projectPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the project path")
}
-
diff --git a/tests/src/integration/triggerrule/triggerrule_test.go b/tests/src/integration/triggerrule/triggerrule_test.go
index b93b8e9..791dabc 100644
--- a/tests/src/integration/triggerrule/triggerrule_test.go
+++ b/tests/src/integration/triggerrule/triggerrule_test.go
@@ -20,10 +20,10 @@
package tests
import (
- "testing"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
"os"
+ "testing"
)
var wskprops = common.GetWskprops()
@@ -38,7 +38,6 @@ func TestTriggerRule(t *testing.T) {
}
var (
- manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/triggerrule/manifest.yml"
+ manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/triggerrule/manifest.yml"
deploymentPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/triggerrule/deployment.yml"
)
-
diff --git a/tests/src/integration/validate-action-annotations/validate-action-annotations_test.go b/tests/src/integration/validate-action-annotations/validate-action-annotations_test.go
index f48aa29..78f86fb 100644
--- a/tests/src/integration/validate-action-annotations/validate-action-annotations_test.go
+++ b/tests/src/integration/validate-action-annotations/validate-action-annotations_test.go
@@ -29,7 +29,7 @@ import (
var path = "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/validate-action-annotations/"
func TestActionAnnotations(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + path + "manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + path + "manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + path + "deployment.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -39,10 +39,9 @@ func TestActionAnnotations(t *testing.T) {
}
func TestInvalidActionAnnotations(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + path + "manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + path + "manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + path + "deployment-with-invalid-annotations.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
assert.NotNil(t, err, "Failed to validate invalid annotations in deployment file")
}
-
diff --git a/tests/src/integration/validate-application-and-project/validate-application-and-project_test.go b/tests/src/integration/validate-application-and-project/validate-application-and-project_test.go
index a110ef2..f49e1c4 100644
--- a/tests/src/integration/validate-application-and-project/validate-application-and-project_test.go
+++ b/tests/src/integration/validate-application-and-project/validate-application-and-project_test.go
@@ -29,7 +29,7 @@ import (
var path = "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/validate-application-and-project/"
func TestApplicationInDeployment(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + path + "manifest-with-application.yaml"
+ manifestPath := os.Getenv("GOPATH") + path + "manifest-with-application.yaml"
deploymentPath := os.Getenv("GOPATH") + path + "deployment-with-application.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -39,7 +39,7 @@ func TestApplicationInDeployment(t *testing.T) {
}
func TestProjectInDeployment(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + path + "manifest-with-project.yaml"
+ manifestPath := os.Getenv("GOPATH") + path + "manifest-with-project.yaml"
deploymentPath := os.Getenv("GOPATH") + path + "deployment-with-project.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -47,4 +47,3 @@ func TestProjectInDeployment(t *testing.T) {
_, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
}
-
diff --git a/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go b/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go
index 8e0d159..715af01 100644
--- a/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go
+++ b/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go
@@ -30,7 +30,7 @@ var PATH = "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integ
func TestBindingInputsAnnotations(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + PATH + "manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + PATH + "manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + PATH + "deployment.yaml"
wskdeploy := common.NewWskdeploy()
@@ -146,11 +146,9 @@ func TestBindingInputsAnnotations(t *testing.T) {
}
}
-
// testing deploy and undeploy
_, err = wskdeploy.Deploy(manifestPath, deploymentPath)
assert.NoError(t, err, "Failed to deploy based on the manifest and deployment files.")
_, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
assert.NoError(t, err, "Failed to undeploy based on the manifest and deployment files.")
}
-
diff --git a/tests/src/integration/validate-manifest-deployment-file-extensions/validate-file-extensions_test.go b/tests/src/integration/validate-manifest-deployment-file-extensions/validate-file-extensions_test.go
index 77c3e6e..0a1940c 100644
--- a/tests/src/integration/validate-manifest-deployment-file-extensions/validate-file-extensions_test.go
+++ b/tests/src/integration/validate-manifest-deployment-file-extensions/validate-file-extensions_test.go
@@ -29,7 +29,7 @@ import (
var projectPath = "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/validate-manifest-deployment-file-extensions/"
func TestYAMLExtension(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "deployment.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -39,7 +39,7 @@ func TestYAMLExtension(t *testing.T) {
}
func TestYMLExtension(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "manifest.yml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "manifest.yml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "deployment.yml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -49,7 +49,7 @@ func TestYMLExtension(t *testing.T) {
}
func TestNonStandardFileNames(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "not-standard-manifest.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "not-standard-manifest.yaml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "not-standard-deployment.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -59,7 +59,7 @@ func TestNonStandardFileNames(t *testing.T) {
}
func TestRandomFileNames(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "random-name-1.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "random-name-1.yaml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "random-name-2.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -69,7 +69,7 @@ func TestRandomFileNames(t *testing.T) {
}
func TestYAMLManifestWithYMLDeployment(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "yaml-manifest-with-yml-deployment.yaml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "yaml-manifest-with-yml-deployment.yaml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "yml-deployment-with-yaml-manifest.yml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -79,7 +79,7 @@ func TestYAMLManifestWithYMLDeployment(t *testing.T) {
}
func TestYMLManifestWithYAMLDeployment(t *testing.T) {
- manifestPath := os.Getenv("GOPATH") + projectPath + "yml-manifest-with-yaml-deployment.yml"
+ manifestPath := os.Getenv("GOPATH") + projectPath + "yml-manifest-with-yaml-deployment.yml"
deploymentPath := os.Getenv("GOPATH") + projectPath + "yaml-deployment-with-yml-manifest.yaml"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
@@ -87,4 +87,3 @@ func TestYMLManifestWithYAMLDeployment(t *testing.T) {
_, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files with .yml manifest and .yaml deployment file.")
}
-
diff --git a/tests/src/integration/validateSequencesCreation/validateSequencesCreation_test.go b/tests/src/integration/validateSequencesCreation/validateSequencesCreation_test.go
index 0bc6679..bb3e7a2 100644
--- a/tests/src/integration/validateSequencesCreation/validateSequencesCreation_test.go
+++ b/tests/src/integration/validateSequencesCreation/validateSequencesCreation_test.go
@@ -20,12 +20,12 @@
package tests
import (
+ "fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
- "os"
"io/ioutil"
+ "os"
"strconv"
- "fmt"
"strings"
"testing"
)
@@ -43,13 +43,13 @@ func composeDeployFiles(count int) (manifestStr string, deploymentStr string) {
TestSequencesCreation:
actions:
`
- sequenceStr :=` sequences:
+ sequenceStr := ` sequences:
validate-sequence:
actions: `
for i := 1; i < count+1; i++ {
- manifestStr = manifestStr + " func"+strconv.Itoa(i)+":"+
-`
+ manifestStr = manifestStr + " func" + strconv.Itoa(i) + ":" +
+ `
function: actions/function.js
runtime: nodejs:6
inputs:
@@ -58,44 +58,44 @@ func composeDeployFiles(count int) (manifestStr string, deploymentStr string) {
outputs:
visited: string
`
- sequenceStr = sequenceStr + "func"+strconv.Itoa(i)+","
- deploymentStr = deploymentStr + " func"+strconv.Itoa(i)+":"+
-`
+ sequenceStr = sequenceStr + "func" + strconv.Itoa(i) + ","
+ deploymentStr = deploymentStr + " func" + strconv.Itoa(i) + ":" +
+ `
inputs:
- functionID: `+strconv.Itoa(i)+
-`
+ functionID: ` + strconv.Itoa(i) +
+ `
visited:
`
- }
- manifestStr = manifestStr + strings.TrimRight(sequenceStr,",")
+ }
+ manifestStr = manifestStr + strings.TrimRight(sequenceStr, ",")
return
}
func _createTmpfile(data string, filename string) (f *os.File, err error) {
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, filename)
- if err != nil {
- return nil, err
- }
- _, err = tmpfile.Write([]byte(data))
- if err != nil {
- return tmpfile, err
- }
- return tmpfile, nil
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, filename)
+ if err != nil {
+ return nil, err
+ }
+ _, err = tmpfile.Write([]byte(data))
+ if err != nil {
+ return tmpfile, err
+ }
+ return tmpfile, nil
}
func TestValidateSequenceCreation(t *testing.T) {
count := 10
wskdeploy := common.NewWskdeploy()
for i := 1; i < count+1; i++ {
- maniData,deplyData := composeDeployFiles(i+1)
+ maniData, deplyData := composeDeployFiles(i + 1)
tmpManifile, err := _createTmpfile(maniData, "sequence_test_mani_")
tmpDeplyfile, err := _createTmpfile(deplyData, "sequence_test_deply_")
if err != nil {
assert.Fail(t, "Failed to create temp file")
}
- fmt.Printf("Deploying sequence %d\n:",i)
+ fmt.Printf("Deploying sequence %d\n:", i)
_, err = wskdeploy.Deploy(tmpManifile.Name(), tmpDeplyfile.Name())
assert.Equal(t, nil, err, "Failed to deploy sequence.")
_, err = wskdeploy.Undeploy(tmpManifile.Name(), tmpDeplyfile.Name())
@@ -107,4 +107,3 @@ func TestValidateSequenceCreation(t *testing.T) {
os.Remove(tmpDeplyfile.Name())
}
}
-
diff --git a/tests/src/integration/webaction/webaction_test.go b/tests/src/integration/webaction/webaction_test.go
index 5ec81ca..43aba14 100644
--- a/tests/src/integration/webaction/webaction_test.go
+++ b/tests/src/integration/webaction/webaction_test.go
@@ -26,7 +26,6 @@ import (
"testing"
)
-
var wskprops = common.GetWskprops()
// TODO: write the integration against openwhisk
diff --git a/tests/src/integration/zipaction/zipaction_test.go b/tests/src/integration/zipaction/zipaction_test.go
index e39ddd6..bf9243b 100644
--- a/tests/src/integration/zipaction/zipaction_test.go
+++ b/tests/src/integration/zipaction/zipaction_test.go
@@ -20,21 +20,21 @@
package tests
import (
- "github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
- "github.com/stretchr/testify/assert"
- "os"
- "testing"
+ "github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
+ "github.com/stretchr/testify/assert"
+ "os"
+ "testing"
)
func TestZipAction(t *testing.T) {
- wskdeploy := common.NewWskdeploy()
- _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
- assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
- _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
- assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
+ wskdeploy := common.NewWskdeploy()
+ _, err := wskdeploy.Deploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
+ _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+ assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
}
var (
- manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/zipaction/manifest.yml"
- deploymentPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/zipaction/deployment.yml"
+ manifestPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/zipaction/manifest.yml"
+ deploymentPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/zipaction/deployment.yml"
)
diff --git a/utils/conversion.go b/utils/conversion.go
index 411cf9c..23dae1c 100644
--- a/utils/conversion.go
+++ b/utils/conversion.go
@@ -48,7 +48,7 @@ func convertMapValue(value interface{}) interface{} {
}
}
-func PrintTypeInfo(name string, value interface{}) {
- info := fmt.Sprintf("Name=[%s], Value=[%v], Type=[%T]\n",name,value,value)
+func PrintTypeInfo(name string, value interface{}) {
+ info := fmt.Sprintf("Name=[%s], Value=[%v], Type=[%T]\n", name, value, value)
fmt.Print(info)
}
diff --git a/utils/dependencies.go b/utils/dependencies.go
index 5ece712..92c19d9 100644
--- a/utils/dependencies.go
+++ b/utils/dependencies.go
@@ -24,10 +24,10 @@ import (
)
type DependencyRecord struct {
- ProjectPath string //root of the source codes of dependent projects, e.g. src_project_path/Packages
- Packagename string //name of the package
- Location string //location
- Version string //version
+ ProjectPath string //root of the source codes of dependent projects, e.g. src_project_path/Packages
+ Packagename string //name of the package
+ Location string //location
+ Version string //version
Parameters whisk.KeyValueArr
Annotations whisk.KeyValueArr
IsBinding bool
@@ -36,12 +36,12 @@ type DependencyRecord struct {
}
func NewDependencyRecord(projectPath string,
- packagename string,
- location string,
- version string,
- parameters whisk.KeyValueArr,
- annotations whisk.KeyValueArr,
- isBinding bool) DependencyRecord {
+ packagename string,
+ location string,
+ version string,
+ parameters whisk.KeyValueArr,
+ annotations whisk.KeyValueArr,
+ isBinding bool) DependencyRecord {
var record DependencyRecord
record.ProjectPath = projectPath
record.Packagename = packagename
@@ -53,9 +53,9 @@ func NewDependencyRecord(projectPath string,
//split url to BaseUrl and SubFolder
if !record.IsBinding {
paths := strings.Split(location, "/")
- record.BaseRepo = strings.Join([]string{paths[0],paths[1],paths[2],paths[3],paths[4]},"/")
- if len(paths)>5 {
- record.SubFolder = strings.TrimPrefix(record.Location,record.BaseRepo)
+ record.BaseRepo = strings.Join([]string{paths[0], paths[1], paths[2], paths[3], paths[4]}, "/")
+ if len(paths) > 5 {
+ record.SubFolder = strings.TrimPrefix(record.Location, record.BaseRepo)
} else {
record.SubFolder = ""
}
diff --git a/utils/fileoperations.go b/utils/fileoperations.go
index 3d01ee4..7838641 100644
--- a/utils/fileoperations.go
+++ b/utils/fileoperations.go
@@ -44,15 +44,15 @@ func FileExists(file string) bool {
func IsDirectory(filePath string) bool {
f, err := os.Open(filePath)
if err != nil {
- return false
- } else {
- defer f.Close()
- }
+ return false
+ } else {
+ defer f.Close()
+ }
fi, err := f.Stat()
- if err != nil {
- return false
- }
+ if err != nil {
+ return false
+ }
switch mode := fi.Mode(); {
case mode.IsDir():
@@ -106,24 +106,24 @@ func WriteProps(path string, props map[string]string) error {
for k, v := range props {
_, err := file.WriteString(k)
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
_, err = file.WriteString("=")
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
_, err = file.WriteString(v)
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
_, err = file.WriteString("\n")
- if err != nil {
- return err
- }
+ if err != nil {
+ return err
+ }
}
return nil
}
diff --git a/utils/fileoperations_test.go b/utils/fileoperations_test.go
index a816a9c..7bb59b0 100644
--- a/utils/fileoperations_test.go
+++ b/utils/fileoperations_test.go
@@ -20,125 +20,125 @@
package utils
import (
- "testing"
- "github.com/stretchr/testify/assert"
- "os"
- "io/ioutil"
- "bufio"
- "fmt"
+ "bufio"
+ "fmt"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
+ "os"
+ "testing"
)
func CreateTmpfile(filename string) (f *os.File, err error) {
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, filename)
- if err != nil {
- return nil, err
- }
- return tmpfile, nil
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, filename)
+ if err != nil {
+ return nil, err
+ }
+ return tmpfile, nil
}
func CreateTmpDir(dir string) error {
- return os.Mkdir(dir, 0777)
+ return os.Mkdir(dir, 0777)
}
func CreateFile(lines []string, path string) error {
- file, err := os.Create(path)
- if err != nil {
- return err
- }
- defer file.Close()
-
- w := bufio.NewWriter(file)
- for _, line := range lines {
- fmt.Fprintln(w, line)
- }
- return w.Flush()
+ file, err := os.Create(path)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+
+ w := bufio.NewWriter(file)
+ for _, line := range lines {
+ fmt.Fprintln(w, line)
+ }
+ return w.Flush()
}
func TestFileExists(t *testing.T) {
- testfile := "testFile"
- tmpFile, err := CreateTmpfile(testfile)
- assert.Nil(t, err, "Failed to create the temporary file.")
-
- // The file exists.
- fileName := tmpFile.Name()
- result := FileExists(fileName)
- assert.True(t, result)
-
- // After the file is removed, the file does not exist.
- tmpFile.Close()
- os.Remove(tmpFile.Name())
- result = FileExists(fileName)
- assert.False(t, result)
+ testfile := "testFile"
+ tmpFile, err := CreateTmpfile(testfile)
+ assert.Nil(t, err, "Failed to create the temporary file.")
+
+ // The file exists.
+ fileName := tmpFile.Name()
+ result := FileExists(fileName)
+ assert.True(t, result)
+
+ // After the file is removed, the file does not exist.
+ tmpFile.Close()
+ os.Remove(tmpFile.Name())
+ result = FileExists(fileName)
+ assert.False(t, result)
}
func TestIsDirectory(t *testing.T) {
- testDir := "testFile"
- err := CreateTmpDir(testDir)
- assert.Nil(t, err, "Failed to create the temporary file.")
-
- // The directory exists.
- result := IsDirectory(testDir)
- assert.True(t, result)
-
- // After the file is removed, the file does not exist.
- os.Remove(testDir)
- result = IsDirectory(testDir)
- assert.False(t, result)
-
- // If this function is tested against a valid file, we will get false.
- testfile := "testFile"
- tmpFile, err := CreateTmpfile(testfile)
- assert.Nil(t, err, "Failed to create the temporary file.")
- fileName := tmpFile.Name()
- result = IsDirectory(fileName)
- assert.False(t, result)
- tmpFile.Close()
- os.Remove(tmpFile.Name())
-
- // If this function is tested against an invalid path, we will get false.
- result = IsDirectory("NonExistent")
- assert.False(t, result)
+ testDir := "testFile"
+ err := CreateTmpDir(testDir)
+ assert.Nil(t, err, "Failed to create the temporary file.")
+
+ // The directory exists.
+ result := IsDirectory(testDir)
+ assert.True(t, result)
+
+ // After the file is removed, the file does not exist.
+ os.Remove(testDir)
+ result = IsDirectory(testDir)
+ assert.False(t, result)
+
+ // If this function is tested against a valid file, we will get false.
+ testfile := "testFile"
+ tmpFile, err := CreateTmpfile(testfile)
+ assert.Nil(t, err, "Failed to create the temporary file.")
+ fileName := tmpFile.Name()
+ result = IsDirectory(fileName)
+ assert.False(t, result)
+ tmpFile.Close()
+ os.Remove(tmpFile.Name())
+
+ // If this function is tested against an invalid path, we will get false.
+ result = IsDirectory("NonExistent")
+ assert.False(t, result)
}
func TestReadProps(t *testing.T) {
- testfile := "testWskPropsRead"
- testKey := "testKey"
- testValue := "testValue"
- testKeySec := "testKeySec"
- testValueSec := "testValueSec"
- lines := []string{ testKey + "=" + testValue, testKeySec + "=" + testValueSec }
- CreateFile(lines, testfile)
- props, err := ReadProps(testfile)
- assert.Nil(t, err, "Failed to read the test prop file.")
- assert.Equal(t, testValue, props[testKey])
- assert.Equal(t, testValueSec, props[testKeySec])
- err = os.Remove(testfile)
- assert.Nil(t, err, "Failed to delete the test prop file.")
-
- // Failed to read wskprops file if it does not exist.
- props, err = ReadProps(testfile)
- assert.NotNil(t, err)
- assert.Equal(t, 0, len(props))
+ testfile := "testWskPropsRead"
+ testKey := "testKey"
+ testValue := "testValue"
+ testKeySec := "testKeySec"
+ testValueSec := "testValueSec"
+ lines := []string{testKey + "=" + testValue, testKeySec + "=" + testValueSec}
+ CreateFile(lines, testfile)
+ props, err := ReadProps(testfile)
+ assert.Nil(t, err, "Failed to read the test prop file.")
+ assert.Equal(t, testValue, props[testKey])
+ assert.Equal(t, testValueSec, props[testKeySec])
+ err = os.Remove(testfile)
+ assert.Nil(t, err, "Failed to delete the test prop file.")
+
+ // Failed to read wskprops file if it does not exist.
+ props, err = ReadProps(testfile)
+ assert.NotNil(t, err)
+ assert.Equal(t, 0, len(props))
}
func TestWriteProps(t *testing.T) {
- testfile := "testWskPropsWrite"
- testKey := "testKeyWrite"
- testValue := "testValueWrite"
- testKeySec := "testKeyWriteSec"
- testValueSec := "testValueWriteSec"
- props := map[string]string{
- testKey: testValue,
- testKeySec: testValueSec,
- }
- err := WriteProps(testfile, props)
- assert.Nil(t, err, "Failed to write the test prop file.")
-
- propsResult, error := ReadProps(testfile)
- assert.Nil(t, error, "Failed to read the test prop file.")
- assert.Equal(t, testValue, propsResult[testKey])
- assert.Equal(t, testValueSec, propsResult[testKeySec])
- err = os.Remove(testfile)
- assert.Nil(t, err, "Failed to delete the test prop file.")
+ testfile := "testWskPropsWrite"
+ testKey := "testKeyWrite"
+ testValue := "testValueWrite"
+ testKeySec := "testKeyWriteSec"
+ testValueSec := "testValueWriteSec"
+ props := map[string]string{
+ testKey: testValue,
+ testKeySec: testValueSec,
+ }
+ err := WriteProps(testfile, props)
+ assert.Nil(t, err, "Failed to write the test prop file.")
+
+ propsResult, error := ReadProps(testfile)
+ assert.Nil(t, error, "Failed to read the test prop file.")
+ assert.Equal(t, testValue, propsResult[testKey])
+ assert.Equal(t, testValueSec, propsResult[testKeySec])
+ err = os.Remove(testfile)
+ assert.Nil(t, err, "Failed to delete the test prop file.")
}
diff --git a/utils/flags.go b/utils/flags.go
index 6cbc0d9..1f61cbb 100644
--- a/utils/flags.go
+++ b/utils/flags.go
@@ -37,10 +37,10 @@ type WskDeployFlags struct {
ManifestPath string
UseDefaults bool
UseInteractive bool
- Strict bool // strict flag to support user defined runtime version.
- Key string
- Cert string
- Managed bool // OpenWhisk Managed Deployments
+ Strict bool // strict flag to support user defined runtime version.
+ Key string
+ Cert string
+ Managed bool // OpenWhisk Managed Deployments
}
func (flags *WskDeployFlags) Format() string {
@@ -53,7 +53,7 @@ func (flags *WskDeployFlags) Format() string {
//var t interface{}
var result string
- for i := 0; i < flagValues.NumField(); i++ {
+ for i := 0; i < flagValues.NumField(); i++ {
name = flagNames.Field(i).Name
value = flagValues.Field(i)
// NOTE: if you need to see the Type, add this line to output
diff --git a/utils/managedannotations.go b/utils/managedannotations.go
index f550193..fa0781e 100644
--- a/utils/managedannotations.go
+++ b/utils/managedannotations.go
@@ -21,8 +21,8 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
- "os"
"github.com/apache/incubator-openwhisk-client-go/whisk"
+ "os"
)
/*
@@ -32,15 +32,14 @@ import (
* __OW__PROJECT__NAME: MyProject
* __OW__PROJECT_HASH: SHA1("OpenWhisk " + <size_of_manifest_file> + "\0" + <contents_of_manifest_file>)
* __OW__FILE: Absolute path of manifest file on file system
-*/
+ */
const (
- MANAGED = "managed"
- OPENWHISK = "OpenWhisk"
- NULL = "golang\000"
+ MANAGED = "managed"
+ OPENWHISK = "OpenWhisk"
+ NULL = "golang\000"
OW_PROJECT_NAME = "__OW_PROJECT_NAME"
OW_PROJECT_HASH = "__OW_PROJECT_HASH"
-
)
type ManagedAnnotation struct {
@@ -108,6 +107,6 @@ func GenerateManagedAnnotation(projectName string, filePath string) (whisk.KeyVa
}
var a interface{}
err = json.Unmarshal(ma, &a)
- managedAnnotation = whisk.KeyValue{Key:MANAGED, Value:a.(map[string]interface{})}
+ managedAnnotation = whisk.KeyValue{Key: MANAGED, Value: a.(map[string]interface{})}
return managedAnnotation, nil
}
diff --git a/utils/misc_test.go b/utils/misc_test.go
index 9430823..d4841e2 100644
--- a/utils/misc_test.go
+++ b/utils/misc_test.go
@@ -20,9 +20,9 @@
package utils
import (
- "testing"
"github.com/stretchr/testify/assert"
"os"
+ "testing"
)
var contentReader = new(ContentReader)
@@ -44,14 +44,14 @@ func TestURLReader_ReadUrl(t *testing.T) {
}
func TestDependencies(t *testing.T) {
- var record = NewDependencyRecord("projectPath","packageName","http://github.com/user/repo","master",nil,nil,false)
- assert.Equal(t, "projectPath", record.ProjectPath,"ProjectPath is wrong")
+ var record = NewDependencyRecord("projectPath", "packageName", "http://github.com/user/repo", "master", nil, nil, false)
+ assert.Equal(t, "projectPath", record.ProjectPath, "ProjectPath is wrong")
assert.Equal(t, "http://github.com/user/repo", record.Location, "URL is wrong")
assert.Equal(t, "http://github.com/user/repo", record.BaseRepo, "BaseRepo is wrong")
assert.Equal(t, "", record.SubFolder, "SubFolder is wrong")
- record = NewDependencyRecord("projectPath","packageName","http://github.com/user/repo/subfolder1/subfolder2","master",nil,nil,false)
- assert.Equal(t, "projectPath", record.ProjectPath,"ProjectPath is wrong")
+ record = NewDependencyRecord("projectPath", "packageName", "http://github.com/user/repo/subfolder1/subfolder2", "master", nil, nil, false)
+ assert.Equal(t, "projectPath", record.ProjectPath, "ProjectPath is wrong")
assert.Equal(t, "http://github.com/user/repo/subfolder1/subfolder2", record.Location, "URL is wrong")
assert.Equal(t, "http://github.com/user/repo", record.BaseRepo, "BaseRepo is wrong")
assert.Equal(t, "/subfolder1/subfolder2", record.SubFolder, "SubFolder is wrong")
@@ -63,7 +63,7 @@ func TestParseOpenWhisk(t *testing.T) {
assert.Equal(t, nil, err, "parse openwhisk info error happened.")
converted := ConvertToMap(openwhisk)
assert.Equal(t, 2, len(converted["nodejs"]), "not expected length")
- assert.Equal(t, 1, len(converted["php"]), "not expected length")
+ assert.Equal(t, 1, len(converted["php"]), "not expected length")
assert.Equal(t, 1, len(converted["java"]), "not expected length")
assert.Equal(t, 3, len(converted["python"]), "not expected length")
assert.Equal(t, 1, len(converted["swift"]), "not expected length")
diff --git a/utils/qualifiedname.go b/utils/qualifiedname.go
index 9a25bd5..e16c122 100644
--- a/utils/qualifiedname.go
+++ b/utils/qualifiedname.go
@@ -72,7 +72,7 @@ func ParseQualifiedName(name string, defaultNamespace string) (QualifiedName, er
}
qualifiedName.EntityName = name
- if (defaultNamespace == "") {
+ if defaultNamespace == "" {
defaultNamespace = "_"
}
qualifiedName.Namespace = defaultNamespace
diff --git a/utils/runtimes.go b/utils/runtimes.go
index ed22fa0..dc2721c 100644
--- a/utils/runtimes.go
+++ b/utils/runtimes.go
@@ -69,7 +69,6 @@ var FileExtensionRuntimeKindMap map[string]string
var SupportedRunTimes map[string][]string
var DefaultRunTimes map[string]string
-
// We could get the openwhisk info from bluemix through running the command
// `curl -k https://openwhisk.ng.bluemix.net`
// hard coding it here in case of network unavailable or failure.
@@ -166,10 +165,10 @@ func FileExtensionRuntimes(op OpenWhiskInfo) (ext map[string]string) {
return
}
-func CheckRuntimeConsistencyWithFileExtension (ext string, runtime string) bool {
+func CheckRuntimeConsistencyWithFileExtension(ext string, runtime string) bool {
rt := FileExtensionRuntimeKindMap[ext]
for _, v := range SupportedRunTimes[rt] {
- if (runtime == v) {
+ if runtime == v {
return true
}
}
diff --git a/utils/validation.go b/utils/validation.go
index 2f926af..b59c5d2 100644
--- a/utils/validation.go
+++ b/utils/validation.go
@@ -19,11 +19,11 @@
package utils
import (
- "strings"
"encoding/json"
"github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "strings"
)
var LocalLicenseRecords = map[string][]string{
diff --git a/wskderrors/wskdeployerror.go b/wskderrors/wskdeployerror.go
index c7d5e83..fa375f8 100644
--- a/wskderrors/wskdeployerror.go
+++ b/wskderrors/wskdeployerror.go
@@ -19,55 +19,55 @@ package wskderrors
import (
"fmt"
+ "io/ioutil"
+ "net/http"
+ "path/filepath"
"runtime"
"strings"
- "path/filepath"
- "net/http"
- "io/ioutil"
)
const (
// Error message compositional strings
- STR_UNKNOWN_VALUE = "Unknown value"
- STR_COMMAND = "Command"
- STR_ERROR_CODE = "Error code"
- STR_FILE = "File"
- STR_PARAMETER = "Parameter"
- STR_TYPE = "Type"
- STR_EXPECTED = "Expected"
- STR_ACTUAL = "Actual"
- STR_NEWLINE = "\n"
- STR_ACTION = "Action"
- STR_RUNTIME = "Runtime"
+ STR_UNKNOWN_VALUE = "Unknown value"
+ STR_COMMAND = "Command"
+ STR_ERROR_CODE = "Error code"
+ STR_FILE = "File"
+ STR_PARAMETER = "Parameter"
+ STR_TYPE = "Type"
+ STR_EXPECTED = "Expected"
+ STR_ACTUAL = "Actual"
+ STR_NEWLINE = "\n"
+ STR_ACTION = "Action"
+ STR_RUNTIME = "Runtime"
STR_SUPPORTED_RUNTIMES = "Supported Runtimes"
- STR_HTTP_STATUS = "HTTP Response Status"
- STR_HTTP_BODY = "HTTP Response Body"
+ STR_HTTP_STATUS = "HTTP Response Status"
+ STR_HTTP_BODY = "HTTP Response Body"
// Formatting
STR_INDENT_1 = "==>"
// Error Types
- ERROR_COMMAND_FAILED = "ERROR_COMMAND_FAILED"
- ERROR_WHISK_CLIENT_ERROR = "ERROR_WHISK_CLIENT_ERROR"
- ERROR_WHISK_CLIENT_INVALID_CONFIG = "ERROR_WHISK_CLIENT_INVALID_CONFIG"
- ERROR_FILE_READ_ERROR = "ERROR_FILE_READ_ERROR"
- ERROR_MANIFEST_FILE_NOT_FOUND = "ERROR_MANIFEST_FILE_NOT_FOUND"
- ERROR_YAML_FILE_FORMAT_ERROR = "ERROR_YAML_FILE_FORMAT_ERROR"
- ERROR_YAML_PARSER_ERROR = "ERROR_YAML_PARSER_ERROR"
+ ERROR_COMMAND_FAILED = "ERROR_COMMAND_FAILED"
+ ERROR_WHISK_CLIENT_ERROR = "ERROR_WHISK_CLIENT_ERROR"
+ ERROR_WHISK_CLIENT_INVALID_CONFIG = "ERROR_WHISK_CLIENT_INVALID_CONFIG"
+ ERROR_FILE_READ_ERROR = "ERROR_FILE_READ_ERROR"
+ ERROR_MANIFEST_FILE_NOT_FOUND = "ERROR_MANIFEST_FILE_NOT_FOUND"
+ ERROR_YAML_FILE_FORMAT_ERROR = "ERROR_YAML_FILE_FORMAT_ERROR"
+ ERROR_YAML_PARSER_ERROR = "ERROR_YAML_PARSER_ERROR"
ERROR_YAML_PARAMETER_TYPE_MISMATCH = "ERROR_YAML_PARAMETER_TYPE_MISMATCH"
- ERROR_YAML_INVALID_PARAMETER_TYPE = "ERROR_YAML_INVALID_PARAMETER_TYPE"
- ERROR_YAML_INVALID_RUNTIME = "ERROR_YAML_INVALID_RUNTIME"
+ ERROR_YAML_INVALID_PARAMETER_TYPE = "ERROR_YAML_INVALID_PARAMETER_TYPE"
+ ERROR_YAML_INVALID_RUNTIME = "ERROR_YAML_INVALID_RUNTIME"
)
/*
* BaseError
*/
type WskDeployBaseErr struct {
- ErrorType string
- FileName string
- LineNum int
- Message string
- MessageFormat string
+ ErrorType string
+ FileName string
+ LineNum int
+ Message string
+ MessageFormat string
}
func NewWskDeployBaseError(typ string, fn string, ln int, msg string) *WskDeployBaseErr {
@@ -100,17 +100,17 @@ func (e *WskDeployBaseErr) SetMessageFormat(fmt string) {
e.MessageFormat = fmt
}
-func (e *WskDeployBaseErr) GetMessage()(string) {
+func (e *WskDeployBaseErr) GetMessage() string {
return e.Message
}
-func (e *WskDeployBaseErr) GetMessageFormat()(string) {
+func (e *WskDeployBaseErr) GetMessageFormat() string {
return e.MessageFormat
}
func (e *WskDeployBaseErr) SetMessage(message interface{}) {
- if message != nil{
+ if message != nil {
switch message.(type) {
case string:
e.Message = message.(string)
@@ -121,16 +121,16 @@ func (e *WskDeployBaseErr) SetMessage(message interface{}) {
}
}
-func (e *WskDeployBaseErr) AppendDetail(detail string){
+func (e *WskDeployBaseErr) AppendDetail(detail string) {
e.appendDetail(detail)
}
-func (e *WskDeployBaseErr) appendDetail(detail string){
+func (e *WskDeployBaseErr) appendDetail(detail string) {
fmt := fmt.Sprintf("\n%s %s", STR_INDENT_1, detail)
e.Message = e.Message + fmt
}
-func (e *WskDeployBaseErr) appendErrorDetails(err error){
+func (e *WskDeployBaseErr) appendErrorDetails(err error) {
if err != nil {
errorMsg := err.Error()
var detailMsg string
@@ -202,8 +202,7 @@ type WhiskClientInvalidConfigError struct {
}
func NewWhiskClientInvalidConfigError(errorMessage string) *WhiskClientInvalidConfigError {
- var err = &WhiskClientInvalidConfigError{
- }
+ var err = &WhiskClientInvalidConfigError{}
err.SetErrorType(ERROR_WHISK_CLIENT_INVALID_CONFIG)
err.SetCallerByStackFrameSkip(2)
err.SetMessage(errorMessage)
@@ -229,7 +228,7 @@ func (e *FileError) SetErrorFileName(fname string) {
}
func (e *FileError) Error() string {
- return fmt.Sprintf("%s [%d]: [%s]: " + STR_FILE + ": [%s]: %s\n",
+ return fmt.Sprintf("%s [%d]: [%s]: "+STR_FILE+": [%s]: %s\n",
e.FileName,
e.LineNum,
e.ErrorType,
@@ -246,8 +245,7 @@ type FileReadError struct {
}
func NewFileReadError(fpath string, errMessage interface{}) *FileReadError {
- var err = &FileReadError{
- }
+ var err = &FileReadError{}
err.SetErrorType(ERROR_FILE_READ_ERROR)
err.SetCallerByStackFrameSkip(2)
err.SetErrorFilePath(fpath)
@@ -255,7 +253,6 @@ func NewFileReadError(fpath string, errMessage interface{}) *FileReadError {
return err
}
-
/*
* ManifestFileNotFoundError
*/
@@ -264,8 +261,7 @@ type ErrorManifestFileNotFound struct {
}
func NewErrorManifestFileNotFound(fpath string, errMessage interface{}) *ErrorManifestFileNotFound {
- var err = &ErrorManifestFileNotFound{
- }
+ var err = &ErrorManifestFileNotFound{}
err.SetErrorType(ERROR_MANIFEST_FILE_NOT_FOUND)
err.SetCallerByStackFrameSkip(2)
err.SetErrorFilePath(fpath)
@@ -281,8 +277,7 @@ type YAMLFileFormatError struct {
}
func NewYAMLFileFormatError(fpath string, errorMessage interface{}) *YAMLFileFormatError {
- var err = &YAMLFileFormatError{
- }
+ var err = &YAMLFileFormatError{}
err.SetErrorType(ERROR_YAML_FILE_FORMAT_ERROR)
err.SetCallerByStackFrameSkip(2)
err.SetErrorFilePath(fpath)
@@ -303,7 +298,7 @@ type ParameterTypeMismatchError struct {
func NewParameterTypeMismatchError(fpath string, param string, expectedType string, actualType string) *ParameterTypeMismatchError {
var err = &ParameterTypeMismatchError{
ExpectedType: expectedType,
- ActualType: actualType,
+ ActualType: actualType,
}
err.SetErrorType(ERROR_YAML_PARAMETER_TYPE_MISMATCH)
@@ -324,8 +319,8 @@ func NewParameterTypeMismatchError(fpath string, param string, expectedType stri
*/
type InvalidParameterTypeError struct {
FileError
- Parameter string
- ActualType string
+ Parameter string
+ ActualType string
}
func NewInvalidParameterTypeError(fpath string, param string, actualType string) *ParameterTypeMismatchError {
@@ -348,29 +343,26 @@ func NewInvalidParameterTypeError(fpath string, param string, actualType string)
*/
type YAMLParserError struct {
FileError
- lines []string
- msgs []string
+ lines []string
+ msgs []string
}
func NewYAMLParserErr(fpath string, msg interface{}) *YAMLParserError {
- var err = &YAMLParserError{
-
- }
+ var err = &YAMLParserError{}
err.SetErrorType(ERROR_YAML_PARSER_ERROR)
err.SetErrorFilePath(fpath)
err.SetCallerByStackFrameSkip(2)
- err.SetMessage(msg)
+ err.SetMessage(msg)
return err
}
-
/*
* InvalidRuntime
*/
type InvalidRuntimeError struct {
FileError
- Runtime string
- SupportedRuntimes []string
+ Runtime string
+ SupportedRuntimes []string
}
func NewInvalidRuntimeError(errMessage string, fpath string, action string, runtime string, supportedRuntimes []string) *InvalidRuntimeError {
@@ -389,7 +381,7 @@ func NewInvalidRuntimeError(errMessage string, fpath string, action string, runt
return err
}
-func IsCustomError( err error ) bool {
+func IsCustomError(err error) bool {
switch err.(type) {
diff --git a/wskderrors/wskdeployerror_test.go b/wskderrors/wskdeployerror_test.go
index c4ba837..57b8d74 100644
--- a/wskderrors/wskdeployerror_test.go
+++ b/wskderrors/wskdeployerror_test.go
@@ -21,12 +21,12 @@ package wskderrors
import (
"errors"
- "testing"
- "github.com/stretchr/testify/assert"
- "strings"
"fmt"
- "runtime"
+ "github.com/stretchr/testify/assert"
"path/filepath"
+ "runtime"
+ "strings"
+ "testing"
)
/*
@@ -38,7 +38,7 @@ func TestCustomErrorOutputFormat(t *testing.T) {
packageName := filepath.Base(fn)
const TEST_DEFAULT_ERROR_MESSAGE = "Some bad error"
const TEST_COMMAND string = "test"
- const TEST_ERROR_CODE = 400 // Bad request
+ const TEST_ERROR_CODE = 400 // Bad request
const TEST_EXISTANT_MANIFEST_FILE = "tests/dat/manifest_validate_multiline_params.yaml"
const TEST_NONEXISTANT_MANIFEST_FILE = "tests/dat/missing_manifest.yaml"
const TEST_INVALID_YAML_MANIFEST_FILE = "tests/dat/manifest_bad_yaml_invalid_comment.yaml"
@@ -88,11 +88,11 @@ func TestCustomErrorOutputFormat(t *testing.T) {
assert.Equal(t, expectedResult, actualResult)
/*
- * FileReadError
- */
+ * FileReadError
+ */
err4 := NewFileReadError(TEST_NONEXISTANT_MANIFEST_FILE, TEST_DEFAULT_ERROR_MESSAGE)
actualResult = strings.TrimSpace(err4.Error())
- expectedResult = fmt.Sprintf("%s [%d]: [%s]: " + STR_FILE + ": [%s]: %s",
+ expectedResult = fmt.Sprintf("%s [%d]: [%s]: "+STR_FILE+": [%s]: %s",
packageName,
err4.LineNum,
ERROR_FILE_READ_ERROR,
@@ -101,8 +101,8 @@ func TestCustomErrorOutputFormat(t *testing.T) {
assert.Equal(t, expectedResult, actualResult)
/*
- * ManifestFileNotFoundError
- */
+ * ManifestFileNotFoundError
+ */
err5 := NewErrorManifestFileNotFound(TEST_NONEXISTANT_MANIFEST_FILE, TEST_DEFAULT_ERROR_MESSAGE)
actualResult = strings.TrimSpace(err5.Error())
expectedResult = fmt.Sprintf("%s [%d]: [%s]: %s: [%s]: %s",
@@ -115,8 +115,8 @@ func TestCustomErrorOutputFormat(t *testing.T) {
assert.Equal(t, expectedResult, actualResult)
/*
- * YAMLFileFormatError
- */
+ * YAMLFileFormatError
+ */
err6 := NewYAMLFileFormatError(TEST_INVALID_YAML_MANIFEST_FILE, TEST_DEFAULT_ERROR_MESSAGE)
actualResult = strings.TrimSpace(err6.Error())
expectedResult = fmt.Sprintf("%s [%d]: [%s]: %s: [%s]: %s",
@@ -159,7 +159,7 @@ func TestCustomErrorOutputFormat(t *testing.T) {
msg9 := fmt.Sprintf("%s [%s]: %s [%s]",
STR_PARAMETER, TEST_PARAM_NAME,
STR_TYPE, TEST_PARAM_TYPE_FOO)
- expectedResult = fmt.Sprintf("%s [%d]: [%s]: " + STR_FILE + ": [%s]: %s",
+ expectedResult = fmt.Sprintf("%s [%d]: [%s]: "+STR_FILE+": [%s]: %s",
packageName,
err9.LineNum,
ERROR_YAML_INVALID_PARAMETER_TYPE,
diff --git a/wskenv/environment.go b/wskenv/environment.go
index 50d935b..3a6cfec 100644
--- a/wskenv/environment.go
+++ b/wskenv/environment.go
@@ -18,10 +18,10 @@
package wskenv
import (
- "strings"
+ "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
"os"
"reflect"
- "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+ "strings"
)
// Test if a string
diff --git a/wskenv/environment_test.go b/wskenv/environment_test.go
index 80dda7f..7961a3a 100644
--- a/wskenv/environment_test.go
+++ b/wskenv/environment_test.go
@@ -18,29 +18,29 @@
package wskenv
import (
- "testing"
- "os"
"fmt"
"github.com/stretchr/testify/assert"
+ "os"
+ "testing"
)
// The dollar sign test cases.
func TestGetEnvVar(t *testing.T) {
-os.Setenv("NoDollar", "NO dollar")
-os.Setenv("WithDollar", "oh, dollars!")
-os.Setenv("5000", "5000")
-fmt.Println(GetEnvVar("NoDollar"))
-fmt.Println(GetEnvVar("$WithDollar"))
-fmt.Println(GetEnvVar("$5000"))
-assert.Equal(t, "NoDollar", GetEnvVar("NoDollar"), "NoDollar should be no change.")
-assert.Equal(t, "oh, dollars!", GetEnvVar("$WithDollar"), "dollar sign should be handled.")
-assert.Equal(t, "5000", GetEnvVar("5000"), "Should be no difference between integer and string.")
-assert.Equal(t, "", GetEnvVar("$WithDollarAgain"), "if not found in environemnt, return empty string.")
-assert.Equal(t, "oh, dollars!.ccc.aaa", GetEnvVar("${WithDollar}.ccc.aaa"), "String concatenation fail")
-assert.Equal(t, "ddd.NO dollar.aaa", GetEnvVar("ddd.${NoDollar}.aaa"), "String concatenation fail")
-assert.Equal(t, "oh, dollars!.NO dollar.aaa", GetEnvVar("${WithDollar}.${NoDollar}.aaa"), "String concatenation fail")
-assert.Equal(t, "ddd.ccc.oh, dollars!", GetEnvVar("ddd.ccc.${WithDollar}"), "String concatenation fail")
-assert.Equal(t, "", GetEnvVar("$WithDollarAgain.ccc.aaa"), "String concatenation fail")
-assert.Equal(t, "ddd..aaa", GetEnvVar("ddd.${WithDollarAgain}.aaa"), "String concatenation fail")
-assert.Equal(t, "oh, dollars!NO dollar.NO dollar", GetEnvVar("${WithDollar}${NoDollar}.${NoDollar}"), "String concatenation fail")
+ os.Setenv("NoDollar", "NO dollar")
+ os.Setenv("WithDollar", "oh, dollars!")
+ os.Setenv("5000", "5000")
+ fmt.Println(GetEnvVar("NoDollar"))
+ fmt.Println(GetEnvVar("$WithDollar"))
+ fmt.Println(GetEnvVar("$5000"))
+ assert.Equal(t, "NoDollar", GetEnvVar("NoDollar"), "NoDollar should be no change.")
+ assert.Equal(t, "oh, dollars!", GetEnvVar("$WithDollar"), "dollar sign should be handled.")
+ assert.Equal(t, "5000", GetEnvVar("5000"), "Should be no difference between integer and string.")
+ assert.Equal(t, "", GetEnvVar("$WithDollarAgain"), "if not found in environemnt, return empty string.")
+ assert.Equal(t, "oh, dollars!.ccc.aaa", GetEnvVar("${WithDollar}.ccc.aaa"), "String concatenation fail")
+ assert.Equal(t, "ddd.NO dollar.aaa", GetEnvVar("ddd.${NoDollar}.aaa"), "String concatenation fail")
+ assert.Equal(t, "oh, dollars!.NO dollar.aaa", GetEnvVar("${WithDollar}.${NoDollar}.aaa"), "String concatenation fail")
+ assert.Equal(t, "ddd.ccc.oh, dollars!", GetEnvVar("ddd.ccc.${WithDollar}"), "String concatenation fail")
+ assert.Equal(t, "", GetEnvVar("$WithDollarAgain.ccc.aaa"), "String concatenation fail")
+ assert.Equal(t, "ddd..aaa", GetEnvVar("ddd.${WithDollarAgain}.aaa"), "String concatenation fail")
+ assert.Equal(t, "oh, dollars!NO dollar.NO dollar", GetEnvVar("${WithDollar}${NoDollar}.${NoDollar}"), "String concatenation fail")
}
diff --git a/wski18n/detection.go b/wski18n/detection.go
index b442cc4..c3866dd 100644
--- a/wski18n/detection.go
+++ b/wski18n/detection.go
@@ -20,24 +20,24 @@ package wski18n
import "github.com/cloudfoundry/jibber_jabber"
type Detector interface {
- DetectLocale() string
- DetectLanguage() string
+ DetectLocale() string
+ DetectLanguage() string
}
type JibberJabberDetector struct{}
func (d *JibberJabberDetector) DetectLocale() string {
- userLocale, err := jibber_jabber.DetectIETF()
- if err != nil {
- userLocale = ""
- }
- return userLocale
+ userLocale, err := jibber_jabber.DetectIETF()
+ if err != nil {
+ userLocale = ""
+ }
+ return userLocale
}
func (d *JibberJabberDetector) DetectLanguage() string {
- lang, err := jibber_jabber.DetectLanguage()
- if err != nil {
- lang = ""
- }
- return lang
+ lang, err := jibber_jabber.DetectLanguage()
+ if err != nil {
+ lang = ""
+ }
+ return lang
}
diff --git a/wski18n/i18n.go b/wski18n/i18n.go
index 38c4172..e851d23 100644
--- a/wski18n/i18n.go
+++ b/wski18n/i18n.go
@@ -18,138 +18,138 @@
package wski18n
import (
- "path/filepath"
- "strings"
+ "path/filepath"
+ "strings"
- goi18n "github.com/nicksnyder/go-i18n/i18n"
+ goi18n "github.com/nicksnyder/go-i18n/i18n"
)
const (
- DEFAULT_LOCALE = "en_US"
+ DEFAULT_LOCALE = "en_US"
)
var SUPPORTED_LOCALES = []string{
- "de_DE",
- "en_US",
- "es_ES",
- "fr_FR",
- "it_IT",
- "ja_JA",
- "ko_KR",
- "pt_BR",
- "zh_Hans",
- "zh_Hant",
+ "de_DE",
+ "en_US",
+ "es_ES",
+ "fr_FR",
+ "it_IT",
+ "ja_JA",
+ "ko_KR",
+ "pt_BR",
+ "zh_Hans",
+ "zh_Hant",
}
var resourcePath = filepath.Join("wski18n", "resources")
// TODO() when are these used?
func GetResourcePath() string {
- return resourcePath
+ return resourcePath
}
// TODO() when are these used?
func SetResourcePath(path string) {
- resourcePath = path
+ resourcePath = path
}
var T goi18n.TranslateFunc
var curLocale string
func init() {
- curLocale = Init(new(JibberJabberDetector))
+ curLocale = Init(new(JibberJabberDetector))
}
// TODO() when are these used?
func CurLocale() string {
- return curLocale
+ return curLocale
}
// TODO() when are these used?
func Locale(detector Detector) string {
- // Use default locale until strings are translated
- /*sysLocale := normalize(detector.DetectLocale())
- if isSupported(sysLocale) {
- return sysLocale
- }
+ // Use default locale until strings are translated
+ /*sysLocale := normalize(detector.DetectLocale())
+ if isSupported(sysLocale) {
+ return sysLocale
+ }
- locale := defaultLocaleForLang(detector.DetectLanguage())
- if locale != "" {
- return locale
- }*/
+ locale := defaultLocaleForLang(detector.DetectLanguage())
+ if locale != "" {
+ return locale
+ }*/
- return DEFAULT_LOCALE
+ return DEFAULT_LOCALE
}
func Init(detector Detector) string {
- l := Locale(detector)
- InitWithLocale(l)
- return l
+ l := Locale(detector)
+ InitWithLocale(l)
+ return l
}
func InitWithLocale(locale string) {
- err := loadFromAsset(locale)
- if err != nil {
- panic(err)
- }
- T = goi18n.MustTfunc(locale)
+ err := loadFromAsset(locale)
+ if err != nil {
+ panic(err)
+ }
+ T = goi18n.MustTfunc(locale)
}
func loadFromAsset(locale string) (err error) {
- assetName := locale + ".all.json"
- assetKey := filepath.Join(resourcePath, assetName)
- bytes, err := Asset(assetKey)
- if err != nil {
- return
- }
- err = goi18n.ParseTranslationFileBytes(assetName, bytes)
- return
+ assetName := locale + ".all.json"
+ assetKey := filepath.Join(resourcePath, assetName)
+ bytes, err := Asset(assetKey)
+ if err != nil {
+ return
+ }
+ err = goi18n.ParseTranslationFileBytes(assetName, bytes)
+ return
}
// TODO() when are these used?
func normalize(locale string) string {
- locale = strings.ToLower(strings.Replace(locale, "-", "_", 1))
- for _, l := range SUPPORTED_LOCALES {
- if strings.EqualFold(locale, l) {
- return l
- }
- }
- switch locale {
- case "zh_cn", "zh_sg":
- return "zh_Hans"
- case "zh_hk", "zh_tw":
- return "zh_Hant"
- }
- return locale
+ locale = strings.ToLower(strings.Replace(locale, "-", "_", 1))
+ for _, l := range SUPPORTED_LOCALES {
+ if strings.EqualFold(locale, l) {
+ return l
+ }
+ }
+ switch locale {
+ case "zh_cn", "zh_sg":
+ return "zh_Hans"
+ case "zh_hk", "zh_tw":
+ return "zh_Hant"
+ }
+ return locale
}
// TODO() when are these used?
func isSupported(locale string) bool {
- for _, l := range SUPPORTED_LOCALES {
- if strings.EqualFold(locale, l) {
- return true
- }
- }
- return false
+ for _, l := range SUPPORTED_LOCALES {
+ if strings.EqualFold(locale, l) {
+ return true
+ }
+ }
+ return false
}
// TODO() when are these used?
func defaultLocaleForLang(lang string) string {
- if lang != "" {
- lang = strings.ToLower(lang)
- for _, l := range SUPPORTED_LOCALES {
- if lang == LangOfLocale(l) {
- return l
- }
- }
- }
- return ""
+ if lang != "" {
+ lang = strings.ToLower(lang)
+ for _, l := range SUPPORTED_LOCALES {
+ if lang == LangOfLocale(l) {
+ return l
+ }
+ }
+ }
+ return ""
}
func LangOfLocale(locale string) string {
- if len(locale) < 2 {
- return ""
- }
- return locale[0:2]
+ if len(locale) < 2 {
+ return ""
+ }
+ return locale[0:2]
}
diff --git a/wski18n/i18n_ids.go b/wski18n/i18n_ids.go
index 8f8b544..d2f4be3 100644
--- a/wski18n/i18n_ids.go
+++ b/wski18n/i18n_ids.go
@@ -20,192 +20,192 @@ package wski18n
// descriptive key names
// DO NOT TRANSLATE
const (
- ACTION_CODE = "Action source"
- ACTIONS = "Actions"
- ACTIVATIONS = "Activations"
- API_HOST = "API host"
- AUTH_KEY = "authentication key"
- COMMAND_LINE = "wskdeploy command line"
- DEPLOYMENT = "deployment"
- CONFIGURATION = "Configuration"
- MANIFEST = "manifest"
- NAME_ACTION = "Action Name"
- NAME_FEED = "Feed Name"
- NAME_RULE = "Rule Name"
- NAME_RUNTIME = "Runtime Name"
- NAME_TRIGGER = "Trigger Name"
- NAMESPACES = "Namespaces"
- PACKAGE_BINDING = "package binding"
- PACKAGE_LICENSE = "package license"
- PACKAGE_NAME = "package name"
- PACKAGE_VERSION = "package version"
- PACKAGES = "Packages"
- PROJECT_NAME = "project name"
- REGISTRY = "registry"
- REGISTRY_URL = "registry URL"
- REPOSITORY = "repository"
- RULES = "Rules"
- TRIGGER_FEED = "trigger feed"
- TRIGGERS = "Triggers"
- WHISK_PROPS = "wskprops"
+ ACTION_CODE = "Action source"
+ ACTIONS = "Actions"
+ ACTIVATIONS = "Activations"
+ API_HOST = "API host"
+ AUTH_KEY = "authentication key"
+ COMMAND_LINE = "wskdeploy command line"
+ DEPLOYMENT = "deployment"
+ CONFIGURATION = "Configuration"
+ MANIFEST = "manifest"
+ NAME_ACTION = "Action Name"
+ NAME_FEED = "Feed Name"
+ NAME_RULE = "Rule Name"
+ NAME_RUNTIME = "Runtime Name"
+ NAME_TRIGGER = "Trigger Name"
+ NAMESPACES = "Namespaces"
+ PACKAGE_BINDING = "package binding"
+ PACKAGE_LICENSE = "package license"
+ PACKAGE_NAME = "package name"
+ PACKAGE_VERSION = "package version"
+ PACKAGES = "Packages"
+ PROJECT_NAME = "project name"
+ REGISTRY = "registry"
+ REGISTRY_URL = "registry URL"
+ REPOSITORY = "repository"
+ RULES = "Rules"
+ TRIGGER_FEED = "trigger feed"
+ TRIGGERS = "Triggers"
+ WHISK_PROPS = "wskprops"
)
// i18n Identifiers
// DO NOT TRANSLATE
-const(
+const (
// Debug / trace message prefixes
- ID_MSG_PREFIX_ERROR = "msg_prefix_error" // "Error"
- ID_MSG_PREFIX_INFO = "msg_prefix_info" // "Info"
- ID_MSG_PREFIX_SUCCESS = "msg_prefix_success" // "Success"
- ID_MSG_PREFIX_WARNING = "msg_prefix_warning" // "Warning"
+ ID_MSG_PREFIX_ERROR = "msg_prefix_error" // "Error"
+ ID_MSG_PREFIX_INFO = "msg_prefix_info" // "Info"
+ ID_MSG_PREFIX_SUCCESS = "msg_prefix_success" // "Success"
+ ID_MSG_PREFIX_WARNING = "msg_prefix_warning" // "Warning"
// Cobra command descriptions
- ID_CMD_DESC_LONG_PUBLISH = "msg_cmd_desc_long_publish"
- ID_CMD_DESC_LONG_REPORT = "msg_cmd_desc_long_report"
- ID_CMD_DESC_LONG_ROOT = "msg_cmd_desc_long_root"
- ID_CMD_DESC_SHORT_ADD = "msg_cmd_desc_short_add"
- ID_CMD_DESC_SHORT_ADD_X_key_X = "msg_cmd_desc_short_add_entity"
- ID_CMD_DESC_SHORT_PUBLISH = "msg_cmd_desc_short_publish"
- ID_CMD_DESC_SHORT_REPORT = "msg_cmd_desc_short_report"
- ID_CMD_DESC_SHORT_ROOT = "msg_cmd_desc_short_root"
- ID_CMD_DESC_SHORT_VERSION = "msg_cmd_desc_short_version"
+ ID_CMD_DESC_LONG_PUBLISH = "msg_cmd_desc_long_publish"
+ ID_CMD_DESC_LONG_REPORT = "msg_cmd_desc_long_report"
+ ID_CMD_DESC_LONG_ROOT = "msg_cmd_desc_long_root"
+ ID_CMD_DESC_SHORT_ADD = "msg_cmd_desc_short_add"
+ ID_CMD_DESC_SHORT_ADD_X_key_X = "msg_cmd_desc_short_add_entity"
+ ID_CMD_DESC_SHORT_PUBLISH = "msg_cmd_desc_short_publish"
+ ID_CMD_DESC_SHORT_REPORT = "msg_cmd_desc_short_report"
+ ID_CMD_DESC_SHORT_ROOT = "msg_cmd_desc_short_root"
+ ID_CMD_DESC_SHORT_VERSION = "msg_cmd_desc_short_version"
// Cobra Flag messages
- ID_CMD_FLAG_API_HOST = "msg_cmd_flag_api_host"
- ID_CMD_FLAG_API_VERSION = "msg_cmd_flag_api_version"
- ID_CMD_FLAG_AUTH_KEY = "msg_cmd_flag_auth_key"
- ID_CMD_FLAG_CERT_FILE = "msg_cmd_flag_cert_file"
- ID_CMD_FLAG_CONFIG = "msg_cmd_flag_config"
- ID_CMD_FLAG_DEFAULTS = "msg_cmd_flag_allow_defaults"
- ID_CMD_FLAG_DEPLOYMENT = "msg_cmd_flag_deployment"
- ID_CMD_FLAG_INTERACTIVE = "msg_cmd_flag_interactive"
- ID_CMD_FLAG_KEY_FILE = "msg_cmd_flag_key_file"
- ID_CMD_FLAG_MANAGED = "msg_cmd_flag_allow_managed"
- ID_CMD_FLAG_MANIFEST = "msg_cmd_flag_manifest"
- ID_CMD_FLAG_NAMESPACE = "msg_cmd_flag_namespace"
- ID_CMD_FLAG_PROJECT = "msg_cmd_flag_project"
- ID_CMD_FLAG_STRICT = "msg_cmd_flag_strict"
- ID_CMD_FLAG_TOGGLE_HELP = "msg_cmd_flag_toggle_help"
- ID_CMD_FLAG_VERBOSE = "msg_cmd_flag_allow_verbose"
+ ID_CMD_FLAG_API_HOST = "msg_cmd_flag_api_host"
+ ID_CMD_FLAG_API_VERSION = "msg_cmd_flag_api_version"
+ ID_CMD_FLAG_AUTH_KEY = "msg_cmd_flag_auth_key"
+ ID_CMD_FLAG_CERT_FILE = "msg_cmd_flag_cert_file"
+ ID_CMD_FLAG_CONFIG = "msg_cmd_flag_config"
+ ID_CMD_FLAG_DEFAULTS = "msg_cmd_flag_allow_defaults"
+ ID_CMD_FLAG_DEPLOYMENT = "msg_cmd_flag_deployment"
+ ID_CMD_FLAG_INTERACTIVE = "msg_cmd_flag_interactive"
+ ID_CMD_FLAG_KEY_FILE = "msg_cmd_flag_key_file"
+ ID_CMD_FLAG_MANAGED = "msg_cmd_flag_allow_managed"
+ ID_CMD_FLAG_MANIFEST = "msg_cmd_flag_manifest"
+ ID_CMD_FLAG_NAMESPACE = "msg_cmd_flag_namespace"
+ ID_CMD_FLAG_PROJECT = "msg_cmd_flag_project"
+ ID_CMD_FLAG_STRICT = "msg_cmd_flag_strict"
+ ID_CMD_FLAG_TOGGLE_HELP = "msg_cmd_flag_toggle_help"
+ ID_CMD_FLAG_VERBOSE = "msg_cmd_flag_allow_verbose"
// Configuration messages
- ID_MSG_CONFIG_MISSING_AUTHKEY = "msg_config_missing_authkey"
- ID_MSG_CONFIG_MISSING_APIHOST = "msg_config_missing_apihost"
- ID_MSG_CONFIG_MISSING_NAMESPACE = "msg_config_missing_namespace"
- ID_MSG_CONFIG_INFO_APIHOST_X_host_X_source_X = "msg_config_apihost_info"
- ID_MSG_CONFIG_INFO_AUTHKEY_X_source_X = "msg_config_authkey_info"
- ID_MSG_CONFIG_INFO_NAMESPACE_X_namespace_X_source_X = "msg_config_namespace_info"
+ ID_MSG_CONFIG_MISSING_AUTHKEY = "msg_config_missing_authkey"
+ ID_MSG_CONFIG_MISSING_APIHOST = "msg_config_missing_apihost"
+ ID_MSG_CONFIG_MISSING_NAMESPACE = "msg_config_missing_namespace"
+ ID_MSG_CONFIG_INFO_APIHOST_X_host_X_source_X = "msg_config_apihost_info"
+ ID_MSG_CONFIG_INFO_AUTHKEY_X_source_X = "msg_config_authkey_info"
+ ID_MSG_CONFIG_INFO_NAMESPACE_X_namespace_X_source_X = "msg_config_namespace_info"
// YAML marshall / unmarshall
- ID_MSG_UNMARSHAL_LOCAL = "msg_unmarshall_local"
- ID_MSG_UNMARSHAL_NETWORK = "msg_unmarshall_network"
+ ID_MSG_UNMARSHAL_LOCAL = "msg_unmarshall_local"
+ ID_MSG_UNMARSHAL_NETWORK = "msg_unmarshall_network"
// Informational
- ID_MSG_DEPLOYMENT_CANCELLED = "msg_deployment_cancelled"
- ID_MSG_DEPLOYMENT_FAILED = "msg_deployment_failed"
- ID_MSG_DEPLOYMENT_REPORT = "msg_deployment_report_status"
- ID_MSG_DEPLOYMENT_SUCCEEDED = "msg_deployment_succeeded"
+ ID_MSG_DEPLOYMENT_CANCELLED = "msg_deployment_cancelled"
+ ID_MSG_DEPLOYMENT_FAILED = "msg_deployment_failed"
+ ID_MSG_DEPLOYMENT_REPORT = "msg_deployment_report_status"
+ ID_MSG_DEPLOYMENT_SUCCEEDED = "msg_deployment_succeeded"
- ID_MSG_UNDEPLOYMENT_CANCELLED = "msg_undeployment_cancelled"
- ID_MSG_UNDEPLOYMENT_FAILED = "msg_undeployment_failed"
- ID_MSG_UNDEPLOYMENT_SUCCEEDED = "msg_undeployment_succeeded"
+ ID_MSG_UNDEPLOYMENT_CANCELLED = "msg_undeployment_cancelled"
+ ID_MSG_UNDEPLOYMENT_FAILED = "msg_undeployment_failed"
+ ID_MSG_UNDEPLOYMENT_SUCCEEDED = "msg_undeployment_succeeded"
- ID_MSG_MANIFEST_DEPLOY_X_path_X = "msg_manifest_using_deployment"
- ID_MSG_MANIFEST_UNDEPLOY_X_path_X = "msg_manifest_using_undeployment"
+ ID_MSG_MANIFEST_DEPLOY_X_path_X = "msg_manifest_using_deployment"
+ ID_MSG_MANIFEST_UNDEPLOY_X_path_X = "msg_manifest_using_undeployment"
- ID_MSG_ENTITY_DEPLOYED_SUCCESS_X_key_X_name_X = "msg_entity_deployed_success"
- ID_MSG_ENTITY_DEPLOYING_X_key_X_name_X = "msg_entity_deploying"
- ID_MSG_ENTITY_UNDEPLOYED_SUCCESS_X_key_X_name_X = "msg_entity_undeployed_success"
- ID_MSG_ENTITY_UNDEPLOYING_X_key_X_name_X = "msg_entity_undeploying"
+ ID_MSG_ENTITY_DEPLOYED_SUCCESS_X_key_X_name_X = "msg_entity_deployed_success"
+ ID_MSG_ENTITY_DEPLOYING_X_key_X_name_X = "msg_entity_deploying"
+ ID_MSG_ENTITY_UNDEPLOYED_SUCCESS_X_key_X_name_X = "msg_entity_undeployed_success"
+ ID_MSG_ENTITY_UNDEPLOYING_X_key_X_name_X = "msg_entity_undeploying"
- ID_MSG_DEPENDENCY_DEPLOYING_X_name_X = "msg_dependency_deploying"
- ID_MSG_DEPENDENCY_DEPLOYMENT_FAILURE_X_name_X = "msg_dependency_deployment_failure"
- ID_MSG_DEPENDENCY_DEPLOYMENT_SUCCESS_X_name_X = "msg_dependency_deployment_success"
- ID_MSG_DEPENDENCY_UNDEPLOYING_X_name_X = "msg_dependency_undeploying"
- ID_MSG_DEPENDENCY_UNDEPLOYMENT_FAILURE_X_name_X = "msg_dependency_undeployment_failure"
- ID_MSG_DEPENDENCY_UNDEPLOYMENT_SUCCESS_X_name_X = "msg_dependency_undeployment_success"
+ ID_MSG_DEPENDENCY_DEPLOYING_X_name_X = "msg_dependency_deploying"
+ ID_MSG_DEPENDENCY_DEPLOYMENT_FAILURE_X_name_X = "msg_dependency_deployment_failure"
+ ID_MSG_DEPENDENCY_DEPLOYMENT_SUCCESS_X_name_X = "msg_dependency_deployment_success"
+ ID_MSG_DEPENDENCY_UNDEPLOYING_X_name_X = "msg_dependency_undeploying"
+ ID_MSG_DEPENDENCY_UNDEPLOYMENT_FAILURE_X_name_X = "msg_dependency_undeployment_failure"
+ ID_MSG_DEPENDENCY_UNDEPLOYMENT_SUCCESS_X_name_X = "msg_dependency_undeployment_success"
// Managed deployments
- ID_MSG_MANAGED_UNDEPLOYMENT_FAILED = "msg_managed_undeployment_failed"
- ID_MSG_MANAGED_FOUND_DELETED_X_key_X_name_X_project_X = "msg_managed_found_deleted_entity"
+ ID_MSG_MANAGED_UNDEPLOYMENT_FAILED = "msg_managed_undeployment_failed"
+ ID_MSG_MANAGED_FOUND_DELETED_X_key_X_name_X_project_X = "msg_managed_found_deleted_entity"
// Interactive (prompts)
- ID_MSG_PROMPT_APIHOST = "msg_prompt_apihost"
- ID_MSG_PROMPT_AUTHKEY = "msg_prompt_authkey"
- ID_MSG_PROMPT_DEPLOY = "msg_prompt_deploy"
- ID_MSG_PROMPT_NAMESPACE = "msg_prompt_namespace"
- ID_MSG_PROMPT_UNDEPLOY = "msg_prompt_undeploy"
+ ID_MSG_PROMPT_APIHOST = "msg_prompt_apihost"
+ ID_MSG_PROMPT_AUTHKEY = "msg_prompt_authkey"
+ ID_MSG_PROMPT_DEPLOY = "msg_prompt_deploy"
+ ID_MSG_PROMPT_NAMESPACE = "msg_prompt_namespace"
+ ID_MSG_PROMPT_UNDEPLOY = "msg_prompt_undeploy"
// Errors
- ID_ERR_DEPENDENCY_UNKNOWN_TYPE = "msg_err_dependency_unknown_type"
- ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X = "msg_err_deployment_name_not_found"
- ID_ERR_ENTITY_CREATE_X_key_X_err_X_code_X = "msg_err_entity_create"
- ID_ERR_ENTITY_DELETE_X_key_X_err_X_code_X = "msg_err_entity_delete"
- ID_ERR_FEED_INVOKE_X_err_X_code_X = "msg_err_feed_invoke"
- ID_ERR_KEY_MISSING_X_key_X = "msg_err_key_missing_mandatory"
- ID_ERR_MANIFEST_FILE_NOT_FOUND_X_path_X = "msg_err_manifest_not_found"
+ ID_ERR_DEPENDENCY_UNKNOWN_TYPE = "msg_err_dependency_unknown_type"
+ ID_ERR_DEPLOYMENT_NAME_NOT_FOUND_X_key_X_name_X = "msg_err_deployment_name_not_found"
+ ID_ERR_ENTITY_CREATE_X_key_X_err_X_code_X = "msg_err_entity_create"
+ ID_ERR_ENTITY_DELETE_X_key_X_err_X_code_X = "msg_err_entity_delete"
+ ID_ERR_FEED_INVOKE_X_err_X_code_X = "msg_err_feed_invoke"
+ ID_ERR_KEY_MISSING_X_key_X = "msg_err_key_missing_mandatory"
+ ID_ERR_MANIFEST_FILE_NOT_FOUND_X_path_X = "msg_err_manifest_not_found"
ID_ERR_NAME_MISMATCH_X_key_X_dname_X_dpath_X_mname_X_moath_X = "msg_err_name_mismatch"
- ID_ERR_RUNTIME_INVALID_X_runtime_X_action_X = "msg_err_runtime_invalid"
- ID_ERR_RUNTIME_MISMATCH_X_runtime_X_ext_X_action_X = "msg_err_runtime_mismatch"
- ID_ERR_RUNTIMES_GET_X_err_X = "msg_err_runtimes_get"
- ID_ERR_URL_INVALID_X_urltype_X_url_X_filetype_X = "msg_err_url_invalid"
- ID_ERR_URL_MALFORMED_X_urltype_X_url_X = "msg_err_url_malformed"
+ ID_ERR_RUNTIME_INVALID_X_runtime_X_action_X = "msg_err_runtime_invalid"
+ ID_ERR_RUNTIME_MISMATCH_X_runtime_X_ext_X_action_X = "msg_err_runtime_mismatch"
+ ID_ERR_RUNTIMES_GET_X_err_X = "msg_err_runtimes_get"
+ ID_ERR_URL_INVALID_X_urltype_X_url_X_filetype_X = "msg_err_url_invalid"
+ ID_ERR_URL_MALFORMED_X_urltype_X_url_X = "msg_err_url_malformed"
// Server-side Errors (wskdeploy as an Action)
- ID_ERR_JSON_MISSING_KEY_CMD = "msg_err_json_missing_cmd_key"
+ ID_ERR_JSON_MISSING_KEY_CMD = "msg_err_json_missing_cmd_key"
// warnings
- ID_WARN_COMMAND_RETRY = "msg_warn_command_retry"
- ID_WARN_CONFIG_INVALID_X_path_X = "msg_warn_config_invalid"
- ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X = "msg_warn_key_deprecated_replaced"
- ID_WARN_KEY_MISSING_X_key_X_value_X = "msg_warn_key_missing"
- ID_WARN_KEYVALUE_INVALID = "msg_warn_key_value_invalid"
- ID_WARN_KEYVALUE_NOT_SAVED_X_key_X = "msg_warn_key_value_not_saved"
- ID_WARN_LIMIT_IGNORED_X_limit_X = "msg_warn_limit_ignored"
- ID_WARN_LIMIT_UNCHANGEABLE_X_name_X = "msg_warn_limit_changeable"
- ID_WARN_LIMITS_LOG_SIZE = "msg_warn_limits_log_size" // TODO() remove for value range
- ID_WARN_LIMITS_MEMORY_SIZE = "msg_warn_limits_memory_size" // TODO() remove for value range
- ID_WARN_LIMITS_TIMEOUT = "msg_warn_limits_timeout" // TODO() remove for value range
- ID_WARN_RUNTIME_CHANGED_X_runtime_X_action_X = "msg_warn_runtime_changed"
- ID_WARN_VALUE_RANGE_X_name_X_key_X_filetype_X_min_X_max_X = "msg_warn_value_range" // TODO() not used, but should be used for limit ranges
- ID_WARN_WHISK_PROPS_DEPRECATED = "msg_warn_whisk_properties"
- ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X = "msg_warn_entity_name_exists"
+ ID_WARN_COMMAND_RETRY = "msg_warn_command_retry"
+ ID_WARN_CONFIG_INVALID_X_path_X = "msg_warn_config_invalid"
+ ID_WARN_KEY_DEPRECATED_X_oldkey_X_filetype_X_newkey_X = "msg_warn_key_deprecated_replaced"
+ ID_WARN_KEY_MISSING_X_key_X_value_X = "msg_warn_key_missing"
+ ID_WARN_KEYVALUE_INVALID = "msg_warn_key_value_invalid"
+ ID_WARN_KEYVALUE_NOT_SAVED_X_key_X = "msg_warn_key_value_not_saved"
+ ID_WARN_LIMIT_IGNORED_X_limit_X = "msg_warn_limit_ignored"
+ ID_WARN_LIMIT_UNCHANGEABLE_X_name_X = "msg_warn_limit_changeable"
+ ID_WARN_LIMITS_LOG_SIZE = "msg_warn_limits_log_size" // TODO() remove for value range
+ ID_WARN_LIMITS_MEMORY_SIZE = "msg_warn_limits_memory_size" // TODO() remove for value range
+ ID_WARN_LIMITS_TIMEOUT = "msg_warn_limits_timeout" // TODO() remove for value range
+ ID_WARN_RUNTIME_CHANGED_X_runtime_X_action_X = "msg_warn_runtime_changed"
+ ID_WARN_VALUE_RANGE_X_name_X_key_X_filetype_X_min_X_max_X = "msg_warn_value_range" // TODO() not used, but should be used for limit ranges
+ ID_WARN_WHISK_PROPS_DEPRECATED = "msg_warn_whisk_properties"
+ ID_WARN_ENTITY_NAME_EXISTS_X_key_X_name_X = "msg_warn_entity_name_exists"
// Verbose (Debug/Trace) messages
- ID_DEBUG_KEY_VERIFY_X_name_X_key_X = "msg_dbg_key_verify"
- ID_DEBUG_DEPLOYING_USING = "msg_dbg_deploying_using"
- ID_DEBUG_UNDEPLOYING_USING = "msg_dbg_undeploying_using"
- ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X = "msg_dbg_searching_project_directory"
+ ID_DEBUG_KEY_VERIFY_X_name_X_key_X = "msg_dbg_key_verify"
+ ID_DEBUG_DEPLOYING_USING = "msg_dbg_deploying_using"
+ ID_DEBUG_UNDEPLOYING_USING = "msg_dbg_undeploying_using"
+ ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X = "msg_dbg_searching_project_directory"
)
// Known keys used for text replacement in i18n translated strings
-const(
- KEY_ACTION = "action"
- KEY_CMD = "cmd"
- KEY_CODE = "code"
- KEY_DEPLOYMENT_NAME = "dname"
- KEY_DEPLOYMENT_PATH = "dpath"
- KEY_ERR = "err"
- KEY_EXTENTION = "ext"
- KEY_FILE_TYPE = "filetype"
- KEY_HOST = "host"
- KEY_KEY = "key"
- KEY_LIMIT = "limit"
- KEY_MANIFEST_NAME = "mname"
- KEY_MANIFEST_PATH = "mpath"
- KEY_NAME = "name"
- KEY_NAMESPACE = "namespace"
- KEY_NEW = "newkey"
- KEY_OLD = "oldkey"
- KEY_PATH = "path"
- KEY_PROJECT = "project"
- KEY_RUNTIME = "runtime"
- KEY_SOURCE = "source"
- KEY_URL = "url"
- KEY_URL_TYPE = "urltype"
- KEY_VALUE = "value"
- KEY_VALUE_MIN = "min" // TODO() attempt to use this for Limit value range errors
- KEY_VALUE_MAX = "max" // TODO() attempt to use this for Limit value range errors
+const (
+ KEY_ACTION = "action"
+ KEY_CMD = "cmd"
+ KEY_CODE = "code"
+ KEY_DEPLOYMENT_NAME = "dname"
+ KEY_DEPLOYMENT_PATH = "dpath"
+ KEY_ERR = "err"
+ KEY_EXTENTION = "ext"
+ KEY_FILE_TYPE = "filetype"
+ KEY_HOST = "host"
+ KEY_KEY = "key"
+ KEY_LIMIT = "limit"
+ KEY_MANIFEST_NAME = "mname"
+ KEY_MANIFEST_PATH = "mpath"
+ KEY_NAME = "name"
+ KEY_NAMESPACE = "namespace"
+ KEY_NEW = "newkey"
+ KEY_OLD = "oldkey"
+ KEY_PATH = "path"
+ KEY_PROJECT = "project"
+ KEY_RUNTIME = "runtime"
+ KEY_SOURCE = "source"
+ KEY_URL = "url"
+ KEY_URL_TYPE = "urltype"
+ KEY_VALUE = "value"
+ KEY_VALUE_MIN = "min" // TODO() attempt to use this for Limit value range errors
+ KEY_VALUE_MAX = "max" // TODO() attempt to use this for Limit value range errors
)
// Used to unit test that translations exist with these IDs
diff --git a/wski18n/i18n_ids_test.go b/wski18n/i18n_ids_test.go
index ac8c828..cfd98b8 100644
--- a/wski18n/i18n_ids_test.go
+++ b/wski18n/i18n_ids_test.go
@@ -20,8 +20,8 @@
package wski18n
import (
- "testing"
"github.com/stretchr/testify/assert"
+ "testing"
)
/*
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 29d8528..f85928c 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -329,14 +329,14 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
- "wski18n/resources/de_DE.all.json": wski18nResourcesDe_deAllJson,
- "wski18n/resources/en_US.all.json": wski18nResourcesEn_usAllJson,
- "wski18n/resources/es_ES.all.json": wski18nResourcesEs_esAllJson,
- "wski18n/resources/fr_FR.all.json": wski18nResourcesFr_frAllJson,
- "wski18n/resources/it_IT.all.json": wski18nResourcesIt_itAllJson,
- "wski18n/resources/ja_JA.all.json": wski18nResourcesJa_jaAllJson,
- "wski18n/resources/ko_KR.all.json": wski18nResourcesKo_krAllJson,
- "wski18n/resources/pt_BR.all.json": wski18nResourcesPt_brAllJson,
+ "wski18n/resources/de_DE.all.json": wski18nResourcesDe_deAllJson,
+ "wski18n/resources/en_US.all.json": wski18nResourcesEn_usAllJson,
+ "wski18n/resources/es_ES.all.json": wski18nResourcesEs_esAllJson,
+ "wski18n/resources/fr_FR.all.json": wski18nResourcesFr_frAllJson,
+ "wski18n/resources/it_IT.all.json": wski18nResourcesIt_itAllJson,
+ "wski18n/resources/ja_JA.all.json": wski18nResourcesJa_jaAllJson,
+ "wski18n/resources/ko_KR.all.json": wski18nResourcesKo_krAllJson,
+ "wski18n/resources/pt_BR.all.json": wski18nResourcesPt_brAllJson,
"wski18n/resources/zh_Hans.all.json": wski18nResourcesZh_hansAllJson,
"wski18n/resources/zh_Hant.all.json": wski18nResourcesZh_hantAllJson,
}
@@ -380,19 +380,20 @@ type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
+
var _bintree = &bintree{nil, map[string]*bintree{
- "wski18n": &bintree{nil, map[string]*bintree{
- "resources": &bintree{nil, map[string]*bintree{
- "de_DE.all.json": &bintree{wski18nResourcesDe_deAllJson, map[string]*bintree{}},
- "en_US.all.json": &bintree{wski18nResourcesEn_usAllJson, map[string]*bintree{}},
- "es_ES.all.json": &bintree{wski18nResourcesEs_esAllJson, map[string]*bintree{}},
- "fr_FR.all.json": &bintree{wski18nResourcesFr_frAllJson, map[string]*bintree{}},
- "it_IT.all.json": &bintree{wski18nResourcesIt_itAllJson, map[string]*bintree{}},
- "ja_JA.all.json": &bintree{wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
- "ko_KR.all.json": &bintree{wski18nResourcesKo_krAllJson, map[string]*bintree{}},
- "pt_BR.all.json": &bintree{wski18nResourcesPt_brAllJson, map[string]*bintree{}},
- "zh_Hans.all.json": &bintree{wski18nResourcesZh_hansAllJson, map[string]*bintree{}},
- "zh_Hant.all.json": &bintree{wski18nResourcesZh_hantAllJson, map[string]*bintree{}},
+ "wski18n": {nil, map[string]*bintree{
+ "resources": {nil, map[string]*bintree{
+ "de_DE.all.json": {wski18nResourcesDe_deAllJson, map[string]*bintree{}},
+ "en_US.all.json": {wski18nResourcesEn_usAllJson, map[string]*bintree{}},
+ "es_ES.all.json": {wski18nResourcesEs_esAllJson, map[string]*bintree{}},
+ "fr_FR.all.json": {wski18nResourcesFr_frAllJson, map[string]*bintree{}},
+ "it_IT.all.json": {wski18nResourcesIt_itAllJson, map[string]*bintree{}},
+ "ja_JA.all.json": {wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
+ "ko_KR.all.json": {wski18nResourcesKo_krAllJson, map[string]*bintree{}},
+ "pt_BR.all.json": {wski18nResourcesPt_brAllJson, map[string]*bintree{}},
+ "zh_Hans.all.json": {wski18nResourcesZh_hansAllJson, map[string]*bintree{}},
+ "zh_Hant.all.json": {wski18nResourcesZh_hantAllJson, map[string]*bintree{}},
}},
}},
}}
@@ -443,4 +444,3 @@ func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
-
diff --git a/wskprint/console.go b/wskprint/console.go
index 122eed7..94e0f5d 100644
--- a/wskprint/console.go
+++ b/wskprint/console.go
@@ -24,21 +24,21 @@ import (
"github.com/mattn/go-colorable"
)
-const(
+const (
STR_PREFIXED_MESSAGE = "%s: %s"
)
-var(
- clrInfo = color.New(color.FgCyan)
- clrWarning = color.New(color.FgYellow)
- clrError = color.New(color.FgRed)
- clrSuccess = color.New(color.FgGreen)
+var (
+ clrInfo = color.New(color.FgCyan)
+ clrWarning = color.New(color.FgYellow)
+ clrError = color.New(color.FgRed)
+ clrSuccess = color.New(color.FgGreen)
clrTitleInfo = color.New(color.FgCyan).Add(color.Underline)
)
func PrintOpenWhiskError(message string) {
outputStream := colorable.NewColorableStderr()
- fmt.Fprintf(outputStream, clrError.Sprintf( STR_PREFIXED_MESSAGE,
+ fmt.Fprintf(outputStream, clrError.Sprintf(STR_PREFIXED_MESSAGE,
wski18n.T(wski18n.ID_MSG_PREFIX_ERROR), message))
}
@@ -48,7 +48,7 @@ func PrintOpenWhiskFromError(err error) {
func PrintOpenWhiskWarning(message string) {
outputStream := colorable.NewColorableStdout()
- fmt.Fprintf(outputStream, clrWarning.Sprintf( STR_PREFIXED_MESSAGE,
+ fmt.Fprintf(outputStream, clrWarning.Sprintf(STR_PREFIXED_MESSAGE,
wski18n.T(wski18n.ID_MSG_PREFIX_WARNING), message))
}
@@ -58,7 +58,7 @@ func PrintlnOpenWhiskWarning(message string) {
func PrintOpenWhiskSuccess(message string) {
outputStream := colorable.NewColorableStdout()
- fmt.Fprintf(outputStream, clrSuccess.Sprintf( STR_PREFIXED_MESSAGE,
+ fmt.Fprintf(outputStream, clrSuccess.Sprintf(STR_PREFIXED_MESSAGE,
wski18n.T(wski18n.ID_MSG_PREFIX_SUCCESS), message))
}
@@ -68,37 +68,36 @@ func PrintlnOpenWhiskSuccess(message string) {
func PrintOpenWhiskInfo(message string) {
outputStream := colorable.NewColorableStdout()
- fmt.Fprintf(outputStream, clrInfo.Sprintf( STR_PREFIXED_MESSAGE,
+ fmt.Fprintf(outputStream, clrInfo.Sprintf(STR_PREFIXED_MESSAGE,
wski18n.T(wski18n.ID_MSG_PREFIX_INFO), message))
}
-
func PrintlnOpenWhiskInfo(message string) {
PrintOpenWhiskInfo(message + "\n")
}
func PrintlnOpenWhiskInfoTitle(message string) {
outputStream := colorable.NewColorableStdout()
- fmt.Fprintf(outputStream, clrTitleInfo.Sprintf( STR_PREFIXED_MESSAGE,
+ fmt.Fprintf(outputStream, clrTitleInfo.Sprintf(STR_PREFIXED_MESSAGE,
wski18n.T(wski18n.ID_MSG_PREFIX_INFO), message))
}
func PrintlnOpenWhiskOutput(message string) {
- fmt.Println(message)
+ fmt.Println(message)
}
func PrintOpenWhiskVerboseTitle(verbose bool, message string) {
- if verbose{
+ if verbose {
PrintlnOpenWhiskInfoTitle(message)
}
}
func PrintOpenWhiskVerbose(verbose bool, message string) {
- if verbose{
+ if verbose {
PrintOpenWhiskInfo(message)
}
}
func PrintlnOpenWhiskVerbose(verbose bool, message string) {
- PrintOpenWhiskVerbose(verbose, message + "\n")
+ PrintOpenWhiskVerbose(verbose, message+"\n")
}
--
To stop receiving notification emails like this one, please contact
mrutkowski@apache.org.