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 2017/09/13 22:20:47 UTC
[incubator-openwhisk-wskdeploy] branch master updated: Add line
number and file name into ParseError (#477)
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 382339c Add line number and file name into ParseError (#477)
382339c is described below
commit 382339c2bd8247030b828bf4416e4530681d0f3b
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Wed Sep 13 18:20:45 2017 -0400
Add line number and file name into ParseError (#477)
The information of the line numbers are available in err.Error(),
and the file name is saved in the varible YamlFile.
---
Godeps/Godeps.json | 2 +-
cmd/root.go | 4 -
deployers/manifestreader.go | 6 +-
deployers/servicedeployer.go | 44 +-
parsers/deploy_parser.go | 34 +-
parsers/deploy_parser_test.go | 95 ++
parsers/manifest_parser.go | 40 +-
parsers/manifest_parser_test.go | 1772 ++++++++++++------------
tests/src/integration/triggerrule/manifest.yml | 1 -
utils/contentreader.go | 11 +-
utils/fileoperations.go | 42 +-
utils/gitreader.go | 24 +-
utils/misc.go | 16 +-
utils/util_test.go | 6 +-
utils/wskdeployerror.go | 35 +-
wski18n/i18n_resources.go | 4 +-
wski18n/resources/en_US.all.json | 6 +-
17 files changed, 1201 insertions(+), 941 deletions(-)
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 7f4faec..0ad04e5 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -162,7 +162,7 @@
},
{
"ImportPath": "gopkg.in/yaml.v2",
- "Rev": "f8db564a0a4a5f6d04f66522493597f18e5ab4ae"
+ "Rev": "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
},
{
"ImportPath": "github.com/palantir/stacktrace",
diff --git a/cmd/root.go b/cmd/root.go
index 9ced685..d715aaf 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -193,10 +193,6 @@ func Deploy() error {
deployer.ProjectPath = projectPath
deployer.ManifestPath = utils.Flags.ManifestPath
deployer.DeploymentPath = utils.Flags.DeploymentPath
- // perform some quick check here.
- go func() {
- deployer.Check()
- }()
deployer.IsDefault = utils.Flags.UseDefaults
deployer.IsInteractive = utils.Flags.UseInteractive
diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index ca60c9d..4f409e6 100644
--- a/deployers/manifestreader.go
+++ b/deployers/manifestreader.go
@@ -53,7 +53,7 @@ func (deployer *ManifestReader) ParseManifest() (*parsers.ManifestYAML, *parsers
}
func (reader *ManifestReader) InitRootPackage(manifestParser *parsers.YAMLParser, manifest *parsers.ManifestYAML) error {
- packg, err := manifestParser.ComposePackage(manifest)
+ packg, err := manifestParser.ComposePackage(manifest, reader.serviceDeployer.ManifestPath)
if err != nil {
return utils.NewInputYamlFormatError(err.Error())
}
@@ -66,7 +66,7 @@ func (reader *ManifestReader) InitRootPackage(manifestParser *parsers.YAMLParser
func (deployer *ManifestReader) HandleYaml(sdeployer *ServiceDeployer, manifestParser *parsers.YAMLParser, manifest *parsers.ManifestYAML) error {
var err error
- deps, err := manifestParser.ComposeDependencies(manifest, deployer.serviceDeployer.ProjectPath)
+ deps, err := manifestParser.ComposeDependencies(manifest, deployer.serviceDeployer.ProjectPath, deployer.serviceDeployer.ManifestPath)
if err != nil {
return utils.NewInputYamlFormatError(err.Error())
}
@@ -81,7 +81,7 @@ func (deployer *ManifestReader) HandleYaml(sdeployer *ServiceDeployer, manifestP
return utils.NewInputYamlFormatError(err.Error())
}
- triggers, err := manifestParser.ComposeTriggers(manifest)
+ triggers, err := manifestParser.ComposeTriggers(manifest, deployer.serviceDeployer.ManifestPath)
if err != nil {
return utils.NewInputYamlFormatError(err.Error())
}
diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index c65803f..0bdb8df 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -142,7 +142,10 @@ func (deployer *ServiceDeployer) ConstructDeploymentPlan() error {
// process deploymet file
if utils.FileExists(deployer.DeploymentPath) {
var deploymentReader = NewDeploymentReader(deployer)
- deploymentReader.HandleYaml()
+ err = deploymentReader.HandleYaml()
+ if err != nil {
+ return err
+ }
deploymentReader.BindAssets()
}
@@ -187,7 +190,10 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentApplica
// process deployment file
if utils.FileExists(deployer.DeploymentPath) {
var deploymentReader = NewDeploymentReader(deployer)
- deploymentReader.HandleYaml()
+ err = deploymentReader.HandleYaml()
+ if err != nil {
+ return deployer.Deployment, err
+ }
deploymentReader.BindAssets()
}
@@ -335,7 +341,10 @@ func (deployer *ServiceDeployer) DeployDependencies() error {
bindingPackage.Publish = &pub
qName, err := utils.ParseQualifiedName(depServiceDeployer.RootPackageName, depServiceDeployer.Deployment.Packages[depServiceDeployer.RootPackageName].Package.Namespace)
- utils.Check(err)
+ if err != nil {
+ return err
+ }
+
bindingPackage.Binding = whisk.Binding{qName.Namespace, qName.EntityName}
bindingPackage.Parameters = depRecord.Parameters
@@ -707,7 +716,13 @@ func (deployer *ServiceDeployer) UnDeployDependencies() error {
// delete binding pkg if the origin package name is different
if (depServiceDeployer.RootPackageName != depName) {
_, err := deployer.Client.Packages.Delete(depName)
- utils.Check(err)
+ if err != nil {
+ wskErr := err.(*whisk.WskError)
+ errString := wski18n.T("Got error deleting binding package with error message: {{.err}} and error code: {{.code}}.\n",
+ map[string]interface{}{"err": wskErr.Error(), "code": strconv.Itoa(wskErr.ExitCode)})
+ whisk.Debug(whisk.DbgError, errString)
+ return utils.NewWhiskClientError(wskErr.Error(), wskErr.ExitCode)
+ }
}
if err := depServiceDeployer.unDeployAssets(plan); err != nil {
@@ -950,7 +965,12 @@ func (deployer *ServiceDeployer) printDeploymentAssets(assets *DeploymentApplica
fmt.Println("Name: " + pack.Package.Name)
fmt.Println(" bindings: ")
for _, p := range pack.Package.Parameters {
- fmt.Printf(" - %s : %v\n", p.Key, utils.PrettyJSON(p.Value))
+ jsonValue, err := utils.PrettyJSON(p.Value)
+ if err != nil {
+ fmt.Printf(" - %s : %s\n", p.Key, "Unknown value")
+ } else {
+ fmt.Printf(" - %s : %v\n", p.Key, jsonValue)
+ }
}
for key, dep := range pack.Dependencies {
@@ -967,7 +987,12 @@ func (deployer *ServiceDeployer) printDeploymentAssets(assets *DeploymentApplica
fmt.Println(" * action: " + action.Action.Name)
fmt.Println(" bindings: ")
for _, p := range action.Action.Parameters {
- fmt.Printf(" - %s : %v\n", p.Key, utils.PrettyJSON(p.Value))
+ jsonValue, err := utils.PrettyJSON(p.Value)
+ if err != nil {
+ fmt.Printf(" - %s : %s\n", p.Key, "Unknown value")
+ } else {
+ fmt.Printf(" - %s : %v\n", p.Key, jsonValue)
+ }
}
fmt.Println(" annotations: ")
for _, p := range action.Action.Annotations {
@@ -990,7 +1015,12 @@ func (deployer *ServiceDeployer) printDeploymentAssets(assets *DeploymentApplica
fmt.Println(" bindings: ")
for _, p := range trigger.Parameters {
- fmt.Printf(" - %s : %v\n", p.Key, utils.PrettyJSON(p.Value))
+ jsonValue, err := utils.PrettyJSON(p.Value)
+ if err != nil {
+ fmt.Printf(" - %s : %s\n", p.Key, "Unknown value")
+ } else {
+ fmt.Printf(" - %s : %v\n", p.Key, jsonValue)
+ }
}
fmt.Println(" annotations: ")
diff --git a/parsers/deploy_parser.go b/parsers/deploy_parser.go
index ddae9b0..2c89083 100644
--- a/parsers/deploy_parser.go
+++ b/parsers/deploy_parser.go
@@ -21,12 +21,12 @@ import (
"fmt"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
"gopkg.in/yaml.v2"
+ "strings"
)
func (dm *YAMLParser) UnmarshalDeployment(input []byte, deploy *DeploymentYAML) error {
err := yaml.UnmarshalStrict(input, deploy)
if err != nil {
- fmt.Printf("error happened during unmarshal :%v", err)
return err
}
return nil
@@ -41,20 +41,44 @@ func (dm *YAMLParser) MarshalDeployment(deployment *DeploymentYAML) (output []by
return data, nil
}
-func (dm *YAMLParser) ParseDeployment(dply string) (*DeploymentYAML, error) {
+func (dm *YAMLParser) ParseDeployment(deploymentPath string) (*DeploymentYAML, error) {
dplyyaml := DeploymentYAML{}
- content, err := new(utils.ContentReader).LocalReader.ReadLocal(dply)
+ content, err := new(utils.ContentReader).LocalReader.ReadLocal(deploymentPath)
if err != nil {
return &dplyyaml, utils.NewInputYamlFileError(err.Error())
}
err = dm.UnmarshalDeployment(content, &dplyyaml)
if err != nil {
- return &dplyyaml, utils.NewInputYamlFileError(err.Error())
+ if err != nil {
+
+ lines, msgs := dm.convertErrorToLinesMsgs(err.Error())
+ return &dplyyaml, utils.NewParserErr(deploymentPath, lines, msgs)
+ }
}
- dplyyaml.Filepath = dply
+ dplyyaml.Filepath = deploymentPath
return &dplyyaml, nil
}
+func (dm *YAMLParser) convertErrorToLinesMsgs(errorString string) (lines []string, msgs []string) {
+ strs := strings.Split(errorString, "\n")
+ for i := 0; i < len(strs); i++ {
+ errMsg := strings.TrimSpace(strs[i])
+ if strings.Contains(errMsg, utils.LINE) {
+ s := strings.Split(errMsg, utils.LINE)
+ lineMsg := s[1]
+ line := strings.Split(lineMsg, ":")
+ if (len(line) == 2) {
+ lines = append(lines, strings.TrimSpace(line[0]))
+ msgs = append(msgs, line[1])
+ continue
+ }
+ }
+ lines = append(lines, utils.UNKNOWN)
+ msgs = append(msgs, errMsg)
+ }
+ return
+}
+
//********************Application functions*************************//
//This is for parse the deployment yaml file.
func (app *Application) GetPackageList() []Package {
diff --git a/parsers/deploy_parser_test.go b/parsers/deploy_parser_test.go
new file mode 100644
index 0000000..9e83b85
--- /dev/null
+++ b/parsers/deploy_parser_test.go
@@ -0,0 +1,95 @@
+// +build unit
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package parsers
+
+import (
+ "github.com/stretchr/testify/assert"
+ "os"
+ "testing"
+ "io/ioutil"
+)
+
+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
+}
+
+func TestInvalidKeyDeploymentYaml(t *testing.T) {
+ data :=`application:
+ name: wskdeploy-samples
+ invalidKey: test`
+ tmpfile, err := createTmpfile(data, "deployment_parser_test_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseDeployment(tmpfile.Name())
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 3.
+ assert.Contains(t, err.Error(), "field invalidKey not found in struct parsers.Application: Line 2, its neighbour lines, or the lines on the same level")
+}
+
+func TestMappingValueDeploymentYaml(t *testing.T) {
+ data :=`application:
+ name: wskdeploy-samples
+ packages: test`
+ tmpfile, err := createTmpfile(data, "deployment_parser_test_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseDeployment(tmpfile.Name())
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 3.
+ assert.Contains(t, err.Error(), "mapping values are not allowed in this context: Line 2, its neighbour lines, or the lines on the same level")
+}
+
+func TestMissingRootNodeDeploymentYaml(t *testing.T) {
+ data :=`name: wskdeploy-samples`
+ tmpfile, err := createTmpfile(data, "deployment_parser_test_")
+ if err != nil {
+ assert.Fail(t, "Failed to create temp file")
+ }
+ defer func() {
+ tmpfile.Close()
+ os.Remove(tmpfile.Name())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseDeployment(tmpfile.Name())
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 3.
+ assert.Contains(t, err.Error(), "field name not found in struct parsers.DeploymentYAML: Line 1, its neighbour lines, or the lines on the same level")
+}
diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index a631a70..579d385 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -69,7 +69,6 @@ func Write(manifest *ManifestYAML, filename string) error {
func (dm *YAMLParser) Unmarshal(input []byte, manifest *ManifestYAML) error {
err := yaml.UnmarshalStrict(input, manifest)
if err != nil {
- fmt.Printf("error happened during unmarshal :%v", err)
return err
}
return nil
@@ -84,24 +83,25 @@ func (dm *YAMLParser) Marshal(manifest *ManifestYAML) (output []byte, err error)
return data, nil
}
-func (dm *YAMLParser) ParseManifest(mani string) (*ManifestYAML, error) {
+func (dm *YAMLParser) ParseManifest(manifestPath string) (*ManifestYAML, error) {
mm := NewYAMLParser()
maniyaml := ManifestYAML{}
- content, err := utils.Read(mani)
+ content, err := utils.Read(manifestPath)
if err != nil {
return &maniyaml, utils.NewInputYamlFileError(err.Error())
}
err = mm.Unmarshal(content, &maniyaml)
if err != nil {
- return &maniyaml, utils.NewInputYamlFileError(err.Error())
+ lines, msgs := dm.convertErrorToLinesMsgs(err.Error())
+ return &maniyaml, utils.NewParserErr(manifestPath, lines, msgs)
}
- maniyaml.Filepath = mani
+ maniyaml.Filepath = manifestPath
return &maniyaml, nil
}
-func (dm *YAMLParser) ComposeDependencies(mani *ManifestYAML, projectPath string) (map[string]utils.DependencyRecord, error) {
+func (dm *YAMLParser) ComposeDependencies(mani *ManifestYAML, projectPath string, filePath string) (map[string]utils.DependencyRecord, error) {
var errorParser error
depMap := make(map[string]utils.DependencyRecord)
@@ -137,7 +137,7 @@ func (dm *YAMLParser) ComposeDependencies(mani *ManifestYAML, projectPath string
var keyVal whisk.KeyValue
keyVal.Key = name
- keyVal.Value, errorParser = ResolveParameter(name, ¶m)
+ keyVal.Value, errorParser = ResolveParameter(name, ¶m, filePath)
if errorParser != nil {
return nil, errorParser
@@ -165,7 +165,7 @@ func (dm *YAMLParser) ComposeDependencies(mani *ManifestYAML, projectPath string
}
// Is we consider multi pacakge in one yaml?
-func (dm *YAMLParser) ComposePackage(mani *ManifestYAML) (*whisk.Package, error) {
+func (dm *YAMLParser) ComposePackage(mani *ManifestYAML, filePath string) (*whisk.Package, error) {
var errorParser error
//mani := dm.ParseManifest(manipath)
@@ -181,7 +181,7 @@ func (dm *YAMLParser) ComposePackage(mani *ManifestYAML) (*whisk.Package, error)
var keyVal whisk.KeyValue
keyVal.Key = name
- keyVal.Value, errorParser = ResolveParameter(name, ¶m)
+ keyVal.Value, errorParser = ResolveParameter(name, ¶m, filePath)
if errorParser != nil {
return nil, errorParser
@@ -328,7 +328,7 @@ func (dm *YAMLParser) ComposeActions(mani *ManifestYAML, manipath string) (ar []
var keyVal whisk.KeyValue
keyVal.Key = name
- keyVal.Value, errorParser = ResolveParameter(name, ¶m)
+ keyVal.Value, errorParser = ResolveParameter(name, ¶m, manipath)
if errorParser != nil {
return nil, errorParser
@@ -374,7 +374,7 @@ func (dm *YAMLParser) ComposeActions(mani *ManifestYAML, manipath string) (ar []
}
-func (dm *YAMLParser) ComposeTriggers(manifest *ManifestYAML) ([]*whisk.Trigger, error) {
+func (dm *YAMLParser) ComposeTriggers(manifest *ManifestYAML, filePath string) ([]*whisk.Trigger, error) {
var errorParser error
var t1 []*whisk.Trigger = make([]*whisk.Trigger, 0)
pkg := manifest.Package
@@ -411,7 +411,7 @@ func (dm *YAMLParser) ComposeTriggers(manifest *ManifestYAML) ([]*whisk.Trigger,
var keyVal whisk.KeyValue
keyVal.Key = name
- keyVal.Value, errorParser = ResolveParameter(name, ¶m)
+ keyVal.Value, errorParser = ResolveParameter(name, ¶m, filePath)
if errorParser != nil {
return nil, errorParser
@@ -516,7 +516,7 @@ func getTypeDefaultValue(typeName string) interface{} {
return nil
}
-func ResolveParamTypeFromValue(value interface{}) (string, error) {
+func ResolveParamTypeFromValue(value interface{}, filePath string) (string, error) {
// Note: string is the default type if not specified.
var paramType string = "string"
var err error = nil
@@ -531,7 +531,9 @@ func ResolveParamTypeFromValue(value interface{}) (string, error) {
} else {
// raise an error if param is not a known type
- err = utils.NewParserErr("Parameter value is not a known type. ["+actualType+"]")
+ lines := []string{"Line Unknown"}
+ msgs := []string{"Parameter value is not a known type. ["+actualType+"]"}
+ err = utils.NewParserErr(filePath, lines, msgs)
}
} else {
@@ -544,7 +546,7 @@ func ResolveParamTypeFromValue(value interface{}) (string, error) {
// Resolve input parameter (i.e., type, value, default)
// Note: parameter values may set later (overriddNen) by an (optional) Deployment file
-func ResolveParameter(paramName string, param *Parameter) (interface{}, error) {
+func ResolveParameter(paramName string, param *Parameter, filePath string) (interface{}, error) {
var errorParser error
var tempType string
@@ -558,7 +560,7 @@ func ResolveParameter(paramName string, param *Parameter) (interface{}, error) {
if !param.multiline {
// we have a single-line parameter declaration
// We need to identify parameter Type here for later validation
- param.Type, errorParser = ResolveParamTypeFromValue(param.Value)
+ param.Type, errorParser = ResolveParamTypeFromValue(param.Value, filePath)
} else {
// we have a multi-line parameter declaration
@@ -570,11 +572,13 @@ func ResolveParameter(paramName string, param *Parameter) (interface{}, error) {
// if we also have a type at this point, verify value (and/or default) matches type, if not error
// Note: if either the value or default is in conflict with the type then this is an error
- tempType, errorParser = ResolveParamTypeFromValue(param.Value)
+ tempType, errorParser = ResolveParamTypeFromValue(param.Value, filePath)
// if we do not have a value or default, but have a type, find its default and use it for the value
if param.Type != "" && !isValidParameterType(param.Type) {
- return value, utils.NewParserErr("Invalid Type for parameter. ["+param.Type+"]")
+ lines := []string{"Line Unknown"}
+ msgs := []string{"Invalid Type for parameter. ["+param.Type+"]"}
+ return value, utils.NewParserErr(filePath, lines, msgs)
} else if param.Type == "" {
param.Type = tempType
}
diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index d1c91b4..8858f0f 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -20,73 +20,73 @@
package parsers
import (
- "fmt"
- "github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/stretchr/testify/assert"
- "io/ioutil"
- "os"
- "path/filepath"
- "reflect"
- "strconv"
- "testing"
+ "github.com/apache/incubator-openwhisk-wskdeploy/utils"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
+ "os"
+ "testing"
+ "fmt"
+ "path/filepath"
+ "reflect"
+ "strconv"
)
// 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) {
- data := `
+ data := `
package:
name: helloworld
actions:
helloNodejs:
function: actions/hello.js
runtime: nodejs:6`
- // set the zero value of struct ManifestYAML
- m := ManifestYAML{}
- // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
- // And returns an error if parsing a manifest data fails
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- if err == nil {
- // ManifestYAML.Filepath does not get set by Parsers.Unmarshal
- // as it takes manifest YAML data as a function parameter
- // instead of file name of a manifest file, therefore there is
- // no way for Unmarshal function to set ManifestYAML.Filepath field
- // (TODO) Ideally we should change this functionality so that
- // (TODO) filepath is set to the actual path of the manifest file
- expectedResult := ""
- actualResult := m.Filepath
- assert.Equal(t, expectedResult, actualResult, "Expected filepath to be an empty"+
- " string instead its set to "+actualResult+" which is invalid value")
- // package name should be "helloworld"
- expectedResult = "helloworld"
- actualResult = m.Package.Packagename
- assert.Equal(t, expectedResult, actualResult, "Expected package name "+expectedResult+" but got "+actualResult)
- // manifest should contain only one action
- expectedResult = string(1)
- actualResult = string(len(m.Package.Actions))
- assert.Equal(t, expectedResult, actualResult, "Expected 1 but got "+actualResult)
- // get the action payload from the map of actions which is stored in
- // ManifestYAML.Package.Actions with the type of map[string]Action
- actionName := "helloNodejs"
- if action, ok := m.Package.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.")
- }
- }
+ // set the zero value of struct ManifestYAML
+ m := ManifestYAML{}
+ // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
+ // And returns an error if parsing a manifest data fails
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ if err == nil {
+ // ManifestYAML.Filepath does not get set by Parsers.Unmarshal
+ // as it takes manifest YAML data as a function parameter
+ // instead of file name of a manifest file, therefore there is
+ // no way for Unmarshal function to set ManifestYAML.Filepath field
+ // (TODO) Ideally we should change this functionality so that
+ // (TODO) filepath is set to the actual path of the manifest file
+ expectedResult := ""
+ actualResult := m.Filepath
+ assert.Equal(t, expectedResult, actualResult, "Expected filepath to be an empty" +
+ " string instead its set to " + actualResult + " which is invalid value")
+ // package name should be "helloworld"
+ expectedResult = "helloworld"
+ actualResult = m.Package.Packagename
+ assert.Equal(t, expectedResult, actualResult, "Expected package name " + expectedResult + " but got " + actualResult)
+ // manifest should contain only one action
+ expectedResult = string(1)
+ actualResult = string(len(m.Package.Actions))
+ assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
+ // get the action payload from the map of actions which is stored in
+ // ManifestYAML.Package.Actions with the type of map[string]Action
+ actionName := "helloNodejs"
+ if action, ok := m.Package.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.")
+ }
+ }
}
// 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) {
- data := `
+ data := `
package:
name: helloworld
actions:
@@ -94,87 +94,87 @@ package:
function: actions/hello.jar
runtime: java
main: Hello`
- m := ManifestYAML{}
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- // nothing to test if Unmarshal returns an err
- if err == nil {
- // get an action from map of actions where key is action name and
- // value is Action struct
- actionName := "helloJava"
- if action, ok := m.Package.Actions[actionName]; ok {
- // runtime of an action should be java
- expectedResult := "java"
- actualResult := action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
- // Main field should be set to "Hello"
- expectedResult = action.Main
- actualResult = "Hello"
- assert.Equal(t, expectedResult, actualResult, "Expected action main function "+expectedResult+" but got "+actualResult)
- } else {
- t.Error("Expected action named " + actionName + " but does not exist.")
- }
- }
+ m := ManifestYAML{}
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ // nothing to test if Unmarshal returns an err
+ if err == nil {
+ // get an action from map of actions where key is action name and
+ // value is Action struct
+ actionName := "helloJava"
+ if action, ok := m.Package.Actions[actionName]; ok {
+ // runtime of an action should be java
+ expectedResult := "java"
+ actualResult := action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
+ // Main field should be set to "Hello"
+ expectedResult = action.Main
+ actualResult = "Hello"
+ assert.Equal(t, expectedResult, actualResult, "Expected action main function " + expectedResult + " but got " + actualResult)
+ } else {
+ t.Error("Expected action named " + actionName + " but does not exist.")
+ }
+ }
}
// 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) {
- data := `
+ data := `
package:
name: helloworld
actions:
helloPython:
function: actions/hello.py
runtime: python`
- m := ManifestYAML{}
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- // nothing to test if Unmarshal returns an err
- if err == nil {
- // get an action from map of actions which is defined as map[string]Action{}
- actionName := "helloPython"
- if action, ok := m.Package.Actions[actionName]; ok {
- // 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("Expected action named " + actionName + " but does not exist.")
- }
- }
+ m := ManifestYAML{}
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ // nothing to test if Unmarshal returns an err
+ if err == nil {
+ // get an action from map of actions which is defined as map[string]Action{}
+ actionName := "helloPython"
+ if action, ok := m.Package.Actions[actionName]; ok {
+ // 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("Expected action named " + actionName + " but does not exist.")
+ }
+ }
}
// 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) {
- data := `
+ data := `
package:
name: helloworld
actions:
helloSwift:
function: actions/hello.swift
runtime: swift`
- m := ManifestYAML{}
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- // nothing to test if Unmarshal returns an err
- if err == nil {
- // get an action from map of actions which is defined as map[string]Action{}
- actionName := "helloSwift"
- if action, ok := m.Package.Actions[actionName]; ok {
- // runtime of an action should be swift
- expectedResult := "swift"
- actualResult := action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
- } else {
- t.Error("Expected action named " + actionName + " but does not exist.")
- }
- }
+ m := ManifestYAML{}
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ // nothing to test if Unmarshal returns an err
+ if err == nil {
+ // get an action from map of actions which is defined as map[string]Action{}
+ actionName := "helloSwift"
+ if action, ok := m.Package.Actions[actionName]; ok {
+ // runtime of an action should be swift
+ expectedResult := "swift"
+ actualResult := action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
+ } else {
+ t.Error("Expected action named " + actionName + " but does not exist.")
+ }
+ }
}
// Test 5: validate manifest_parser:Unmarshal() method for an action with parameters
// validate that manifest_parser is able to read and parse the manifest data, specially
// validate two input parameters and their values
func TestUnmarshalForHelloWithParams(t *testing.T) {
- var data = `
+ var data = `
package:
name: helloworld
actions:
@@ -184,39 +184,39 @@ package:
inputs:
name: Amy
place: Paris`
- m := ManifestYAML{}
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- if err == nil {
- actionName := "helloWithParams"
- if action, ok := m.Package.Actions[actionName]; ok {
- expectedResult := "Amy"
- actualResult := action.Inputs["name"].Value.(string)
- assert.Equal(t, expectedResult, actualResult,
- "Expected input parameter "+expectedResult+" but got "+actualResult+"for name")
- expectedResult = "Paris"
- actualResult = action.Inputs["place"].Value.(string)
- assert.Equal(t, expectedResult, actualResult,
- "Expected input parameter "+expectedResult+" but got "+actualResult+"for place")
- }
- }
+ m := ManifestYAML{}
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ if err == nil {
+ actionName := "helloWithParams"
+ if action, ok := m.Package.Actions[actionName]; ok {
+ expectedResult := "Amy"
+ actualResult := action.Inputs["name"].Value.(string)
+ assert.Equal(t, expectedResult, actualResult,
+ "Expected input parameter " + expectedResult + " but got " + actualResult + "for name")
+ expectedResult = "Paris"
+ actualResult = action.Inputs["place"].Value.(string)
+ assert.Equal(t, expectedResult, actualResult,
+ "Expected input parameter " + expectedResult + " but got " + actualResult + "for place")
+ }
+ }
}
// 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) {
- data := `
+ data := `
actions:
helloNodejs:
function: actions/hello.js
runtime: nodejs:6
helloJava:
function: actions/hello.java`
- // set the zero value of struct ManifestYAML
- m := ManifestYAML{}
- // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
- // And returns an error if parsing a manifest data fails
- err := NewYAMLParser().Unmarshal([]byte(data), &m)
- assert.NotNil(t, err, "Expected some error from Unmarshal but got no error")
+ // set the zero value of struct ManifestYAML
+ m := ManifestYAML{}
+ // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
+ // And returns an error if parsing a manifest data fails
+ err := NewYAMLParser().Unmarshal([]byte(data), &m)
+ assert.NotNil(t, err, "Expected some error from Unmarshal but got no error")
}
/*
@@ -240,231 +240,231 @@ func TestUnmarshalForMissingPackage(t *testing.T) {
default: <default value>
*/
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, _ := NewYAMLParser().ParseManifest(manifestFile)
-
- // validate package name should be "validate"
- expectedPackageName := m.Package.Packagename
- actualPackageName := "validate"
- assert.Equal(t, expectedPackageName, actualPackageName,
- "Expected "+expectedPackageName+" but got "+actualPackageName)
-
- // validate this package contains one action
- expectedActionsCount := 1
- actualActionsCount := len(m.Package.Actions)
- assert.Equal(t, expectedActionsCount, actualActionsCount,
- "Expected "+string(expectedActionsCount)+" but got "+string(actualActionsCount))
-
- // 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.Package.Actions[actionName]; ok {
- // validate location/function of an action to be "actions/dump_params.js"
- expectedResult := "actions/dump_params.js"
- actualResult := action.Function
- assert.Equal(t, expectedResult, actualResult, "Expected action function "+expectedResult+" but got "+actualResult)
-
- // validate runtime of an action to be "nodejs:6"
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
-
- // validate the number of inputs to this action
- expectedResult = strconv.FormatInt(10, 10)
- actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // 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, "Expected "+expectedResult+" but got "+actualResult)
- case "param_int_value_only":
- expectedResult = strconv.FormatInt(123, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- 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, "Expected "+expectedResult+" but got "+actualResult)
- case "param_string_type_and_value_only":
- expectedResult = "foo"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_string_type_only":
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_integer_type_only":
- expectedResult = "integer"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_float_type_only":
- expectedResult = "float"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_string_with_default":
- expectedResult = "string"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = "bar"
- actualResult = param.Default.(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_integer_with_default":
- expectedResult = "integer"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(param.Default.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_float_with_default":
- expectedResult = "float"
- actualResult = param.Type
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
- actualResult = strconv.FormatFloat(param.Default.(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- }
- }
-
- // validate outputs
- // output payload is of type string and has a description
- if payload, ok := action.Outputs["payload"]; ok {
- p := payload.(map[interface{}]interface{})
- expectedResult = "string"
- actualResult = p["type"].(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = "parameter dump"
- actualResult = p["description"].(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- }
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
+ // read and parse manifest.yaml file
+ m, _ := NewYAMLParser().ParseManifest(manifestFile)
+
+ // validate package name should be "validate"
+ expectedPackageName := m.Package.Packagename
+ actualPackageName := "validate"
+ assert.Equal(t, expectedPackageName, actualPackageName,
+ "Expected " + expectedPackageName + " but got " + actualPackageName)
+
+ // validate this package contains one action
+ expectedActionsCount := 1
+ actualActionsCount := len(m.Package.Actions)
+ assert.Equal(t, expectedActionsCount, actualActionsCount,
+ "Expected " + string(expectedActionsCount) + " but got " + string(actualActionsCount))
+
+ // 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.Package.Actions[actionName]; ok {
+ // validate location/function of an action to be "actions/dump_params.js"
+ expectedResult := "actions/dump_params.js"
+ actualResult := action.Function
+ assert.Equal(t, expectedResult, actualResult, "Expected action function " + expectedResult + " but got " + actualResult)
+
+ // validate runtime of an action to be "nodejs:6"
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
+
+ // validate the number of inputs to this action
+ expectedResult = strconv.FormatInt(10, 10)
+ actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // 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, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_int_value_only":
+ expectedResult = strconv.FormatInt(123, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ 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, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_string_type_and_value_only":
+ expectedResult = "foo"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_string_type_only":
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_integer_type_only":
+ expectedResult = "integer"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_float_type_only":
+ expectedResult = "float"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_string_with_default":
+ expectedResult = "string"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = "bar"
+ actualResult = param.Default.(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_integer_with_default":
+ expectedResult = "integer"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(param.Default.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_float_with_default":
+ expectedResult = "float"
+ actualResult = param.Type
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(param.Default.(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ }
+ }
+
+ // validate outputs
+ // output payload is of type string and has a description
+ if payload, ok := action.Outputs["payload"]; ok {
+ p := payload.(map[interface{}]interface{})
+ expectedResult = "string"
+ actualResult = p["type"].(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = "parameter dump"
+ actualResult = p["description"].(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ }
+ }
}
// 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, _ := NewYAMLParser().ParseManifest(manifestFile)
-
- // validate package name should be "validate"
- expectedPackageName := m.Package.Packagename
- actualPackageName := "validate"
- assert.Equal(t, expectedPackageName, actualPackageName,
- "Expected "+expectedPackageName+" but got "+actualPackageName)
-
- // validate this package contains one action
- expectedActionsCount := 1
- actualActionsCount := len(m.Package.Actions)
- assert.Equal(t, expectedActionsCount, actualActionsCount,
- "Expected "+string(expectedActionsCount)+" but got "+string(actualActionsCount))
-
- actionName := "validate_singleline_params"
- if action, ok := m.Package.Actions[actionName]; ok {
- // validate location/function of an action to be "actions/dump_params.js"
- expectedResult := "actions/dump_params.js"
- actualResult := action.Function
- assert.Equal(t, expectedResult, actualResult, "Expected action function "+expectedResult+" but got "+actualResult)
-
- // validate runtime of an action to be "nodejs:6"
- expectedResult = "nodejs:6"
- actualResult = action.Runtime
- assert.Equal(t, expectedResult, actualResult, "Expected action runtime "+expectedResult+" but got "+actualResult)
-
- // validate the number of inputs to this action
- expectedResult = strconv.FormatInt(17, 10)
- actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // 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, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_integer_1":
- expectedResult = strconv.FormatInt(1, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_integer_2":
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_integer_3":
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_integer_4":
- expectedResult = strconv.FormatInt(99999, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_integer_5":
- expectedResult = strconv.FormatInt(-99999, 10)
- actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- 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, "Expected "+expectedResult+" but got "+actualResult)
- 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, "Expected "+expectedResult+" but got "+actualResult)
- 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, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_env_var_1":
- expectedResult = "$GOPATH"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- case "param_simple_invalid_env_var":
- expectedResult = "$DollarSignNotInEnv"
- actualResult = param.Value.(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- 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, "Expected empty string but got "+actualResult)
- case "param_simple_explicit_empty_2":
- actualResult = param.Value.(string)
- assert.Empty(t, actualResult, "Expected empty string but got "+actualResult)
- }
- }
-
- // validate outputs
- // output payload is of type string and has a description
- if payload, ok := action.Outputs["payload"]; ok {
- p := payload.(map[interface{}]interface{})
- expectedResult = "string"
- actualResult = p["type"].(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- expectedResult = "parameter dump"
- actualResult = p["description"].(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- }
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
+ // read and parse manifest.yaml file
+ m, _ := NewYAMLParser().ParseManifest(manifestFile)
+
+ // validate package name should be "validate"
+ expectedPackageName := m.Package.Packagename
+ actualPackageName := "validate"
+ assert.Equal(t, expectedPackageName, actualPackageName,
+ "Expected " + expectedPackageName + " but got " + actualPackageName)
+
+ // validate this package contains one action
+ expectedActionsCount := 1
+ actualActionsCount := len(m.Package.Actions)
+ assert.Equal(t, expectedActionsCount, actualActionsCount,
+ "Expected " + string(expectedActionsCount) + " but got " + string(actualActionsCount))
+
+ actionName := "validate_singleline_params"
+ if action, ok := m.Package.Actions[actionName]; ok {
+ // validate location/function of an action to be "actions/dump_params.js"
+ expectedResult := "actions/dump_params.js"
+ actualResult := action.Function
+ assert.Equal(t, expectedResult, actualResult, "Expected action function " + expectedResult + " but got " + actualResult)
+
+ // validate runtime of an action to be "nodejs:6"
+ expectedResult = "nodejs:6"
+ actualResult = action.Runtime
+ assert.Equal(t, expectedResult, actualResult, "Expected action runtime " + expectedResult + " but got " + actualResult)
+
+ // validate the number of inputs to this action
+ expectedResult = strconv.FormatInt(17, 10)
+ actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // 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, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_integer_1":
+ expectedResult = strconv.FormatInt(1, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_integer_2":
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_integer_3":
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_integer_4":
+ expectedResult = strconv.FormatInt(99999, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_integer_5":
+ expectedResult = strconv.FormatInt(-99999, 10)
+ actualResult = strconv.FormatInt(int64(param.Value.(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ 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, "Expected " + expectedResult + " but got " + actualResult)
+ 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, "Expected " + expectedResult + " but got " + actualResult)
+ 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, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_env_var_1":
+ expectedResult = "$GOPATH"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ case "param_simple_invalid_env_var":
+ expectedResult = "$DollarSignNotInEnv"
+ actualResult = param.Value.(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ 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, "Expected empty string but got " + actualResult)
+ case "param_simple_explicit_empty_2":
+ actualResult = param.Value.(string)
+ assert.Empty(t, actualResult, "Expected empty string but got " + actualResult)
+ }
+ }
+
+ // validate outputs
+ // output payload is of type string and has a description
+ if payload, ok := action.Outputs["payload"]; ok {
+ p := payload.(map[interface{}]interface{})
+ expectedResult = "string"
+ actualResult = p["type"].(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ expectedResult = "parameter dump"
+ actualResult = p["description"].(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ }
+ }
}
// 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:
@@ -477,259 +477,259 @@ func TestComposeActionsForImplicitRuntimes(t *testing.T) {
helloSwift:
function: ../tests/src/integration/helloworld/actions/hello.swift`
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtimes_")
- 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.ComposeActions(m, tmpfile.Name())
- var expectedResult string
- if err == nil {
- for i := 0; i < len(actions); i++ {
- if actions[i].Action.Name == "helloNodejs" {
- expectedResult = "nodejs:6"
- } else if actions[i].Action.Name == "helloJava" {
- expectedResult = "java"
- } else if actions[i].Action.Name == "helloPython" {
- expectedResult = "python"
- } else if actions[i].Action.Name == "helloSwift" {
- expectedResult = "swift:3"
- }
- actualResult := actions[i].Action.Exec.Kind
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- }
- }
-
- }
- tmpfile.Close()
- }
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtimes_")
+ 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.ComposeActions(m, tmpfile.Name())
+ var expectedResult string
+ if err == nil {
+ for i := 0; i < len(actions); i++ {
+ if actions[i].Action.Name == "helloNodejs" {
+ expectedResult = "nodejs:6"
+ } else if actions[i].Action.Name == "helloJava" {
+ expectedResult = "java"
+ } else if actions[i].Action.Name == "helloPython" {
+ expectedResult = "python"
+ } else if actions[i].Action.Name == "helloSwift" {
+ expectedResult = "swift:3"
+ }
+ actualResult := actions[i].Action.Exec.Kind
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ }
+ }
+
+ }
+ tmpfile.Close()
+ }
}
// Test 10: validate manifest_parser.ComposeActions() method for invalid runtimes
// when a runtime of an action is set to some garbage, manifest_parser should
// report an error for that action
func TestComposeActionsForInvalidRuntime(t *testing.T) {
- data :=
- `package:
+ data :=
+ `package:
name: helloworld
actions:
helloInvalidRuntime:
function: ../tests/src/integration/helloworld/actions/hello.js
runtime: invalid`
- dir, _ := os.Getwd()
- tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtime_")
- 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())
- _, err := p.ComposeActions(m, tmpfile.Name())
- // (TODO) uncomment the following test case after issue #307 is fixed
- // (TODO) its failing right now as we are lacking check on invalid runtime
- // assert.NotNil(t, err, "Invalid runtime, ComposeActions should report an error")
- // (TODO) remove this print statement after uncommenting above test case
- fmt.Println(err)
- }
- tmpfile.Close()
- }
+ dir, _ := os.Getwd()
+ tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtime_")
+ 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())
+ _, err := p.ComposeActions(m, tmpfile.Name())
+ // (TODO) uncomment the following test case after issue #307 is fixed
+ // (TODO) its failing right now as we are lacking check on invalid runtime
+ // assert.NotNil(t, err, "Invalid runtime, ComposeActions should report an error")
+ // (TODO) remove this print statement after uncommenting above test case
+ fmt.Println(err)
+ }
+ tmpfile.Close()
+ }
}
// Test 11: validate manfiest_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, _ := p.ParseManifest(manifestFile)
- actions, err := p.ComposeActions(m, manifestFile)
-
- if err == nil {
- // assert that the actions variable has only one action
- assert.Equal(t, 1, len(actions), "We have defined only one action but we got "+string(len(actions)))
-
- action := actions[0]
-
- // param_simple_string should value "foo"
- expectedResult := "foo"
- actualResult := action.Action.Parameters.GetValue("param_simple_string").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_integer_1 should have value 1
- expectedResult = strconv.FormatInt(1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_1").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_integer_2 should have value 0
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_2").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_integer_3 should have value -1
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_3").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_integer_4 should have value 99999
- expectedResult = strconv.FormatInt(99999, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_4").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_integer_5 should have value -99999
- expectedResult = strconv.FormatInt(-99999, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_5").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_float_1 should have value 1.1
- expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_1").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_float_2 should have value 0.0
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_2").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_float_3 should have value -1.1
- expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_3").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_env_var_1 should have value of env. variable $GOPATH
- expectedResult = os.Getenv("GOPATH")
- actualResult = action.Action.Parameters.GetValue("param_simple_env_var_1").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_invalid_env_var should have value of ""
- expectedResult = ""
- actualResult = action.Action.Parameters.GetValue("param_simple_invalid_env_var").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_simple_implied_empty should be ""
- actualResult = action.Action.Parameters.GetValue("param_simple_implied_empty").(string)
- assert.Empty(t, actualResult, "Expected empty string but got "+actualResult)
-
- // param_simple_explicit_empty_1 should be ""
- actualResult = action.Action.Parameters.GetValue("param_simple_explicit_empty_1").(string)
- assert.Empty(t, actualResult, "Expected empty string but got "+actualResult)
-
- // param_simple_explicit_empty_2 should be ""
- actualResult = action.Action.Parameters.GetValue("param_simple_explicit_empty_2").(string)
- assert.Empty(t, actualResult, "Expected empty string but got "+actualResult)
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_singleline_params.yaml"
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(manifestFile)
+ actions, err := p.ComposeActions(m, manifestFile)
+
+ if err == nil {
+ // assert that the actions variable has only one action
+ assert.Equal(t, 1, len(actions), "We have defined only one action but we got " + string(len(actions)))
+
+ action := actions[0]
+
+ // param_simple_string should value "foo"
+ expectedResult := "foo"
+ actualResult := action.Action.Parameters.GetValue("param_simple_string").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_integer_1 should have value 1
+ expectedResult = strconv.FormatInt(1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_1").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_integer_2 should have value 0
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_2").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_integer_3 should have value -1
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_3").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_integer_4 should have value 99999
+ expectedResult = strconv.FormatInt(99999, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_4").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_integer_5 should have value -99999
+ expectedResult = strconv.FormatInt(-99999, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_5").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_float_1 should have value 1.1
+ expectedResult = strconv.FormatFloat(1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_1").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_float_2 should have value 0.0
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_2").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_float_3 should have value -1.1
+ expectedResult = strconv.FormatFloat(-1.1, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_float_3").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_env_var_1 should have value of env. variable $GOPATH
+ expectedResult = os.Getenv("GOPATH")
+ actualResult = action.Action.Parameters.GetValue("param_simple_env_var_1").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_invalid_env_var should have value of ""
+ expectedResult = ""
+ actualResult = action.Action.Parameters.GetValue("param_simple_invalid_env_var").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_simple_implied_empty should be ""
+ actualResult = action.Action.Parameters.GetValue("param_simple_implied_empty").(string)
+ assert.Empty(t, actualResult, "Expected empty string but got " + actualResult)
+
+ // param_simple_explicit_empty_1 should be ""
+ actualResult = action.Action.Parameters.GetValue("param_simple_explicit_empty_1").(string)
+ assert.Empty(t, actualResult, "Expected empty string but got " + actualResult)
+
+ // param_simple_explicit_empty_2 should be ""
+ actualResult = action.Action.Parameters.GetValue("param_simple_explicit_empty_2").(string)
+ assert.Empty(t, actualResult, "Expected empty string but got " + actualResult)
+ }
}
// Test 12: validate manfiest_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, _ := p.ParseManifest(manifestFile)
- actions, err := p.ComposeActions(m, manifestFile)
-
- if err == nil {
- // assert that the actions variable has only one action
- assert.Equal(t, 1, len(actions), "We have defined only one action but we got "+string(len(actions)))
-
- action := actions[0]
-
- fmt.Println(action.Action.Parameters)
-
- // param_string_value_only should be "foo"
- expectedResult := "foo"
- actualResult := action.Action.Parameters.GetValue("param_string_value_only").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_int_value_only should be 123
- expectedResult = strconv.FormatInt(123, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_int_value_only").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_float_value_only should be 3.14
- expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_value_only").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_string_type_and_value_only should be foo
- expectedResult = "foo"
- actualResult = action.Action.Parameters.GetValue("param_string_type_and_value_only").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_string_type_only should be ""
- actualResult = action.Action.Parameters.GetValue("param_string_type_only").(string)
- assert.Empty(t, actualResult, "Expected empty string but got "+actualResult)
-
- // param_integer_type_only should be 0
- expectedResult = strconv.FormatInt(0, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_integer_type_only").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_float_type_only should be 0
- expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_type_only").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_string_with_default should be "bar"
- expectedResult = "bar"
- actualResult = action.Action.Parameters.GetValue("param_string_with_default").(string)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_integer_with_default should be -1
- expectedResult = strconv.FormatInt(-1, 10)
- actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_integer_with_default").(int)), 10)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
-
- // param_float_with_default should be 2.9
- expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
- actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_with_default").(float64), 'f', -1, 64)
- assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
- }
+ // manifest file is located under ../tests folder
+ manifestFile := "../tests/dat/manifest_validate_multiline_params.yaml"
+ // read and parse manifest.yaml file
+ p := NewYAMLParser()
+ m, _ := p.ParseManifest(manifestFile)
+ actions, err := p.ComposeActions(m, manifestFile)
+
+ if err == nil {
+ // assert that the actions variable has only one action
+ assert.Equal(t, 1, len(actions), "We have defined only one action but we got " + string(len(actions)))
+
+ action := actions[0]
+
+ fmt.Println(action.Action.Parameters)
+
+ // param_string_value_only should be "foo"
+ expectedResult := "foo"
+ actualResult := action.Action.Parameters.GetValue("param_string_value_only").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_int_value_only should be 123
+ expectedResult = strconv.FormatInt(123, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_int_value_only").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_float_value_only should be 3.14
+ expectedResult = strconv.FormatFloat(3.14, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_value_only").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_string_type_and_value_only should be foo
+ expectedResult = "foo"
+ actualResult = action.Action.Parameters.GetValue("param_string_type_and_value_only").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_string_type_only should be ""
+ actualResult = action.Action.Parameters.GetValue("param_string_type_only").(string)
+ assert.Empty(t, actualResult, "Expected empty string but got " + actualResult)
+
+ // param_integer_type_only should be 0
+ expectedResult = strconv.FormatInt(0, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_integer_type_only").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_float_type_only should be 0
+ expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_type_only").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_string_with_default should be "bar"
+ expectedResult = "bar"
+ actualResult = action.Action.Parameters.GetValue("param_string_with_default").(string)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_integer_with_default should be -1
+ expectedResult = strconv.FormatInt(-1, 10)
+ actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_integer_with_default").(int)), 10)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+ // param_float_with_default should be 2.9
+ expectedResult = strconv.FormatFloat(2.9, 'f', -1, 64)
+ actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_float_with_default").(float64), 'f', -1, 64)
+ assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+ }
}
// Test 13: validate manfiest_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.ComposeActions(m, tmpfile.Name())
- 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.ComposeActions(m, tmpfile.Name())
+ 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()
+ }
}
@@ -781,182 +781,184 @@ func TestComposeActionsForFunction(t *testing.T) {
// Test 15: validate manfiest_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.ComposeActions(m, tmpfile.Name())
- 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.ComposeActions(m, tmpfile.Name())
+ 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) {
- p := "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(p, ¶m1)
- assert.Equal(t, v, r1, "Expected value "+v+" but got "+r1.(string))
- assert.IsType(t, v, r1, "Expected parameter %v of type %T but found %T", p, v, r1)
-
- // type string - type and value only param
- param2 := Parameter{Type: y, Value: v, multiline: true}
- r2, _ := ResolveParameter(p, ¶m2)
- assert.Equal(t, v, r2, "Expected value "+v+" but got "+r2.(string))
- assert.IsType(t, v, r2, "Expected parameter %v of type %T but found %T", p, v, r2)
-
- // type string - type, no value, but default value param
- param3 := Parameter{Type: y, Default: d, multiline: true}
- r3, _ := ResolveParameter(p, ¶m3)
- assert.Equal(t, d, r3, "Expected value "+d+" but got "+r3.(string))
- assert.IsType(t, d, r3, "Expected parameter %v of type %T but found %T", p, d, r3)
-
- // 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(p, ¶m4)
- assert.Equal(t, v1, r4, "Expected value "+strconv.FormatInt(int64(v1), 10)+" but got "+strconv.FormatInt(int64(r4.(int)), 10))
- assert.IsType(t, v1, r4, "Expected parameter %v of type %T but found %T", p, v1, r4)
-
- // type invalid - type only param
- param5 := Parameter{Type: "invalid", multiline: true}
- _, err := ResolveParameter(p, ¶m5)
- assert.NotNil(t, err, "Expected error saying Invalid type for parameter")
- expectedErr := utils.NewParserErr("Invalid Type for parameter. [invalid]")
+ p := "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(p, ¶m1, "")
+ assert.Equal(t, v, r1, "Expected value " + v + " but got " + r1.(string))
+ assert.IsType(t, v, r1, "Expected parameter %v of type %T but found %T", p, v, r1)
+
+ // type string - type and value only param
+ param2 := Parameter{Type: y, Value: v, multiline: true}
+ r2, _ := ResolveParameter(p, ¶m2, "")
+ assert.Equal(t, v, r2, "Expected value " + v + " but got " + r2.(string))
+ assert.IsType(t, v, r2, "Expected parameter %v of type %T but found %T", p, v, r2)
+
+ // type string - type, no value, but default value param
+ param3 := Parameter{Type: y, Default: d, multiline: true}
+ r3, _ := ResolveParameter(p, ¶m3, "")
+ assert.Equal(t, d, r3, "Expected value " + d + " but got " + r3.(string))
+ assert.IsType(t, d, r3, "Expected parameter %v of type %T but found %T", p, d, r3)
+
+ // 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(p, ¶m4, "")
+ assert.Equal(t, v1, r4, "Expected value " + strconv.FormatInt(int64(v1), 10) + " but got " + strconv.FormatInt(int64(r4.(int)), 10))
+ assert.IsType(t, v1, r4, "Expected parameter %v of type %T but found %T", p, v1, r4)
+
+ // type invalid - type only param
+ param5 := Parameter{Type: "invalid", multiline: true}
+ _, err := ResolveParameter(p, ¶m5, "")
+ assert.NotNil(t, err, "Expected error saying Invalid type for parameter")
+ lines := []string{"Line Unknown"}
+ msgs := []string{"Invalid Type for parameter. [invalid]"}
+ expectedErr := utils.NewParserErr("", lines, msgs)
switch errorType := err.(type) {
- default:
- assert.Fail(t, "Wrong error type received: We are expecting ParserErr.")
- case *utils.ParserErr:
- assert.Equal(t, expectedErr.Message, errorType.Message,
- "Expected error " + expectedErr.Message + " but found " + errorType.Message)
+ default:
+ assert.Fail(t, "Wrong error type received: We are expecting ParserErr.")
+ case *utils.ParserErr:
+ assert.Equal(t, expectedErr.Message, errorType.Message,
+ "Expected error " + expectedErr.Message + " but found " + errorType.Message)
}
- // type none - param without type, without value, and without default value
- param6 := Parameter{multiline: true}
- r6, _ := ResolveParameter("none", ¶m6)
- assert.Empty(t, r6, "Expected default value of empty string but found "+r6.(string))
+ // type none - param without type, without value, and without default value
+ param6 := Parameter{multiline: true}
+ r6, _ := ResolveParameter("none", ¶m6, "")
+ assert.Empty(t, r6, "Expected default value of empty string but found " + r6.(string))
}
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.ComposePackage(m)
- if err == nil {
- assert.Equal(t, "helloworld", pkg.Name, "Failed to get package name")
- assert.Equal(t, "default", pkg.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.ComposePackage(m, tmpfile.Name())
+ if err == nil {
+ assert.Equal(t, "helloworld", pkg.Name, "Failed to get package name")
+ assert.Equal(t, "default", pkg.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.ComposeSequences("", m)
- 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.ComposeSequences("", m)
+ 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) {
- data :=`package:
+ data := `package:
name: helloworld
triggers:
trigger1:
@@ -968,37 +970,37 @@ func TestComposeTriggers(t *testing.T) {
inputs:
name: myname
place: myplace`
- 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())
- triggerList, err := p.ComposeTriggers(m)
- 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")
- }
- }
+ 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())
+ triggerList, err := p.ComposeTriggers(m, tmpfile.Name())
+ 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:
@@ -1007,36 +1009,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.ComposeRules(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.ComposeRules(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:
@@ -1053,64 +1055,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.ComposeApiRecords(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.ComposeApiRecords(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:
@@ -1121,42 +1123,102 @@ 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.ComposeDependencies(m, "/project_folder")
- 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")
- switch depdy_name {
- 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.ComposeDependencies(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")
+ switch depdy_name {
+ 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 TestInvalidKeyManifestYaml(t *testing.T) {
+ data := `package:
+ name: helloWorldTriggerRule
+ version: 1.0
+ invalidKey: test
+ license: Apache-2.0`
+ 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())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseManifest(tmpfile.Name())
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 4.
+ assert.Contains(t, err.Error(), "field invalidKey not found in struct parsers.Package: Line 2, its neighbour lines, or the lines on the same level")
+}
+
+func TestMappingValueManifestYaml(t *testing.T) {
+ data := `package:
+ name: helloWorldTriggerRule
+ version: 1.0
+ license: Apache-2.0
+ actions: test`
+ 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())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseManifest(tmpfile.Name())
+ assert.NotNil(t, err)
+ // go-yaml/yaml prints the wrong line number for mapping values. It should be 5.
+ assert.Contains(t, err.Error(), "mapping values are not allowed in this context: Line 4, its neighbour lines, or the lines on the same level")
+}
+
+func TestMissingRootValueManifestYaml(t *testing.T) {
+ data := `actions:
+ helloNodejs:
+ function: actions/hello.js`
+ 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())
+ }()
+ p := NewYAMLParser()
+ _, err = p.ParseManifest(tmpfile.Name())
+ assert.NotNil(t, err)
+ assert.Contains(t, err.Error(), "field actions not found in struct parsers.ManifestYAML: Line 1, its neighbour lines, or the lines on the same level")
}
diff --git a/tests/src/integration/triggerrule/manifest.yml b/tests/src/integration/triggerrule/manifest.yml
index 6776b7c..4a816b8 100644
--- a/tests/src/integration/triggerrule/manifest.yml
+++ b/tests/src/integration/triggerrule/manifest.yml
@@ -20,4 +20,3 @@ package:
#the action name and the action file greeting.js should consistent.
#currently the implementation decide the action name consistent with action file name?
action: greeting
-
diff --git a/utils/contentreader.go b/utils/contentreader.go
index bea50f2..d93d608 100644
--- a/utils/contentreader.go
+++ b/utils/contentreader.go
@@ -34,10 +34,15 @@ type URLReader struct {
func (urlReader *URLReader) ReadUrl(url string) (content []byte, err error) {
resp, err := http.Get(url)
- Check(err)
+ if err != nil {
+ return content, err
+ }
b, err := ioutil.ReadAll(resp.Body)
- defer resp.Body.Close()
- Check(err)
+ if err != nil {
+ return content, err
+ } else {
+ defer resp.Body.Close()
+ }
return b, nil
}
diff --git a/utils/fileoperations.go b/utils/fileoperations.go
index 92e7375..6d5d6ed 100644
--- a/utils/fileoperations.go
+++ b/utils/fileoperations.go
@@ -49,12 +49,16 @@ func FileExists(file string) bool {
func IsDirectory(filePath string) bool {
f, err := os.Open(filePath)
- Check(err)
-
- defer f.Close()
+ if err != nil {
+ return false
+ } else {
+ defer f.Close()
+ }
fi, err := f.Stat()
- Check(err)
+ if err != nil {
+ return false
+ }
switch mode := fi.Mode(); {
case mode.IsDir():
@@ -102,9 +106,11 @@ func CreateActionFromFile(manipath, filePath string) (*whisk.Action, error) {
dat, err = new(ContentReader).URLReader.ReadUrl(filePath)
}
+ if err != nil {
+ return action, err
+ }
code := string(dat)
pub := false
- Check(err)
action.Exec = new(whisk.Exec)
action.Exec.Code = &code
action.Exec.Kind = kind
@@ -161,26 +167,24 @@ func WriteProps(path string, props map[string]string) error {
for k, v := range props {
_, err := file.WriteString(k)
- Check(err)
+ if err != nil {
+ return err
+ }
_, err = file.WriteString("=")
- Check(err)
+ if err != nil {
+ return err
+ }
_, err = file.WriteString(v)
- Check(err)
+ if err != nil {
+ return err
+ }
_, err = file.WriteString("\n")
- Check(err)
+ if err != nil {
+ return err
+ }
}
return nil
}
-
-// Load configuration will load properties from a file
-func LoadConfiguration(propPath string) ([]string, error) {
- props, err := ReadProps(propPath)
- Check(err)
- Namespace := props["NAMESPACE"]
- Apihost := props["APIHOST"]
- Authtoken := props["AUTH"]
- return []string{Namespace, Apihost, Authtoken}, nil
-}
diff --git a/utils/gitreader.go b/utils/gitreader.go
index ca1dbce..8d04b3b 100644
--- a/utils/gitreader.go
+++ b/utils/gitreader.go
@@ -55,18 +55,26 @@ func (reader *GitReader) CloneDependency() error {
os.MkdirAll(reader.ProjectPath, os.ModePerm)
output, err := os.Create(path.Join(reader.ProjectPath, zipFileName))
- Check(err)
+ if err != nil {
+ return err
+ }
defer output.Close()
response, err := http.Get(zipFilePath)
- Check(err)
+ if err != nil {
+ return err
+ }
defer response.Body.Close()
_, err = io.Copy(output, response.Body)
- Check(err)
+ if err != nil {
+ return err
+ }
zipReader, err := zip.OpenReader(path.Join(reader.ProjectPath, zipFileName))
- Check(err)
+ if err != nil {
+ return err
+ }
u, err := url.Parse(reader.Url)
team, _ := path.Split(u.Path)
@@ -83,11 +91,15 @@ func (reader *GitReader) CloneDependency() error {
}
fileReader, err := file.Open()
- Check(err)
+ if err != nil {
+ return err
+ }
defer fileReader.Close()
targetFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
- Check(err)
+ if err != nil {
+ return err
+ }
defer targetFile.Close()
if _, err := io.Copy(targetFile, fileReader); err != nil {
diff --git a/utils/misc.go b/utils/misc.go
index 2b010a9..d23e91f 100644
--- a/utils/misc.go
+++ b/utils/misc.go
@@ -81,7 +81,9 @@ func GetURLBase(host string) (*url.URL, error) {
func GetHomeDirectory() string {
usr, err := user.Current()
- Check(err)
+ if err != nil {
+ return ""
+ }
return usr.HomeDir
}
@@ -113,11 +115,13 @@ func IsJSON(s string) (interface{}, bool) {
}
-func PrettyJSON(j interface{}) string {
+func PrettyJSON(j interface{}) (string, error) {
formatter := prettyjson.NewFormatter()
bytes, err := formatter.Marshal(j)
- Check(err)
- return string(bytes)
+ if err != nil {
+ return "", err
+ }
+ return string(bytes), nil
}
// Common utilities
@@ -248,7 +252,9 @@ func GetExec(artifact string, kind string, isDocker bool, mainEntry string) (*wh
if !isDocker || ext == ".zip" {
content, err = new(ContentReader).ReadLocal(artifact)
- Check(err)
+ if err != nil {
+ return nil, err
+ }
code = string(content)
exec.Code = &code
}
diff --git a/utils/util_test.go b/utils/util_test.go
index 12bfd22..7a00659 100644
--- a/utils/util_test.go
+++ b/utils/util_test.go
@@ -31,8 +31,7 @@ var contentReader = new(ContentReader)
var testfile = "../tests/dat/deployment.yaml"
func TestLocalReader_ReadLocal(t *testing.T) {
- b, err := contentReader.ReadLocal(testfile)
- Check(err)
+ b, _ := contentReader.ReadLocal(testfile)
if b == nil {
t.Error("get local centent failed")
}
@@ -40,8 +39,7 @@ func TestLocalReader_ReadLocal(t *testing.T) {
func TestURLReader_ReadUrl(t *testing.T) {
var exampleUrl = "http://www.baidu.com"
- b, err := contentReader.ReadUrl(exampleUrl)
- Check(err)
+ b, _ := contentReader.ReadUrl(exampleUrl)
if b == nil {
t.Error("get web content failed")
}
diff --git a/utils/wskdeployerror.go b/utils/wskdeployerror.go
index 4455c61..d6b0939 100644
--- a/utils/wskdeployerror.go
+++ b/utils/wskdeployerror.go
@@ -21,12 +21,15 @@ import (
"fmt"
"runtime"
"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+ "strings"
)
const (
INVALID_YAML_INPUT = "Invalid input of Yaml file"
INVALID_YAML_FORMAT = "Invalid input of Yaml format"
OPENWHISK_CLIENT_ERROR = "OpenWhisk Client Error"
+ UNKNOWN = "Unknown"
+ LINE = "line"
)
type TestCaseError struct {
@@ -50,7 +53,7 @@ type BaseErr struct {
}
func (e *BaseErr) Error() string {
- return fmt.Sprintf("%s [%d]: %s", e.FileName, e.LineNum, e.Message)
+ return fmt.Sprintf("%s [%d]: %s\n", e.FileName, e.LineNum, e.Message)
}
func (e *BaseErr) SetFileName(fileName string) {
@@ -86,7 +89,7 @@ func (e *InputYamlFileError) SetErrorType(errorType string) {
}
func (e *InputYamlFileError) Error() string {
- return fmt.Sprintf("%s [%d]: %s =====> %s", e.FileName, e.LineNum, e.errorType, e.Message)
+ return fmt.Sprintf("%s [%d]: %s =====> %s\n", e.FileName, e.LineNum, e.errorType, e.Message)
}
type InputYamlFormatError struct {
@@ -122,7 +125,7 @@ func NewWhiskClientError(errMessage string, code int) *WhiskClientError {
}
func (e *WhiskClientError) Error() string {
- return fmt.Sprintf("%s [%d]: %s =====> %s Error code: %d.", e.FileName, e.LineNum, e.errorType, e.Message, e.errorCode)
+ return fmt.Sprintf("%s [%d]: %s =====> %s Error code: %d.\n", e.FileName, e.LineNum, e.errorType, e.Message, e.errorCode)
}
type InvalidWskpropsError struct {
@@ -140,13 +143,33 @@ func NewInvalidWskpropsError(errMessage string) *InvalidWskpropsError {
type ParserErr struct {
BaseErr
+ YamlFile string
+ lines []string
+ msgs []string
}
-func NewParserErr(msg string) *ParserErr {
+func NewParserErr(yamlFile string, lines []string, msgs []string) *ParserErr {
_, fn, line, _ := runtime.Caller(1)
- var err = &ParserErr{}
+ var err = &ParserErr{
+ YamlFile: yamlFile,
+ lines: lines,
+ msgs: msgs,
+ }
err.SetFileName(fn)
err.SetLineNum(line)
- err.SetMessage(msg)
return err
}
+
+func (e *ParserErr) Error() string {
+ result := make([]string, len(e.msgs))
+ for index, each := range e.msgs {
+ var s string
+ if e.lines[index] == UNKNOWN {
+ s = fmt.Sprintf("%s", each)
+ } else {
+ s = fmt.Sprintf("%s: Line %s, its neighbour lines, or the lines on the same level.", each, e.lines[index])
+ }
+ result[index] = s
+ }
+ return fmt.Sprintf("%s [%d]:\n Failed to parse the yaml file %s\n =====> %s\n", e.FileName, e.LineNum, e.YamlFile, strings.Join(result, "\n "))
+}
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index ce202fa..9c48f2c 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -114,7 +114,7 @@ func wski18nResourcesDe_deAllJson() (*asset, error) {
return a, nil
}
-var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x4d\x8f\xdb\x36\x10\xbd\xeb\x57\x0c\x7c\xc9\x25\x50\xef\xb9\x05\xe9\xb6\x59\x04\xcd\x06\xd9\xb4\x45\xd0\x16\x30\x23\x8e\x2c\xd6\x14\x29\x90\x43\x2f\x5c\x41\xff\xbd\xa0\x64\x7b\x37\x1b\x91\xa2\xfc\x85\x14\xe8\x4d\x12\xf9\xde\x9b\xe1\x90\x33\x1c\xfd\x91\x01\xb4\x19\x00\xc0\x42\xf0\xc5\x2b\x58\xbc\x45\x29\xf5\xe2\xe5\xf0\x89\x0c\x53\x56\x32\x12\x5a\xf9\xb1\xd7\x0a\x5e\x7f\xb8\x85\x4a\x5b\x82\xda\x59 [...]
+var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x59\x4f\x6f\xe3\xb6\x13\xbd\xfb\x53\x0c\x72\xf1\x25\xd0\xef\x9e\x5b\xb0\xbf\x74\x37\xd8\x6e\x12\x24\x69\x17\x41\x5b\xc0\x8c\x38\xb2\x58\x53\xa4\x40\x0e\x1d\xb8\x82\xbe\x7b\x41\xc9\x76\xb2\x59\x89\xa2\xfc\xaf\x5b\xa0\x37\x4b\xe2\x7b\x6f\x86\x43\x0e\x67\xe8\xdf\x26\x00\xd5\x04\x00\xe0\x4c\xf0\xb3\x0b\x38\xfb\x84\x52\xea\xb3\xf3\xf6\x15\x19\xa6\xac\x64\x24\xb4\xf2\xdf\x2e\x15\x5c\xde\x5d\x43\xae\x2d\x41 [...]
func wski18nResourcesEn_usAllJsonBytes() ([]byte, error) {
return bindataRead(
@@ -129,7 +129,7 @@ func wski18nResourcesEn_usAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 7592, mode: os.FileMode(420), modTime: time.Unix(1504712756, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 8110, mode: os.FileMode(420), modTime: time.Unix(1505233045, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 78b97a9..5ebe74d 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -209,7 +209,9 @@
{
"id": "WARNING: The 'source' YAML key in trigger entity is deprecated. Please use 'feed' instead as described in specifications.\n",
"translation": "WARNING: The 'source' YAML key in trigger entity is deprecated. Please use 'feed' instead as described in specifications.\n"
+ },
+ {
+ "id": "Got error deleting binding package with error message: {{.err}} and error code: {{.code}}.\n",
+ "translation": "Got error deleting binding package with error message: {{.err}} and error code: {{.code}}.\n"
}
-
-
]
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].