pritidesai closed pull request #800: Display error message for each missing 
wskprop value.
URL: https://github.com/apache/incubator-openwhisk-wskdeploy/pull/800
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index e9e8271b..fa541169 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 0ef55d8e..e49526ef 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -402,6 +402,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 be5fcf6c..7f60359a 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 dc45e950..f27f9916 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 e3c87c76..baa39560 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 643d8155..360c9ef9 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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to