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/27 02:14:59 UTC
[incubator-openwhisk-wskdeploy] branch master updated: Add
integration test for inputs and annotation bindings (#552)
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 4add0dc Add integration test for inputs and annotation bindings (#552)
4add0dc is described below
commit 4add0dcebf77b3b2de2ca9ec645895c0f125dd06
Author: Ying Chun Guo <gu...@cn.ibm.com>
AuthorDate: Wed Sep 27 10:14:57 2017 +0800
Add integration test for inputs and annotation bindings (#552)
---
tests/src/integration/common/wskdeploy.go | 114 +++++++++++++-------
.../actions/helloworld.js | 11 ++
.../deployment.yaml | 27 +++++
.../manifest.yaml | 27 +++++
.../validate-bind-inputs-anno_test.go | 115 +++++++++++++++++++++
5 files changed, 258 insertions(+), 36 deletions(-)
diff --git a/tests/src/integration/common/wskdeploy.go b/tests/src/integration/common/wskdeploy.go
index 098bd75..b142789 100644
--- a/tests/src/integration/common/wskdeploy.go
+++ b/tests/src/integration/common/wskdeploy.go
@@ -19,22 +19,25 @@ package common
import (
"bytes"
+ "errors"
"fmt"
+ "github.com/apache/incubator-openwhisk-client-go/whisk"
"github.com/apache/incubator-openwhisk-wskdeploy/utils"
- "github.com/apache/incubator-openwhisk-client-go/whisk"
+ "github.com/apache/incubator-openwhisk-wskdeploy/deployers"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
"os"
"os/exec"
"strings"
- "errors"
+ "path/filepath"
+ "path"
)
const (
- cmd = "wskdeploy"
- BLUEMIX_APIHOST = "BLUEMIX_APIHOST"
- BLUEMIX_NAMESPACE = "BLUEMIX_NAMESPACE"
- BLUEMIX_AUTH = "BLUEMIX_AUTH"
+ cmd = "wskdeploy"
+ BLUEMIX_APIHOST = "BLUEMIX_APIHOST"
+ BLUEMIX_NAMESPACE = "BLUEMIX_NAMESPACE"
+ BLUEMIX_AUTH = "BLUEMIX_AUTH"
)
type Wskdeploy struct {
@@ -47,38 +50,37 @@ func NewWskdeploy() *Wskdeploy {
}
func GetWskpropsFromEnvVars(apiHost string, namespace string, authKey string) *whisk.Wskprops {
- return GetWskpropsFromValues(os.Getenv(apiHost), os.Getenv(namespace), os.Getenv(authKey), "v1")
+ return GetWskpropsFromValues(os.Getenv(apiHost), os.Getenv(namespace), os.Getenv(authKey), "v1")
}
func GetWskpropsFromValues(apiHost string, namespace string, authKey string, version string) *whisk.Wskprops {
- dep := whisk.Wskprops {
- APIHost: apiHost,
- AuthKey: authKey,
- Namespace: namespace,
- AuthAPIGWKey: "",
- APIGWSpaceSuid: "",
- Apiversion: version,
- Key: "",
- Cert: "",
- Source: "",
- }
- return &dep
+ dep := whisk.Wskprops{
+ APIHost: apiHost,
+ AuthKey: authKey,
+ Namespace: namespace,
+ AuthAPIGWKey: "",
+ APIGWSpaceSuid: "",
+ Apiversion: version,
+ Key: "",
+ Cert: "",
+ Source: "",
+ }
+ return &dep
}
func ValidateWskprops(wskprops *whisk.Wskprops) error {
- if len(wskprops.APIHost) == 0 {
- return errors.New("Missing APIHost for wskprops.")
- }
- if len(wskprops.Namespace) == 0 {
- return errors.New("Missing Namespace for wskprops.")
- }
- if len(wskprops.AuthKey) == 0 {
- return errors.New("Missing AuthKey for wskprops.")
- }
- return nil
+ if len(wskprops.APIHost) == 0 {
+ return errors.New("Missing APIHost for wskprops.")
+ }
+ if len(wskprops.Namespace) == 0 {
+ return errors.New("Missing Namespace for wskprops.")
+ }
+ if len(wskprops.AuthKey) == 0 {
+ return errors.New("Missing AuthKey for wskprops.")
+ }
+ return nil
}
-
func NewWskWithPath(path string) *Wskdeploy {
var dep Wskdeploy
dep.Path = cmd
@@ -121,8 +123,8 @@ func (wskdeploy *Wskdeploy) RunCommand(s ...string) (string, error) {
if len(errb.String()) > 0 {
returnError = utils.NewTestCaseError(errb.String())
} else {
- returnError = err
- }
+ returnError = err
+ }
}
printOutput(outb.String())
if returnError != nil {
@@ -136,8 +138,8 @@ func (wskdeploy *Wskdeploy) Deploy(manifestPath string, deploymentPath string) (
}
func (wskdeploy *Wskdeploy) DeployWithCredentials(manifestPath string, deploymentPath string, wskprops *whisk.Wskprops) (string, error) {
- return wskdeploy.RunCommand("-m", manifestPath, "-d", deploymentPath, "--auth", wskprops.AuthKey,
- "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
+ return wskdeploy.RunCommand("-m", manifestPath, "-d", deploymentPath, "--auth", wskprops.AuthKey,
+ "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
}
func (wskdeploy *Wskdeploy) Undeploy(manifestPath string, deploymentPath string) (string, error) {
@@ -145,8 +147,8 @@ func (wskdeploy *Wskdeploy) Undeploy(manifestPath string, deploymentPath string)
}
func (wskdeploy *Wskdeploy) UndeployWithCredentials(manifestPath string, deploymentPath string, wskprops *whisk.Wskprops) (string, error) {
- return wskdeploy.RunCommand("undeploy", "-m", manifestPath, "-d", deploymentPath, "--auth", wskprops.AuthKey,
- "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
+ return wskdeploy.RunCommand("undeploy", "-m", manifestPath, "-d", deploymentPath, "--auth", wskprops.AuthKey,
+ "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
}
func (wskdeploy *Wskdeploy) DeployProjectPathOnly(projectPath string) (string, error) {
@@ -164,5 +166,45 @@ func (wskdeploy *Wskdeploy) DeployManifestPathOnly(manifestpath string) (string,
func (wskdeploy *Wskdeploy) UndeployManifestPathOnly(manifestpath string) (string, error) {
return wskdeploy.RunCommand("undeploy", "-m", manifestpath)
+}
+// This method is only for testing
+// This method will mock a construction of deployment plan, creating all the memory objects
+// This method CANNOT be used for real deployment!
+// Param manifestPath & deploymentPath MUST be the absolute path.
+func (wskdeploy *Wskdeploy) GetDeploymentObjects(manifestPath string, deploymentPath string) (*deployers.DeploymentApplication, error) {
+ //create ServiceDeployer and set default values
+ deployer := deployers.NewServiceDeployer()
+ deployer.ProjectPath = filepath.Dir(manifestPath)
+ deployer.ManifestPath = manifestPath
+ deployer.DeploymentPath = deploymentPath
+ deployer.IsDefault = false
+ deployer.DependencyMaster = make(map[string]utils.DependencyRecord)
+
+ //create client config with namespace, apihost, authkey and etc.
+ //these values might be mock values because it's only for testing
+ userHome := utils.GetHomeDirectory()
+ defaultPath := path.Join(userHome, whisk.DEFAULT_LOCAL_CONFIG)
+ clientConfig, err := deployers.NewWhiskConfig(defaultPath, deploymentPath, manifestPath, false)
+ if err != nil {
+ return nil, err
+ }
+ deployer.ClientConfig = clientConfig
+
+ //setSupportedRuntimes(apiHost string)
+ //only for testing, mock values
+ op, err := utils.ParseOpenWhisk(clientConfig.Host)
+ if err == nil {
+ utils.Rts = utils.ConvertToMap(op)
+ } else {
+ utils.Rts = utils.DefaultRts
+ }
+
+ //invokce ConstructDeploymentPlan to create the in memory objects for deployment
+ err = deployer.ConstructDeploymentPlan()
+ if err != nil {
+ return nil,err
+ }
+ //return the deployment objects
+ return deployer.Deployment, nil
}
diff --git a/tests/src/integration/validate-binding-inputs-annotations/actions/helloworld.js b/tests/src/integration/validate-binding-inputs-annotations/actions/helloworld.js
new file mode 100644
index 0000000..eaa6834
--- /dev/null
+++ b/tests/src/integration/validate-binding-inputs-annotations/actions/helloworld.js
@@ -0,0 +1,11 @@
+/**
+ * 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/src/integration/validate-binding-inputs-annotations/deployment.yaml b/tests/src/integration/validate-binding-inputs-annotations/deployment.yaml
new file mode 100644
index 0000000..81d1988
--- /dev/null
+++ b/tests/src/integration/validate-binding-inputs-annotations/deployment.yaml
@@ -0,0 +1,27 @@
+application:
+ name: BindingTest
+ packages:
+ packagebinding:
+ inputs:
+ name: daisy
+ city: Beijing
+ annotations:
+ tag: hello
+ aaa: this is an annotation
+ actions:
+ helloworld:
+ inputs:
+ name: Amy
+ place: Paris
+ annotations:
+ tag: hello
+ aaa: this is an annotation
+ triggers:
+ dbtrigger:
+ inputs:
+ dbname: cats
+ docid: 1234567
+ annotations:
+ tag: hello
+ aaa: this is an annotation
+
diff --git a/tests/src/integration/validate-binding-inputs-annotations/manifest.yaml b/tests/src/integration/validate-binding-inputs-annotations/manifest.yaml
new file mode 100644
index 0000000..5ecc86f
--- /dev/null
+++ b/tests/src/integration/validate-binding-inputs-annotations/manifest.yaml
@@ -0,0 +1,27 @@
+packages:
+ packagebinding:
+ actions:
+ helloworld:
+ function: actions/helloworld.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!
+ triggers:
+ dbtrigger:
+ inputs:
+ dbname:
+ type: string
+ description: name of a database
+ docid:
+ type: string
+ description: doc ID
+
diff --git a/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go b/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go
new file mode 100644
index 0000000..40184fd
--- /dev/null
+++ b/tests/src/integration/validate-binding-inputs-annotations/validate-bind-inputs-anno_test.go
@@ -0,0 +1,115 @@
+// +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 TestBindingInputsAnnotations(t *testing.T) {
+ wskdeploy := common.NewWskdeploy()
+ // verify the inputs & annotations are set
+ deploymentObjects, err := wskdeploy.GetDeploymentObjects(manifestPath, deploymentPath)
+ assert.NoError(t, err, "Failed to get deployment object.")
+
+ // verify the inputs & annotations of package
+ pkgobj := deploymentObjects.Packages["packagebinding"]
+ wskpkg := pkgobj.Package
+ for _, param := range wskpkg.Parameters {
+ switch param.Key {
+ case "name":
+ assert.Equal(t, "daisy", param.Value, "Failed to get package inputs")
+ case "city":
+ assert.Equal(t, "Beijing", param.Value, "Failed to get package inputs")
+ default:
+ assert.Fail(t, "Failed to get package inputs key")
+ }
+ }
+ for _, annos := range wskpkg.Annotations {
+ switch annos.Key {
+ case "tag":
+ assert.Equal(t, "hello", annos.Value, "Failed to get package annotations")
+ case "aaa":
+ assert.Equal(t, "this is an annotation", annos.Value, "Failed to get package annotations")
+ default:
+ assert.Fail(t, "Failed to get package annotation key")
+ }
+ }
+
+ // verify the inputs & annotations of action
+ wskaction := pkgobj.Actions["helloworld"].Action
+ for _, param := range wskaction.Parameters {
+ switch param.Key {
+ case "name":
+ assert.Equal(t, "Amy", param.Value, "Failed to get action inputs")
+ case "place":
+ assert.Equal(t, "Paris", param.Value, "Failed to get action inputs")
+ default:
+ assert.Fail(t, "Failed to get action inputs key")
+ }
+ }
+ for _, annos := range wskaction.Annotations {
+ switch annos.Key {
+ case "tag":
+ assert.Equal(t, "hello", annos.Value, "Failed to get action annotations")
+ case "aaa":
+ assert.Equal(t, "this is an annotation", annos.Value, "Failed to get action annotations")
+ default:
+ assert.Fail(t, "Failed to get action annotation key")
+ }
+ }
+
+ // verify the inputs & annotations of trigger
+ wsktrigger := deploymentObjects.Triggers["dbtrigger"]
+ for _, param := range wsktrigger.Parameters {
+ switch param.Key {
+ case "dbname":
+ assert.Equal(t, "cats", param.Value, "Failed to get trigger inputs")
+ case "docid":
+ assert.Equal(t, 1234567, param.Value, "Failed to get trigger inputs")
+ default:
+ assert.Fail(t, "Failed to get trigger inputs key")
+ }
+ }
+ for _, annos := range wsktrigger.Annotations {
+ switch annos.Key {
+ case "tag":
+ assert.Equal(t, "hello", annos.Value, "Failed to get trigger annotations")
+ case "aaa":
+ assert.Equal(t, "this is an annotation", annos.Value, "Failed to get trigger annotations")
+ default:
+ assert.Fail(t, "Failed to get annotation key")
+ }
+ }
+
+ // testing deploy and undeploy
+ _, err = wskdeploy.Deploy(manifestPath, deploymentPath)
+ assert.NoError(t, err, "Failed to deploy based on the manifest and deployment files.")
+ _, err = wskdeploy.Undeploy(manifestPath, deploymentPath)
+ assert.NoError(t, 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/validate-binding-inputs-annotations/manifest.yaml"
+ deploymentPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/validate-binding-inputs-annotations/deployment.yaml"
+)
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].