openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject [incubator-openwhisk-wskdeploy] branch master updated: Display error message for each missing wskprop value. (#800)
Date Wed, 14 Mar 2018 02:45:26 GMT
This is an automated email from the ASF dual-hosted git repository.

pdesai 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 715f562  Display error message for each missing wskprop value. (#800)
715f562 is described below

commit 715f5628d720c5060c2dd5b563e50f6e7900e070
Author: Matt Rutkowski <mrutkows@us.ibm.com>
AuthorDate: Tue Mar 13 21:45:24 2018 -0500

    Display error message for each missing wskprop value. (#800)
    
    * Display error message for each missing wskprop value.
    
    * Add method to append to an error detail message and use.
    
    * Add test for AUTHKEY detection by validation method.
    
    * Add test for APIHOST and NAMESPACE detection.
    
    * Cleanup new unit test.
    
    * Cleanup new unit test.
    
    * Cleanup new unit test.
---
 deployers/manifestreader.go   |  2 +-
 deployers/servicedeployer.go  |  1 +
 deployers/whiskclient.go      | 20 ++++++++++++++------
 deployers/whiskclient_test.go | 35 +++++++++++++++++++++++++++++++++++
 wskderrors/wskdeployerror.go  | 10 ++++++++++
 wskenv/environment.go         |  4 ++--
 6 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index e9e8271..fa54116 100644
--- a/deployers/manifestreader.go
+++ b/deployers/manifestreader.go
@@ -278,7 +278,7 @@ func (reader *ManifestReader) SetSequences(actions []utils.ActionRecord)
error {
 		// If the sequence action exists in actions, return error
 		_, exists := reader.serviceDeployer.Deployment.Packages[seqAction.Packagename].Actions[seqAction.Action.Name]
 		if exists == true {
-			// TODO(): i18n of error message (or create a new named error)
+			// TODO(798): i18n of error message (or create a new named error)
 			err := errors.New("Sequence action's name [" +
 				seqAction.Action.Name + "] is already used by an action.")
 			return wskderrors.NewYAMLParserErr(reader.serviceDeployer.ManifestPath, err)
diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index dfffb85..7fa8abe 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -403,6 +403,7 @@ func (deployer *ServiceDeployer) DeployDependencies() error {
 				}
 
 				if len(dependentPackages) > 1 {
+					// TODO(799) i18n
 					errMessage := "GitHub dependency " + depName + " has multiple packages in manifest file:
" +
 						strings.Join(dependentPackages, ", ") + ". " +
 						"One GitHub dependency can only be associated with single package in manifest file."
+
diff --git a/deployers/whiskclient.go b/deployers/whiskclient.go
index be5fcf6..7f60359 100644
--- a/deployers/whiskclient.go
+++ b/deployers/whiskclient.go
@@ -288,22 +288,30 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath
string,
 
 func validateClientConfig(credential PropertyValue, apiHost PropertyValue, namespace PropertyValue)
error {
 
-	// Display error message based upon which config value was missing
+	// Display error message for each config value found missing
 	if len(credential.Value) == 0 || len(apiHost.Value) == 0 || len(namespace.Value) == 0 {
-		var errmsg string
+
+		var errorMsg string = ""
 		if len(credential.Value) == 0 {
-			errmsg = wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_AUTHKEY)
+			errorMsg = wskderrors.AppendDetailToErrorMessage(
+				errorMsg, wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_AUTHKEY), 1)
 		}
 
 		if len(apiHost.Value) == 0 {
-			errmsg = wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_APIHOST)
+			errorMsg = wskderrors.AppendDetailToErrorMessage(
+				errorMsg, wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_APIHOST), 1)
+
 		}
 
 		if len(namespace.Value) == 0 {
-			errmsg = wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_NAMESPACE)
+			errorMsg = wskderrors.AppendDetailToErrorMessage(
+				errorMsg, wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_NAMESPACE), 1)
+
 		}
 
-		return wskderrors.NewWhiskClientInvalidConfigError(errmsg)
+		if len(errorMsg) > 0 {
+			return wskderrors.NewWhiskClientInvalidConfigError(errorMsg)
+		}
 	}
 
 	// Show caller what final values we used for credential, apihost and namespace
diff --git a/deployers/whiskclient_test.go b/deployers/whiskclient_test.go
index dc45e95..f27f991 100644
--- a/deployers/whiskclient_test.go
+++ b/deployers/whiskclient_test.go
@@ -22,6 +22,8 @@ package deployers
 import (
 	"github.com/apache/incubator-openwhisk-client-go/whisk"
 	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
+	"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
+	"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
 	"github.com/stretchr/testify/assert"
 	"testing"
 )
@@ -47,6 +49,11 @@ const (
 	WSKPROPS_CERT = "test_cert_file"
 )
 
+func init() {
+	// Setup "trace" flag for unit tests based upon "go test" -v flag
+	utils.Flags.Trace = wskprint.DetectGoTestVerbose()
+}
+
 func initializeFlags() {
 	utils.Flags.Auth = ""
 	utils.Flags.Namespace = ""
@@ -247,3 +254,31 @@ func TestNewWhiskConfigWithDeploymentAndManifestFile(t *testing.T) {
 	assert.Equal(t, config.Namespace, DEPLOYMENT_NAMESPACE, "Failed to get namespace from deployment
file")
 	assert.True(t, config.Insecure, "Config should set insecure to true")
 }
+
+// Test for the following error messages if corresponding config. values' validation fails
+// wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_AUTHKEY)
+// wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_APIHOST)
+// wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_NAMESPACE)
+func TestValidateClientConfig(t *testing.T) {
+
+	ASSERT_ERROR_DETECT_AUTHKEY := "Validation did not detect missing AUTHKEY"
+	ASSERT_ERROR_DETECT_APIHOST := "Validation did not detect missing APIHOST"
+	ASSERT_ERROR_DETECT_NAMESPACE := "Validation did not detect missing NAMESPACE"
+
+	// test missing values for all 3 primary keys
+	credential.Value = ""
+	apiHost.Value = ""
+	namespace.Value = ""
+	err := validateClientConfig(credential, apiHost, namespace)
+
+	if err != nil {
+		// Verify all 3 missing config. values are accounted for in the error message
+		assert.Contains(t, err.Error(), wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_AUTHKEY), ASSERT_ERROR_DETECT_AUTHKEY)
+		assert.Contains(t, err.Error(), wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_APIHOST), ASSERT_ERROR_DETECT_APIHOST)
+		assert.Contains(t, err.Error(), wski18n.T(wski18n.ID_MSG_CONFIG_MISSING_NAMESPACE), ASSERT_ERROR_DETECT_NAMESPACE)
+	} else {
+		assert.Error(t, err, ASSERT_ERROR_DETECT_AUTHKEY)
+	}
+
+	// TODO() test remainder of validateClientConfig() processing
+}
diff --git a/wskderrors/wskdeployerror.go b/wskderrors/wskdeployerror.go
index e3c87c7..baa3956 100644
--- a/wskderrors/wskdeployerror.go
+++ b/wskderrors/wskdeployerror.go
@@ -454,3 +454,13 @@ func IsCustomError(err error) bool {
 	}
 	return false
 }
+
+func AppendDetailToErrorMessage(detail string, add string, location int) string {
+
+	if len(detail) == 0 {
+		detail = "\n"
+	}
+	_, fname, lineNum, _ := runtime.Caller(location)
+	detail += fmt.Sprintf("  >> %s [%v]: %s", filepath.Base(fname), lineNum, add)
+	return detail
+}
diff --git a/wskenv/environment.go b/wskenv/environment.go
index 643d815..360c9ef 100644
--- a/wskenv/environment.go
+++ b/wskenv/environment.go
@@ -72,7 +72,7 @@ func InterpolateStringWithEnvVar(key interface{}) interface{} {
 				} else if strings.Contains(keystr, "$"+substr) {
 					thisValue = os.Getenv(substr)
 					if thisValue == "" {
-						// TODO() i18n
+						// TODO(797) i18n
 						wskprint.PrintlnOpenWhiskWarning("Missing Environment Variable " + substr + ".")
 					}
 					keystr = strings.Replace(keystr, "$"+substr, thisValue, -1)
@@ -81,7 +81,7 @@ func InterpolateStringWithEnvVar(key interface{}) interface{} {
 				} else if strings.Contains(keystr, "${"+substr+"}") {
 					thisValue = os.Getenv(substr)
 					if thisValue == "" {
-						// TODO() i18n
+						// TODO(797) i18n
 						wskprint.PrintlnOpenWhiskWarning("Missing Environment Variable " + substr + ".")
 					}
 					keystr = strings.Replace(keystr, "${"+substr+"}", thisValue, -1)

-- 
To stop receiving notification emails like this one, please contact
pdesai@apache.org.

Mime
View raw message