Skip to content

Commit

Permalink
Merge pull request #118 from TIBCOSoftware/issue_116
Browse files Browse the repository at this point in the history
fix generated trigger test scaffolding
  • Loading branch information
Frank Martinez authored Aug 7, 2018
2 parents ef52c5f + 3d3c523 commit 23f8654
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions gen/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,64 +119,55 @@ func (t *MyTrigger) Stop() error {
var tplTriggerGoTestGo = `package {{.Name}}
import (
"context"
"io/ioutil"
"encoding/json"
"testing"
"github.com/TIBCOSoftware/flogo-lib/core/action"
"github.com/TIBCOSoftware/flogo-lib/core/trigger"
)
func getJsonMetadata() string{
func getJsonMetadata() string {
jsonMetadataBytes, err := ioutil.ReadFile("trigger.json")
if err != nil{
if err != nil {
panic("No Json Metadata found for trigger.json path")
}
return string(jsonMetadataBytes)
}
type TestRunner struct {
}
// Execute implements action.Runner.Execute
func (runner *TestRunner) Execute(ctx context.Context, act action.Action, inputs map[string]*data.Attribute) (results map[string]*data.Attribute, err error) {
return nil, nil
}
const testConfig string = ` + "`" + `{
"id": "mytrigger",
"settings": {
"setting": "somevalue"
},
"handlers": [
{
"actionId": "test_action",
"settings": {
"handler_setting": "somevalue"
},
"action" {
"id": "test_action"
}
}
]
}` + "`" + `
func TestInit(t *testing.T) {
func TestCreate(t *testing.T) {
// New factory
md := trigger.NewMetadata(getJsonMetadata())
f := NewFactory(md)
if f == nil {
t.Fail()
}
// New Trigger
config := trigger.Config{}
json.Unmarshal([]byte(testConfig), config)
tgr := f.New(&config)
runner := &TestRunner{}
trg := f.New(&config)
initCtx := &struct {
handlers []*trigger.Handler
}{
handlers: make([]*trigger.Handler, 0, len(config.Handlers))
if trg == nil {
t.Fail()
}
tgr.Initialize(initCtx)
}
`

0 comments on commit 23f8654

Please sign in to comment.