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 59a6613 Add support to parse the type slice (#1010)
59a6613 is described below
commit 59a66134e91c71dc921332401b176dadefe4c362
Author: Vincent <[email protected]>
AuthorDate: Mon Nov 19 11:53:23 2018 -0500
Add support to parse the type slice (#1010)
Closes-bug: #999
---
parsers/manifest_parser_test.go | 23 ++++++++++++++++++++++
parsers/parameters.go | 7 +++++++
runtimes/runtimes_test.go | 2 +-
.../manifest_data_compose_actions_for_inputs.yaml | 14 +++++++++++++
4 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index 61f9e96..5b93a6d 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -56,6 +56,7 @@ const (
TEST_MSG_ACTION_FUNCTION_PATH_MISSING = "Action function path
missing"
TEST_MSG_INVALID_ACTION_ANNOTATION = "Action annotations
are invalid"
TEST_MSG_PACKAGE_PARAMETER_VALUE_MISMATCH = "Package parameter
value mismatched."
+ TEST_MSG_MISMATCH_ACTION_INPUT_PARAMS = "Action parameters
mismatched."
// local error messages
TEST_ERROR_MANIFEST_PARSE_FAILURE = "Manifest [%s]: Failed to
parse. Error: %s"
@@ -1338,6 +1339,28 @@ func TestParseManifestForJSONParams(t *testing.T) {
}
}
+// Test 18: validate manifest_parser.ComposeActions() method for parsing the
correct inputs to the action
+func TestComposeActionsForInputs(t *testing.T) {
+ file := "../tests/dat/manifest_data_compose_actions_for_inputs.yaml"
+ _, m, _ := testLoadParseManifest(t, file)
+ packageName := "testActionInputsInManifest"
+ actionName := "helloNodejs"
+
+ if action, ok := m.Packages[packageName].Actions[actionName]; ok {
+ // validate Inputs to this action
+ for input, param := range action.Inputs {
+ switch input {
+ case "param1":
+ assert.Equal(t, []interface{}{"v1", "v2"},
+ param.Value.([]interface{}),
TEST_MSG_MISMATCH_ACTION_INPUT_PARAMS)
+ case "param2":
+ assert.Equal(t, []interface{}{"value1",
"value2"},
+ param.Value.([]interface{}),
TEST_MSG_MISMATCH_ACTION_INPUT_PARAMS)
+ }
+ }
+ }
+}
+
func TestComposePackage(t *testing.T) {
file := "../tests/dat/manifest_data_compose_packages.yaml"
diff --git a/parsers/parameters.go b/parsers/parameters.go
index c9d9f85..25dff91 100644
--- a/parsers/parameters.go
+++ b/parsers/parameters.go
@@ -35,6 +35,7 @@ const (
FLOAT string = "float"
BOOLEAN string = "boolean"
JSON string = "json"
+ SLICE string = "slice"
)
var validParameterNameMap = map[string]string{
@@ -52,6 +53,7 @@ var validParameterNameMap = map[string]string{
"float64": FLOAT,
JSON: JSON,
"map": JSON,
+ "slice": SLICE,
}
var typeDefaultValueMap = map[string]interface{}{
@@ -347,6 +349,11 @@ func ResolveParameter(paramName string, param *Parameter,
filePath string) (inte
value, errorParser = resolveJSONParameter(filePath, paramName,
param, value)
}
+ if param.Value != nil && param.Type == "slice" {
+ value = wskenv.InterpolateStringWithEnvVar(param.Value)
+ value = utils.ConvertInterfaceValue(value)
+ }
+
// Default value to zero value for the Type
// Do NOT error/terminate as Value may be provided later by a
Deployment file.
if value == nil {
diff --git a/runtimes/runtimes_test.go b/runtimes/runtimes_test.go
index 5ea5840..2f2ade0 100644
--- a/runtimes/runtimes_test.go
+++ b/runtimes/runtimes_test.go
@@ -32,7 +32,7 @@ func TestParseOpenWhisk(t *testing.T) {
println(converted["nodejs"])
println(converted["python"])
//println(converted["go"])
- assert.Equal(t, 2, len(converted["nodejs"]), "not expected length")
+ assert.Equal(t, 3, len(converted["nodejs"]), "not expected length")
assert.Equal(t, 2, len(converted["php"]), "not expected length")
assert.Equal(t, 1, len(converted["java"]), "not expected length")
assert.Equal(t, 6, len(converted["python"]), "not expected length")
diff --git a/tests/dat/manifest_data_compose_actions_for_inputs.yaml
b/tests/dat/manifest_data_compose_actions_for_inputs.yaml
new file mode 100644
index 0000000..05fdfa9
--- /dev/null
+++ b/tests/dat/manifest_data_compose_actions_for_inputs.yaml
@@ -0,0 +1,14 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+
+packages:
+ testActionInputsInManifest:
+ actions:
+ helloNodejs:
+ function: actions/hello.js
+ inputs:
+ name: Tom
+ param1: ["v1", "v2"]
+ param2:
+ - "value1"
+ - "value2"