Skip to content

Commit

Permalink
Fixes export project with feed bug
Browse files Browse the repository at this point in the history
Added test validating export trigger with feed action
  • Loading branch information
kpavel committed Apr 28, 2019
1 parent ed5d622 commit d7bb65e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
23 changes: 16 additions & 7 deletions cmd/export.go
Expand Up @@ -216,12 +216,19 @@ func exportProject(projectName string, targetManifest string) error {
// export trigger to manifest

if feedname, isFeed := utils.IsFeedAction(&trg); isFeed {
// export feed input parameters
feedAction, _, _ := client.Actions.Get(feedname, true)
if err != nil {
return err
// check if feed name starts with namespace and workaround it
// the current problem is that client has user namespace and when feed specified with different namespace it will fail to invoke the feed action
// we need to transform the path from e.g.
// /api/v1/namespaces/kpavel@il.ibm.com_uspace/actions//whisk.system/alarms/interval?blocking=true
// in to
// /api/v1/namespaces/kpavel@il.ibm.com_uspace/actions/../../whisk.system/actions/alarms/interval?blocking=true
if strings.HasPrefix(feedname, "/") {
// /whisk.system/alarms/interval -> ../../whisk.system/actions/alarms/interval
prts := strings.SplitN(feedname, "/", 3)
feedname = "../../" + prts[1] + "/actions/" + prts[2]
}

// export feed input parameters
params := make(map[string]interface{})
params["authKey"] = client.Config.AuthToken
params["lifecycleEvent"] = "READ"
Expand All @@ -231,10 +238,12 @@ func exportProject(projectName string, targetManifest string) error {
return err
}
feedConfig := res["config"]
for key, val := range feedConfig.(map[string]interface{}) {

if i := feedAction.Parameters.FindKeyValue(key); i >= 0 {
trg.Parameters = trg.Parameters.AddOrReplace(&whisk.KeyValue{Key: key, Value: val})
if feedConfig != nil {
for key, val := range feedConfig.(map[string]interface{}) {
if key != "startDate" {
trg.Parameters = trg.Parameters.AddOrReplace(&whisk.KeyValue{Key: key, Value: val})
}
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion tests/src/integration/export/export_test.go
Expand Up @@ -155,7 +155,7 @@ func TestExportApi(t *testing.T) {
_, err = wskdeploy.ExportProject(projectName, targetApiExpManifestPath)
assert.Equal(t, nil, err, "Failed to export project.")

_, err = os.Stat(manifestApiExpPath)
_, err = os.Stat(targetApiExpManifestPath)
assert.Equal(t, nil, err, "Missing exported manifest file")

_, err = os.Stat(targetManifestFolder + "api-gateway-test/greeting.js")
Expand All @@ -171,6 +171,35 @@ func TestExportApi(t *testing.T) {
assert.Equal(t, nil, err, "Failed to undeploy the exported manifest file")
}

func TestExportTriggerFeed(t *testing.T) {
projectName := "FeedExp"
wskdeploy := common.NewWskdeploy()

defer os.RemoveAll(targetManifestFolder)

_, err := wskdeploy.ManagedDeploymentManifestAndProject(manifestFeedExpPath, projectName)
assert.Equal(t, nil, err, "Failed to deploy the FeedExp manifest file.")

_, err = wskdeploy.ExportProject(projectName, targetFeedExpManifestPath)
assert.Equal(t, nil, err, "Failed to export project with trigger feed.")

_, err = os.Stat(targetFeedExpManifestPath)
assert.Equal(t, nil, err, "Missing exported manifest file")

_, err = os.Stat(targetManifestFolder + "trigger-feed-test/greeting.js")
assert.Equal(t, nil, err, "Missing exported trigger-feed-test/greeting.js")

_, err = wskdeploy.UndeployManifestPathOnly(manifestFeedExpPath)
assert.Equal(t, nil, err, "Failed to undeploy manifest feed")

wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
_, err = wskdeploy.DeployWithCredentials(targetFeedExpManifestPath, manifestFeedExpPath, wskprops)
assert.Equal(t, nil, err, "Failed to redeploy the exported manifest file.")

_, err = wskdeploy.UndeployWithCredentials(targetFeedExpManifestPath, manifestFeedExpPath, wskprops)
assert.Equal(t, nil, err, "Failed to undeploy the exported manifest file")
}

var (
manifestLib1Path = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib1.yaml"
manifestLib2Path = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib2.yaml"
Expand All @@ -184,4 +213,7 @@ var (

manifestApiExpPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_apiexp.yaml"
targetApiExpManifestPath = targetManifestFolder + "exportedapimanifest.yaml"

manifestFeedExpPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_feed.yaml"
targetFeedExpManifestPath = targetManifestFolder + "exportedfeedmanifest.yaml"
)
15 changes: 15 additions & 0 deletions tests/src/integration/export/manifest_feed.yaml
@@ -0,0 +1,15 @@
# 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:
trigger-feed-test:
version: 1.0
license: Apache-2.0
actions:
greeting:
function: src/greeting.js
runtime: nodejs:6
triggers:
test_alarm_trigger:
feed: /whisk.system/alarms/interval
inputs:
minutes: 1

0 comments on commit d7bb65e

Please sign in to comment.