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

[incubator-openwhisk-wskdeploy] branch master updated: Adding integration test on helloworld (#432)

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

mrutkowski 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 d5f8f7d  Adding integration test on helloworld (#432)
d5f8f7d is described below

commit d5f8f7dc41f8a0db5551cc06976dcd30fbcaa8d4
Author: Priti Desai <pd...@us.ibm.com>
AuthorDate: Fri Sep 1 20:09:50 2017 -0700

    Adding integration test on helloworld (#432)
    
    * Adding integration test on helloworld
    
    * Adding newline in the end of file
---
 parsers/manifest_parser_test.go                    |  22 ++---
 parsers/yamlparser_test.go                         |  29 ------
 tests/README.md                                    |   2 +-
 tests/src/integration/helloworld/README.md         |  97 +++++++++++++++++++++
 .../integration}/helloworld/actions/Hello.java     |   3 +
 tests/src/integration/helloworld/actions/hello.jar | Bin 0 -> 1053 bytes
 .../integration}/helloworld/actions/hello.js       |   5 +-
 .../integration}/helloworld/actions/hello.py       |   0
 .../integration}/helloworld/actions/hello.swift    |  10 ++-
 tests/src/integration/helloworld/deployment.yaml   |  16 ++++
 .../src/integration/helloworld/helloworld_test.go  |  40 +++++++++
 tests/src/integration/helloworld/manifest.yaml     |  70 +++++++++++++++
 tests/usecases/helloworld/README.md                |  47 ----------
 tests/usecases/helloworld/actions/greeting.js      |  11 ---
 tests/usecases/helloworld/actions/greeting2.js     |  12 ---
 tests/usecases/helloworld/actions/hello.jar        | Bin 966 -> 0 bytes
 tests/usecases/helloworld/manifest.yaml            |  27 ------
 17 files changed, 249 insertions(+), 142 deletions(-)

diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index fb3f1c9..b83251e 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -477,14 +477,14 @@ func TestComposeActionsForImplicitRuntimes(t *testing.T) {
   name: helloworld
   actions:
     helloNodejs:
-      function: ../tests/usecases/helloworld/actions/hello.js
+      function: ../tests/src/integration/helloworld/actions/hello.js
     helloJava:
-      function: ../tests/usecases/helloworld/actions/hello.jar
+      function: ../tests/src/integration/helloworld/actions/hello.jar
       main: Hello
     helloPython:
-      function: ../tests/usecases/helloworld/actions/hello.py
+      function: ../tests/src/integration/helloworld/actions/hello.py
     helloSwift:
-      function: ../tests/usecases/helloworld/actions/hello.swift`
+      function: ../tests/src/integration/helloworld/actions/hello.swift`
 
 	dir, _ := os.Getwd()
 	tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtimes_")
@@ -530,7 +530,7 @@ func TestComposeActionsForInvalidRuntime(t *testing.T) {
    name: helloworld
    actions:
      helloInvalidRuntime:
-       function: ../tests/usecases/helloworld/actions/hello.js
+       function: ../tests/src/integration/helloworld/actions/hello.js
        runtime: invalid`
 	dir, _ := os.Getwd()
 	tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_runtime_")
@@ -712,10 +712,10 @@ func TestComposeActionsForFunction(t *testing.T) {
   name: helloworld
   actions:
     hello1:
-      function: ../tests/usecases/helloworld/actions/hello.js`
+      function: ../tests/src/integration/helloworld/actions/hello.js`
 	// (TODO) uncomment this after we add support for action file content from URL
 	// hello2:
-	//  function: https://raw.githubusercontent.com/apache/incubator-openwhisk-wskdeploy/master/tests/usecases/helloworld/manifest.yaml`
+	//  function: https://raw.githubusercontent.com/apache/incubator-openwhisk-wskdeploy/master/tests/isrc/integration/helloworld/manifest.yaml`
 	dir, _ := os.Getwd()
 	tmpfile, err := ioutil.TempFile(dir, "manifest_parser_validate_locations_")
 	if err == nil {
@@ -729,7 +729,7 @@ func TestComposeActionsForFunction(t *testing.T) {
 			if err == nil {
 				for i := 0; i < len(actions); i++ {
 					if actions[i].Action.Name == "hello1" {
-						expectedResult, _ = filepath.Abs("../tests/usecases/helloworld/actions/hello.js")
+						expectedResult, _ = filepath.Abs("../tests/src/integration/helloworld/actions/hello.js")
 						actualResult, _ = filepath.Abs(actions[i].Filepath)
 						assert.Equal(t, expectedResult, actualResult, "Expected "+expectedResult+" but got "+actualResult)
 						// (TODO) Uncomment the following condition, hello2
@@ -754,9 +754,9 @@ func TestComposeActionsForFunction(t *testing.T) {
 //  name: helloworld
 //  actions:
 //    hello1:
-//      function: ../tests/usecases/helloworld/actions/hello.js
+//      function: ../tests/src/integration/helloworld/actions/hello.js
 //    hello2:
-//      function: ../tests/usecases/helloworld/actions/hello.js
+//      function: ../tests/src/integration/helloworld/actions/hello.js
 //      limits:
 //        timeout: 60
 //        memorySize: 128
@@ -799,7 +799,7 @@ func TestComposeActionsForWebActions(t *testing.T) {
   name: helloworld
   actions:
     hello:
-      function: ../tests/usecases/helloworld/actions/hello.js
+      function: ../tests/src/integration/helloworld/actions/hello.js
       annotations:
         foo: bar
       web-export: true`
diff --git a/parsers/yamlparser_test.go b/parsers/yamlparser_test.go
index b069016..7bef6e3 100644
--- a/parsers/yamlparser_test.go
+++ b/parsers/yamlparser_test.go
@@ -25,7 +25,6 @@ import (
 	"testing"
 )
 
-var manifest_yaml = "../tests/usecases/helloworld/manifest.yaml"
 var manifestfile1 = "../tests/dat/manifest1.yaml"
 var manifestfile3 = "../tests/dat/manifest3.yaml"
 var manifestfile4 = "../tests/dat/manifest4.yaml"
@@ -36,34 +35,6 @@ var testfile2 = "../tests/dat/deploy2.yaml"
 var testfile3 = "../tests/dat/deploy3.yaml"
 var testfile4 = "../tests/dat/deploy4.yaml"
 
-func TestParseManifestYAML(t *testing.T) {
-	data, err := ioutil.ReadFile(manifest_yaml)
-	if err != nil {
-		panic(err)
-	}
-
-	var manifest ManifestYAML
-	err = NewYAMLParser().Unmarshal(data, &manifest)
-	if err != nil {
-		panic(err)
-	}
-	//get and verify package name
-	assert.Equal(t, "helloworld", manifest.Package.Packagename, "Get package name failed.")
-
-	count := 0
-	for action_name := range manifest.Package.Actions {
-		var action = manifest.Package.Actions[action_name]
-		//get and verify action location
-		//assert.Equal(t, "src/greeting.js", action.Location, "Get action location failed.")
-		//get and verify total param number
-		assert.Equal(t, 2, len(action.Inputs), "Get input param number failed.")
-		count++
-	}
-	//get and verify action count
-	assert.Equal(t, 2, count, "Get action number failed.")
-
-}
-
 func TestParseManifestYAML_trigger(t *testing.T) {
 	data, err := ioutil.ReadFile(manifestfile3)
 	if err != nil {
diff --git a/tests/README.md b/tests/README.md
index 8b7be57..e13d536 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -65,5 +65,5 @@ Different integration tests can be grouped into different packages as well, and
 | [deployers / manifestreader_test.go](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/deployers/manifestreader_test.go) | dat/manifest6.yaml | N/A | Tests ManifestReader service |
 | [utils / utils_test.go](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/utils/util_test.go) | N/A | dat/deployment.yaml| Tests ContentReader, ReadUrl |
 | [cmd / root_test.go](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/cmd/root_test.go) | N/A | N/A | Tests Cobra frameworks "Root" command (i.e., "wskdeploy") and its child commands|
-| [parsers / yamlparser_test.go](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/parsers/yamlparser_test.go) | usecases/helloworld/manifest.yaml, dat/manifest1.yaml, dat/manifest2.yaml, dat/manifest3.yaml, dat/manifest4.yaml, dat/manifest5.yaml, dat/manifest6.yaml | dat/deploy1.yaml, dat/deploy2.yaml, dat/deploy3.yaml, dat/deploy4.yaml | Tests YAML parser against various Manifest and Deployment files. |
+| [parsers / yamlparser_test.go](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/parsers/yamlparser_test.go) | dat/manifest1.yaml, dat/manifest2.yaml, dat/manifest3.yaml, dat/manifest4.yaml, dat/manifest5.yaml, dat/manifest6.yaml | dat/deploy1.yaml, dat/deploy2.yaml, dat/deploy3.yaml, dat/deploy4.yaml | Tests YAML parser against various Manifest and Deployment files. |
 <!-- | []() | <manifest> | <depl> | <desc> | -->
diff --git a/tests/src/integration/helloworld/README.md b/tests/src/integration/helloworld/README.md
new file mode 100644
index 0000000..c9d9460
--- /dev/null
+++ b/tests/src/integration/helloworld/README.md
@@ -0,0 +1,97 @@
+# Integration Test - helloworld
+
+### Package description
+
+The [manifest.yaml](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/tests/src/integration/helloworld/manifest.yaml) file defines:
+
+- a Package named `IntegrationTestHelloWorld` which contains:
+ 
+    - Four actions:
+
+        - an action named `helloNodejs`
+        - an action named `helloJava`
+        - an action named `helloPython`
+        - an action named `helloSwift`
+        
+    - A Sequence `hello-world-series` which includes all four actions.
+    
+    - A trigger `triggerHelloworld` to invoke `hello-world-series` sequence
+    
+    - A rule `ruleMappingHelloworld` to associate the sequence `hello-world-series` with trigger `triggerHelloworld` 
+
+- `helloNodejs`:
+
+    - accepts two parameters:
+        - `name` (string) (default: Amy)
+        - `place` (string) (default: Paris)
+    - returns `Hello Amy from Paris`
+
+- `helloJava`
+
+    - accepts one parameter:
+        - `name` (string) (default: Bob)
+    - returns `Hello Bob!`
+    
+- `helloPython`
+
+    - accepts one parameter:
+        - `name` (string) (default: Henry)
+    - returns `Hello Henry!`
+    
+- `helloSwift`
+
+    - accepts one parameter:
+        - `name` (string) (no default)
+    - returns `Hello stranger!`
+
+
+### How to deploy and test
+
+#### Step 1. Deploy 
+
+Deploy it using `wskdeploy`:
+
+```
+$ wskdeploy -p tests/src/integration/helloworld
+```
+
+#### Step 2. Verify
+
+```
+$ wsk package get IntegrationTestHelloWorld #lists all four actions and a sequence
+$ wsk trigger get triggerHelloworld
+$ wsk rule get ruleMappingHelloworld 
+```
+
+#### Step 3. Invoke
+
+```
+# invoke all four actions in a sequence hello-world-series
+# results in four activation IDs and polling on displays outputs from all four actions 
+$ wsk trigger fire triggerHelloworld
+Activation: helloSwift (5a0)
+[
+    "2017-09-01T17:09:51.589079299Z stdout: [\"greeting\": \"Hello stranger!\"]"
+]
+
+Activation: helloPython (219)
+[
+    "2017-09-01T17:09:51.554034831Z stdout: Hello Henry!"
+]
+
+Activation: helloJava (725)
+[
+    "2017-09-01T17:09:51.547499195Z stdout: {\"greeting\":\"Hello Bob!\"}"
+]
+
+Activation: triggerHelloworld (566)
+[]
+
+Activation: ruleMappingHelloworld (270)
+[]
+
+Activation: helloNodejs (495)
+[
+    "2017-09-01T17:09:51.459935244Z stdout: Hello, Amy from Paris"
+]
+```
diff --git a/tests/usecases/helloworld/actions/Hello.java b/tests/src/integration/helloworld/actions/Hello.java
similarity index 94%
rename from tests/usecases/helloworld/actions/Hello.java
rename to tests/src/integration/helloworld/actions/Hello.java
index 33b2396..ab9630c 100644
--- a/tests/usecases/helloworld/actions/Hello.java
+++ b/tests/src/integration/helloworld/actions/Hello.java
@@ -17,12 +17,15 @@
 
 import com.google.gson.JsonObject;
 public class Hello {
+    private JsonObject response;
+
     public static JsonObject main(JsonObject args) {
         String name = "stranger";
         if (args.has("name"))
             name = args.getAsJsonPrimitive("name").getAsString();
         JsonObject response = new JsonObject();
         response.addProperty("greeting", "Hello " + name + "!");
+        System.out.println(response);
         return response;
     }
 }
diff --git a/tests/src/integration/helloworld/actions/hello.jar b/tests/src/integration/helloworld/actions/hello.jar
new file mode 100644
index 0000000..4b4e55c
Binary files /dev/null and b/tests/src/integration/helloworld/actions/hello.jar differ
diff --git a/tests/usecases/helloworld/actions/hello.js b/tests/src/integration/helloworld/actions/hello.js
similarity index 88%
rename from tests/usecases/helloworld/actions/hello.js
rename to tests/src/integration/helloworld/actions/hello.js
index 5486e7b..25fdafb 100644
--- a/tests/usecases/helloworld/actions/hello.js
+++ b/tests/src/integration/helloworld/actions/hello.js
@@ -19,5 +19,8 @@
  * Return a simple greeting message for the whole world.
  */
 function main(params) {
-    return {payload:  'Hello, world!'};
+    msg = "Hello, " + params.name + " from " + params.place;
+    console.log(msg)
+    return { payload:  msg };
 }
+
diff --git a/tests/usecases/helloworld/actions/hello.py b/tests/src/integration/helloworld/actions/hello.py
similarity index 100%
rename from tests/usecases/helloworld/actions/hello.py
rename to tests/src/integration/helloworld/actions/hello.py
diff --git a/tests/usecases/helloworld/actions/hello.swift b/tests/src/integration/helloworld/actions/hello.swift
similarity index 84%
rename from tests/usecases/helloworld/actions/hello.swift
rename to tests/src/integration/helloworld/actions/hello.swift
index 6bf7e23..6e591f3 100644
--- a/tests/usecases/helloworld/actions/hello.swift
+++ b/tests/src/integration/helloworld/actions/hello.swift
@@ -16,10 +16,14 @@
  */
 
 func main(args: [String:Any]) -> [String:Any] {
+    var msg = ["greeting": "Hello stranger!"]
     if let name = args["name"] as? String {
-        return [ "greeting" : "Hello \(name)!" ]
-    } else {
-        return [ "greeting" : "Hello stranger!" ]
+        if !name.isEmpty {
+            msg["greeting"] = "Hello \(name)!"
+        }
     }
+    print (msg)
+    return msg
 }
 
+
diff --git a/tests/src/integration/helloworld/deployment.yaml b/tests/src/integration/helloworld/deployment.yaml
new file mode 100644
index 0000000..9d102c6
--- /dev/null
+++ b/tests/src/integration/helloworld/deployment.yaml
@@ -0,0 +1,16 @@
+application:
+  name: IntegrationTest
+  packages:
+    IntegrationTestHelloWorld:
+      actions:
+        helloNodejs:
+          inputs:
+            name: Amy
+            place: Paris
+        helloJava:
+          inputs:
+            name: Bob
+        helloPython:
+          inputs:
+            name: Henry
+        helloSwift:
diff --git a/tests/src/integration/helloworld/helloworld_test.go b/tests/src/integration/helloworld/helloworld_test.go
new file mode 100644
index 0000000..d453e66
--- /dev/null
+++ b/tests/src/integration/helloworld/helloworld_test.go
@@ -0,0 +1,40 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests
+
+import (
+	"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
+	"github.com/stretchr/testify/assert"
+	"os"
+	"testing"
+)
+
+func IntegrationTestHelloWorld(t *testing.T) {
+	wskdeploy := common.NewWskdeploy()
+	_, err := wskdeploy.Deploy(manifestPath, deploymentPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the manifest and deployment files.")
+	_, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+	assert.Equal(t, nil, err, "Failed to undeploy based on the manifest and deployment files.")
+}
+
+var (
+	manifestPath   = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/helloworld/manifest.yaml"
+	deploymentPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/helloworld/deployment.yaml"
+)
diff --git a/tests/src/integration/helloworld/manifest.yaml b/tests/src/integration/helloworld/manifest.yaml
new file mode 100644
index 0000000..b2fd76a
--- /dev/null
+++ b/tests/src/integration/helloworld/manifest.yaml
@@ -0,0 +1,70 @@
+package:
+  name: IntegrationTestHelloWorld
+  actions:
+    # helloworld action in NodeJS
+    helloNodejs:
+      function: actions/hello.js
+      runtime: nodejs:6
+      inputs:
+        name:
+          type: string
+          description: name of a person
+        place:
+          type: string
+          description: location of a person
+      outputs:
+        payload:
+          type: string
+          description: a simple greeting message, Hello World!
+    # helloworld action in Java
+    helloJava:
+      function: actions/hello.jar
+      main: Hello
+      runtime: java
+      inputs:
+        name:
+          type: string
+          description: name of a person
+      outputs:
+        payload:
+          type: string
+          description: a simple greeting message, Hello Bob!
+    # helloworld action in python
+    helloPython:
+      function: actions/hello.py
+      runtime: python
+      inputs:
+        name:
+          type: string
+          description: name of a person
+      outputs:
+        payload:
+          type: string
+          description: a simple greeting message, Hello Henry!
+    # helloworld action in swift
+    helloSwift:
+      function: actions/hello.swift
+      runtime: swift:3.1.1
+      inputs:
+        name:
+          type: string
+          description: name of a person
+      outputs:
+        payload:
+          type: string
+          description: a simple greeting message, Hello stranger!
+  sequences:
+    # sequence of helloworld in all four runtimes
+    hello-world-series:
+      actions: helloNodejs, helloJava, helloPython, helloSwift
+  triggers:
+    # trigger to activate helloworld sequence
+    triggerHelloworld:
+  rules:
+    # rule associating trigger with sequence of helloworld actions
+    ruleMappingHelloworld:
+      trigger: triggerHelloworld
+      action: hello-world-series
+
+
+
diff --git a/tests/usecases/helloworld/README.md b/tests/usecases/helloworld/README.md
deleted file mode 100644
index 7e8e21d..0000000
--- a/tests/usecases/helloworld/README.md
+++ /dev/null
@@ -1,47 +0,0 @@
-# "helloworld" test case for wskdeploy.
-
-### Package description
-
-The [manifest.yaml](https://github.com/apache/incubator-openwhisk-wskdeploy/blob/master/tests/usecases/helloworld/manifest.yaml) file defines:
-
-- a Package named "helloworld" which contains two Actions:
-    - an Action named "hello"
-    - an Action named "helloworld"
-    - Two optional triggers "trigger1" and "trigger2"
-
-Both the "hello" and "helloworld" Actions accept the same two parameters:
-    - "name" (string)
-    - "place" (string)
-
-The "hello" Action has the following defaults for these properties:
-    - name: Paul
-    - place Boston
-
-The "helloworld" Action has the following defaults for these properties:
-    - name: Bernie
-    - place Vermont
-
-and will return a greeting message:
-
-```
-"Hello, <name> from <place>!"
-```
-
-### How to deploy and test
-
-Step 1. Deploy the package.
-
-Deploy it using the  ```wskdeploy``` command as follows using the manifest.yaml file found in the "path" indicated on the '-p' command line option:
-```
-$ wskdeploy -p tests/usecases/helloworld
-```
-
-Step 2. Verify the actions were created.
-```
-$ wsk action list
-```
-
-Step 3. Invoke the action.
-```
-$ wsk action invoke --blocking --result helloworld/hello --param name Bernie --param place Vermont
-```
diff --git a/tests/usecases/helloworld/actions/greeting.js b/tests/usecases/helloworld/actions/greeting.js
deleted file mode 100644
index eaa6834..0000000
--- a/tests/usecases/helloworld/actions/greeting.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * Return a simple greeting message for someone.
- *
- * @param name A person's name.
- * @param place Where the person is from.
- */
-function main(params) {
-    var name = params.name || params.payload || 'stranger';
-    var place = params.place || 'somewhere';
-    return {payload:  'Hello, ' + name + ' from ' + place + '!'};
-}
diff --git a/tests/usecases/helloworld/actions/greeting2.js b/tests/usecases/helloworld/actions/greeting2.js
deleted file mode 100644
index 674aaaf..0000000
--- a/tests/usecases/helloworld/actions/greeting2.js
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * Return a simple greeting message for someone.
- *
- * @param name A person's name.
- * @param place Where the person is from.
- */
-function main(params) {
-    var name = params.name || params.payload || 'stranger';
-    var place = params.place || 'somewhere';
-    console.log('Hello, ' + name + ' from ' + place + '!')
-    return {payload:  'Hello, ' + name + ' from ' + place + '!'};
-}
diff --git a/tests/usecases/helloworld/actions/hello.jar b/tests/usecases/helloworld/actions/hello.jar
deleted file mode 100644
index b05753f..0000000
Binary files a/tests/usecases/helloworld/actions/hello.jar and /dev/null differ
diff --git a/tests/usecases/helloworld/manifest.yaml b/tests/usecases/helloworld/manifest.yaml
deleted file mode 100644
index ffcd9c1..0000000
--- a/tests/usecases/helloworld/manifest.yaml
+++ /dev/null
@@ -1,27 +0,0 @@
-package:
-  name: helloworld
-  version: 1.0
-  license: Apache-2.0
-  actions:
-    hello:
-      version: 2.0
-      function: actions/greeting.js
-      runtime: nodejs:6
-      inputs:
-        name: Paul
-        place: Boston
-    helloworld:
-      version: 1.0
-      function: actions/greeting2.js
-      runtime: nodejs:6
-      inputs:
-        name: Bernie
-        place: Vermont
-  triggers:
-    trigger1:
-      name: trigger1
-    trigger2:
-      name: trigger2
-
-
-

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