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

rabbah 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 57e9d49  fix language:default runtime setting (#1039)
57e9d49 is described below

commit 57e9d490d7a2b95ca79ea5b6e849ececb4a9f343
Author: TPei <[email protected]>
AuthorDate: Mon Mar 4 15:41:54 2019 +0100

    fix language:default runtime setting (#1039)
---
 parsers/manifest_parser_test.go                    |  26 ++++++++++++++++++++-
 runtimes/runtimes.go                               |   3 +++
 runtimes/runtimes_test.go                          |  15 ++++++------
 .../manifest_data_compose_runtimes_default.yaml    |  18 ++++++++++++++
 tests/src/integration/helloworld/actions/hello.zip | Bin 0 -> 404 bytes
 5 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index e97207a..e7358f8 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -498,7 +498,7 @@ func TestParseManifestForSingleLineParams(t *testing.T) {
        }
 }
 
-// Test 9: validate manifest_parser.ComposeActions() method for implicit 
runtimes
+// Test 9(1): validate manifest_parser.ComposeActions() method for implicit 
runtimes
 // when a runtime of an action is not provided, manifest_parser determines the 
runtime
 // based on the file extension of an action file
 func TestComposeActionsForImplicitRuntimes(t *testing.T) {
@@ -522,6 +522,30 @@ func TestComposeActionsForImplicitRuntimes(t *testing.T) {
        }
 }
 
+// Test 9(2): validate manifest_parser.ComposeActions() method for default 
runtimes
+// when a runtime of an action is set to default, manifest_parser determines
+// the runtime based on the default runtimes
+func TestComposeActionsForDefaultRuntimes(t *testing.T) {
+       file := "../tests/dat/manifest_data_compose_runtimes_default.yaml"
+       p, m, _ := testLoadParseManifest(t, file)
+       actions, err := p.ComposeActionsFromAllPackages(m, m.Filepath, 
whisk.KeyValue{}, map[string]PackageInputs{})
+       assert.Nil(t, err, fmt.Sprintf(TEST_ERROR_COMPOSE_ACTION_FAILURE, file))
+       var expectedResult string
+       for i := 0; i < len(actions); i++ {
+               if actions[i].Action.Name == "helloNodejs" {
+                       expectedResult = "nodejs:default"
+               } else if actions[i].Action.Name == "helloJava" {
+                       expectedResult = "java:default"
+               } else if actions[i].Action.Name == "helloPython" {
+                       expectedResult = "python:default"
+               } else if actions[i].Action.Name == "helloSwift" {
+                       expectedResult = "swift:default"
+               }
+               actualResult := actions[i].Action.Exec.Kind
+               assert.Equal(t, expectedResult, actualResult, 
TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
+       }
+}
+
 // Test 10(1): validate manifest_parser.ComposeActions() method for invalid 
runtimes
 // when the action has a source file written in unsupported runtimes, 
manifest_parser should
 // report an error for that action
diff --git a/runtimes/runtimes.go b/runtimes/runtimes.go
index d91546e..24236ee 100644
--- a/runtimes/runtimes.go
+++ b/runtimes/runtimes.go
@@ -167,6 +167,9 @@ func ConvertToMap(op OpenWhiskInfo) (rt 
map[string][]string) {
                        if !v[i].Deprecated {
                                rt[k] = append(rt[k], v[i].Kind)
                        }
+                       if v[i].Default {
+                               rt[k] = append(rt[k], strings.Split(v[i].Kind, 
":")[0]+":default")
+                       }
                }
        }
        return
diff --git a/runtimes/runtimes_test.go b/runtimes/runtimes_test.go
index 84d6665..cdca181 100644
--- a/runtimes/runtimes_test.go
+++ b/runtimes/runtimes_test.go
@@ -32,11 +32,12 @@ func TestParseOpenWhisk(t *testing.T) {
        println(converted["nodejs"])
        println(converted["python"])
        println(converted["go"])
-       assert.Equal(t, 3, len(converted["nodejs"]), "not expected length")
-       assert.Equal(t, 3, 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")
-       assert.Equal(t, 1, len(converted["ruby"]), "not expected length")
-       assert.Equal(t, 3, len(converted["swift"]), "not expected length")
-       assert.Equal(t, 1, len(converted["go"]), "not expected length")
+       //one larger than in api response because of explicit :default
+       assert.Equal(t, 4, len(converted["nodejs"]), "not expected length")
+       assert.Equal(t, 4, len(converted["php"]), "not expected length")
+       assert.Equal(t, 2, len(converted["java"]), "not expected length")
+       assert.Equal(t, 7, len(converted["python"]), "not expected length")
+       assert.Equal(t, 2, len(converted["ruby"]), "not expected length")
+       assert.Equal(t, 4, len(converted["swift"]), "not expected length")
+       assert.Equal(t, 2, len(converted["go"]), "not expected length")
 }
diff --git a/tests/dat/manifest_data_compose_runtimes_default.yaml 
b/tests/dat/manifest_data_compose_runtimes_default.yaml
new file mode 100644
index 0000000..5c642a4
--- /dev/null
+++ b/tests/dat/manifest_data_compose_runtimes_default.yaml
@@ -0,0 +1,18 @@
+# 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:
+  helloworld:
+    actions:
+      helloNodejs:
+        location: ../src/integration/helloworld/actions/hello.zip
+        runtime: nodejs:default
+      helloJava:
+        location: ../src/integration/helloworld/actions/hello.zip
+        runtime: java:default
+      helloPython:
+        location: ../src/integration/helloworld/actions/hello.zip
+        runtime: python:default
+      helloSwift:
+        location: ../src/integration/helloworld/actions/hello.zip
+        runtime: swift:default
diff --git a/tests/src/integration/helloworld/actions/hello.zip 
b/tests/src/integration/helloworld/actions/hello.zip
new file mode 100644
index 0000000..c5553e7
Binary files /dev/null and b/tests/src/integration/helloworld/actions/hello.zip 
differ

Reply via email to