You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by da...@apache.org on 2017/09/20 03:23:47 UTC

[incubator-openwhisk-wskdeploy] branch master updated: Fix typed parameters, add missing functional tests (#518)

This is an automated email from the ASF dual-hosted git repository.

daisyguo 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 89aa538  Fix typed parameters, add missing functional tests (#518)
89aa538 is described below

commit 89aa5383e7c05f976515e2d96bbee07dbae272fc
Author: Matt Rutkowski <mr...@us.ibm.com>
AuthorDate: Tue Sep 19 22:23:45 2017 -0500

    Fix typed parameters, add missing functional tests (#518)
    
    * Update functional tests with more env. vars. variations.
    
    * Update functional tests to include values that are Type names.
    
    * Update functional tests to include values that are Type names.
    
    * Update functional tests to include values that are Type names.
    
    * Update functional tests to include values that are Type names.
---
 parsers/manifest_parser.go                         | 22 +++----
 parsers/manifest_parser_test.go                    | 77 ++++++++++++++++++++--
 tests/dat/manifest_validate_singleline_params.yaml |  5 ++
 3 files changed, 89 insertions(+), 15 deletions(-)

diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index 720e336..d1665eb 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -667,17 +667,17 @@ func ResolveParameter(paramName string, param *Parameter, filePath string) (inte
 
 		// In single-line format, the param's <value> can be a "Type name" and NOT an actual value.
 		// if this is the case, we must detect it and set the value to the default for that type name.
-		//if param.Type == "string" {
-		//	// The value is a <string>; now we must test if is the name of a known Type
-		//	var tempValue = param.Value.(string)
-		//	if isValidParameterType(tempValue) {
-		//              // If the value is indeed the name of a Type, we must change BOTH its
-		//		// Type to be that type and its value to that Type's default value
-		//		// (which happens later by setting it to nil here
-		//		param.Type = param.Value.(string)
-		//		param.Value = nil
-		//	}
-		//}
+		if param.Value!=nil && param.Type == "string" {
+			// The value is a <string>; now we must test if is the name of a known Type
+			var tempValue = param.Value.(string)
+			if isValidParameterType(tempValue) {
+				// If the value is indeed the name of a Type, we must change BOTH its
+				// Type to be that type and its value to that Type's default value
+				// (which happens later by setting it to nil here
+				param.Type = param.Value.(string)
+				param.Value = nil
+			}
+		}
 
 	} else {
 		// we have a multi-line parameter declaration
diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index 0dfffcf..a2532b5 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -383,7 +383,7 @@ func TestParseManifestForSingleLineParams(t *testing.T) {
         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)
+        expectedResult = strconv.FormatInt(22, 10)
         actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
         assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
 
@@ -554,11 +554,19 @@ func TestComposeActionsForSingleLineParams(t *testing.T) {
 
         action := actions[0]
 
+        /*
+         * Simple 'string' value tests
+         */
+
         // 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)
 
+        /*
+         * Simple 'integer' value tests
+         */
+
         // 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)
@@ -584,6 +592,10 @@ func TestComposeActionsForSingleLineParams(t *testing.T) {
         actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_integer_5").(int)), 10)
         assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
 
+        /*
+         * Simple 'float' value tests
+         */
+
         // 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)
@@ -599,27 +611,84 @@ func TestComposeActionsForSingleLineParams(t *testing.T) {
         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)
 
+        /*
+         * Environment Variable / dollar ($) notation tests
+         */
+
         // 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_env_var_2 should have value of env. variable $GOPATH
+        expectedResult = os.Getenv("GOPATH")
+        actualResult = action.Action.Parameters.GetValue("param_simple_env_var_2").(string)
+        assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+        // param_simple_env_var_3 should have value of env. variable "${}"
+        expectedResult = "${}"
+        actualResult = action.Action.Parameters.GetValue("param_simple_env_var_3").(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)
 
+        /*
+         * Environment Variable concatenation tests
+         */
+
+        // param_simple_env_var_concat_1 should have value of env. variable "$GOPTH/test" empty string
+        expectedResult = os.Getenv("GOPATH") + "/test"
+        actualResult = action.Action.Parameters.GetValue("param_simple_env_var_concat_1").(string)
+        assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+        // param_simple_env_var_concat_2 should have value of env. variable "" empty string
+        // as the "/test" is treated as part of the environment var. and not concatenated.
+        expectedResult = ""
+        actualResult = action.Action.Parameters.GetValue("param_simple_env_var_concat_2").(string)
+        assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+        // param_simple_env_var_concat_3 should have value of env. variable "" empty string
+        expectedResult = "ddd.ccc." + os.Getenv("GOPATH")
+        actualResult = action.Action.Parameters.GetValue("param_simple_env_var_concat_3").(string)
+        assert.Equal(t, expectedResult, actualResult, "Expected " + expectedResult + " but got " + actualResult)
+
+        /*
+         * Empty string tests
+         */
+
         // 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)
+        assert.Empty(t, "", "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)
+        assert.Empty(t, "", "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)
+        assert.Empty(t, "", "Expected empty string but got " + actualResult)
+
+        /*
+         * Test values that contain "Type names" (e.g., "string", "integer", "float, etc.)
+         */
+
+        // param_simple_type_string should be "" when value set to "string"
+        actualResult = action.Action.Parameters.GetValue("param_simple_type_string").(string)
+        assert.Empty(t, "", "Expected empty string but got " + actualResult)
+
+        // param_simple_type_integer should be 0.0 when value set to "integer"
+        expectedResult = strconv.FormatInt(0, 10)
+        actualResult = strconv.FormatInt(int64(action.Action.Parameters.GetValue("param_simple_type_integer").(int)), 10)
+        assert.Empty(t, 0, "Expected empty string but got " + actualResult)
+
+        // param_simple_type_float should be 0 when value set to "float"
+        expectedResult = strconv.FormatFloat(0.0, 'f', -1, 64)
+        actualResult = strconv.FormatFloat(action.Action.Parameters.GetValue("param_simple_type_float").(float64), 'f', -1, 64)
+        assert.Empty(t, 0.0, "Expected empty string but got " + actualResult)
+
     }
 }
 
diff --git a/tests/dat/manifest_validate_singleline_params.yaml b/tests/dat/manifest_validate_singleline_params.yaml
index cc420b0..ff78514 100644
--- a/tests/dat/manifest_validate_singleline_params.yaml
+++ b/tests/dat/manifest_validate_singleline_params.yaml
@@ -19,7 +19,12 @@ package:
                 param_simple_float_3: -1.1
                 # simple Environment variables
                 param_simple_env_var_1: $GOPATH
+                param_simple_env_var_2: ${GOPATH}
+                param_simple_env_var_3: ${}
                 param_simple_invalid_env_var: $DollarSignNotInEnv
+                param_simple_env_var_concat_1: ${GOPATH}/test
+                param_simple_env_var_concat_2: $GOPATH/test
+                param_simple_env_var_concat_3: ddd.ccc.${GOPATH}
                 # Empty (string)
                 param_simple_implied_empty:
                 param_simple_explicit_empty_1: ''

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].