This is an automated email from the ASF dual-hosted git repository.
houshengbo 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 b682b75 Add YAMLParserError test and underlying support for testing
(#670)
b682b75 is described below
commit b682b756189ad37a38541ada653d96b7d8c79a88
Author: Matt Rutkowski <[email protected]>
AuthorDate: Wed Dec 13 13:58:50 2017 -0600
Add YAMLParserError test and underlying support for testing (#670)
* Add unit test for YAMLParserError and its unit test.A
* Add unit test for YAMLParserError and its unit test.A
* Add unit test for YAMLParserError and its unit test.A
* Add unit test for YAMLParserError and its unit test.A
---
parsers/yamlparser.go | 17 ---------------
wskderrors/wskdeployerror.go | 44 +++++++++++++++++++++++++++++++--------
wskderrors/wskdeployerror_test.go | 36 +++++++++++++++-----------------
3 files changed, 52 insertions(+), 45 deletions(-)
diff --git a/parsers/yamlparser.go b/parsers/yamlparser.go
index f6e352c..bfd345c 100644
--- a/parsers/yamlparser.go
+++ b/parsers/yamlparser.go
@@ -27,23 +27,6 @@ func NewYAMLParser() *YAMLParser {
return &YAMLParser{}
}
-//type ParseYaml interface {
-// Unmarshal(input []byte, deploy *YAML) error
-// Marshal(manifest *YAML) (output []byte, err error)
-//
-// //Compose Package entity according to yaml content
-// ComposePackages(manifestpath string) ([]*whisk.Package, error)
-//
-// // Compose Action entities according to yaml content
-// ComposeActions(manifestpath string) ([]*whisk.Action, error)
-//
-// // Compose Trigger entities according to deployment and manifest yaml
content
-// ComposeTriggers(manifestpath string, deploymentpath string)
([]*whisk.Trigger, error)
-//
-// // Compose Rule entities according to yaml content
-// ComposeRules(manifestpath string) ([]*whisk.Rule, error)
-//}
-
type YAMLParser struct {
manifests []*YAML
lastID uint32
diff --git a/wskderrors/wskdeployerror.go b/wskderrors/wskdeployerror.go
index 2d675a3..b1935f4 100644
--- a/wskderrors/wskdeployerror.go
+++ b/wskderrors/wskdeployerror.go
@@ -30,7 +30,6 @@ const (
STR_COMMAND = "Command"
STR_ERROR_CODE = "Error code"
STR_FILE = "File"
- STR_LINE = "Line"
STR_PARAMETER = "Parameter"
STR_TYPE = "Type"
STR_EXPECTED = "Expected"
@@ -56,10 +55,21 @@ const (
* BaseError
*/
type WskDeployBaseErr struct {
- ErrorType string
- FileName string
- LineNum int
- Message string
+ ErrorType string
+ FileName string
+ LineNum int
+ Message string
+ MessageFormat string
+}
+
+func NewWskDeployBaseError(typ string, fn string, ln int, msg string)
*WskDeployBaseErr {
+ var err = &WskDeployBaseErr{
+ ErrorType: typ,
+ FileName: fn,
+ LineNum: ln,
+ }
+ err.SetMessage(msg)
+ return err
}
func (e *WskDeployBaseErr) Error() string {
@@ -78,6 +88,18 @@ func (e *WskDeployBaseErr) SetErrorType(errorType string) {
e.ErrorType = errorType
}
+func (e *WskDeployBaseErr) SetMessageFormat(fmt string) {
+ e.MessageFormat = fmt
+}
+
+func (e *WskDeployBaseErr) GetMessage()(string) {
+ return e.Message
+}
+
+func (e *WskDeployBaseErr) GetMessageFormat()(string) {
+ return e.MessageFormat
+}
+
func (e *WskDeployBaseErr) SetMessage(message interface{}) {
if message != nil{
@@ -129,7 +151,8 @@ func NewCommandError(cmd string, errorMessage string)
*CommandError {
}
err.SetErrorType(ERROR_COMMAND_FAILED)
err.SetCallerByStackFrameSkip(2)
- str := fmt.Sprintf("%s: [%s]: %s", STR_COMMAND, cmd, errorMessage)
+ err.SetMessageFormat("%s: [%s]: %s")
+ str := fmt.Sprintf(err.MessageFormat, STR_COMMAND, cmd, errorMessage)
err.SetMessage(str)
return err
}
@@ -148,7 +171,8 @@ func NewWhiskClientError(errorMessage string, code int)
*WhiskClientError {
}
err.SetErrorType(ERROR_WHISK_CLIENT_ERROR)
err.SetCallerByStackFrameSkip(2)
- str := fmt.Sprintf("%s: %d: %s", STR_ERROR_CODE, code, errorMessage)
+ err.SetMessageFormat("%s: %d: %s")
+ str := fmt.Sprintf(err.MessageFormat, STR_ERROR_CODE, code,
errorMessage)
err.SetMessage(str)
return err
}
@@ -268,7 +292,8 @@ func NewParameterTypeMismatchError(fpath string, param
string, expectedType stri
err.SetErrorType(ERROR_YAML_PARAMETER_TYPE_MISMATCH)
err.SetCallerByStackFrameSkip(2)
err.SetErrorFilePath(fpath)
- str := fmt.Sprintf("%s [%s]: %s %s: [%s], %s: [%s]",
+ err.SetMessageFormat("%s [%s]: %s %s: [%s], %s: [%s]")
+ str := fmt.Sprintf(err.MessageFormat,
STR_PARAMETER, param,
STR_TYPE,
STR_EXPECTED, expectedType,
@@ -293,7 +318,8 @@ func NewInvalidParameterTypeError(fpath string, param
string, actualType string)
err.SetErrorFilePath(fpath)
err.SetErrorType(ERROR_YAML_INVALID_PARAMETER_TYPE)
err.SetCallerByStackFrameSkip(2)
- str := fmt.Sprintf("%s [%s]: %s [%s]",
+ err.SetMessageFormat("%s [%s]: %s [%s]")
+ str := fmt.Sprintf(err.MessageFormat,
STR_PARAMETER, param,
STR_TYPE, actualType)
err.SetMessage(str)
diff --git a/wskderrors/wskdeployerror_test.go
b/wskderrors/wskdeployerror_test.go
index 8bf153e..117d973 100644
--- a/wskderrors/wskdeployerror_test.go
+++ b/wskderrors/wskdeployerror_test.go
@@ -20,6 +20,7 @@
package wskderrors
import (
+ "errors"
"testing"
"github.com/stretchr/testify/assert"
"strings"
@@ -170,23 +171,20 @@ func TestCustomErrorOutputFormat(t *testing.T) {
* YAMLParserErr
*/
- // TODO add a unit test once we re-factor error related modules into a
new package
- // TODO - use actual YAML files to generate actual errors for
comparison with expected error output
- //var TEST_LINES = []string{"40", STR_UNKNOWN, "123"}
- //var TEST_MESSAGES = []string{"did not find expected key", "did not
find expected ',' or ']'", "found duplicate %YAML directive"}
- //
- //err10 := NewYAMLParserErr(TEST_EXISTANT_MANIFEST_FILE, TEST_LINES,
TEST_MESSAGES)
- //actualResult = strings.TrimSpace(err10.Error())
- //
- //msgs := "\n==> Line [40]: did not find expected key" +
- // "\n==> Line [Unknown]: did not find expected ',' or ']'" +
- // "\n==> Line [123]: found duplicate %YAML directive"
- //
- //expectedResult = fmt.Sprintf("%s [%d]: [%s]: " + STR_FILE + ": [%s]:
%s",
- // packageName,
- // err10.LineNum,
- // ERROR_YAML_PARSER_ERROR,
- // filepath.Base(TEST_EXISTANT_MANIFEST_FILE),
- // msgs)
- //assert.Equal(t, expectedResult, actualResult)
+ // verify that nested (YAML) errors get correctly appended as indented
details to the top-level error message
+ ERR_YAML_1 := "did not find expected key"
+ ERR_YAML_2 := "did not find expected ',' or ']'"
+ ERR_YAML_3 := "found duplicate %YAML directive"
+
+ yamlErrors := fmt.Sprintf("%s\n%s\n%s", ERR_YAML_1, ERR_YAML_2,
ERR_YAML_3)
+ err10 := NewYAMLParserErr(TEST_EXISTANT_MANIFEST_FILE,
errors.New(yamlErrors))
+
+ baseErr := NewWskDeployBaseError("type", "fx", 100, "")
+ baseErr.appendDetail(ERR_YAML_1)
+ baseErr.appendDetail(ERR_YAML_2)
+ baseErr.appendDetail(ERR_YAML_3)
+ msg := baseErr.GetMessage()
+
+ assert.Equal(t, msg, err10.GetMessage())
+
}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].