-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve go-sdk options and fix fn name detection (#51)
* fix: improve detection of fn name * fix: support multiple events and crons * feat: support single functions in go-sdk
- Loading branch information
1 parent
373b9f4
commit 2e87128
Showing
2 changed files
with
132 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,76 @@ | ||
package worker | ||
|
||
// import ( | ||
// "context" | ||
// "testing" | ||
// ) | ||
|
||
// // type actionInput struct { | ||
// // Message string `json:"message"` | ||
// // } | ||
|
||
// // type stepOneOutput struct { | ||
// // Message string `json:"message"` | ||
// // } | ||
|
||
// // type stepTwoOutput struct { | ||
// // Message string `json:"message"` | ||
// // } | ||
|
||
// // func TestToWorkflowJob(t *testing.T) { | ||
// // testJob := WorkflowJob{ | ||
// // Name: "test", | ||
// // Description: "test", | ||
// // Timeout: "1m", | ||
// // Steps: []WorkflowStep{ | ||
// // { | ||
// // ActionId: "test:test", | ||
// // Function: func(ctx context.Context, input *actionInput) (result *stepOneOutput, err error) { | ||
// // return nil, nil | ||
// // }, | ||
// // }, | ||
// // { | ||
// // ActionId: "test:test", | ||
// // Function: func(ctx context.Context, input *stepOneOutput) (result *stepTwoOutput, err error) { | ||
// // return nil, nil | ||
// // }, | ||
// // }, | ||
// // }, | ||
// // } | ||
|
||
// // job, err := testJob.ToWorkflowJob() | ||
|
||
// // if err != nil { | ||
// // t.Fatalf("could not convert workflow job: %v", err) | ||
// // } | ||
|
||
// // t.Fatalf("%v", job) | ||
// // } | ||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func namedFunction() {} | ||
|
||
func TestGetFnNameAnon(t *testing.T) { | ||
fn := func() {} | ||
|
||
name := getFnName(fn) | ||
|
||
if name != "TestGetFnNameAnon-func1" { | ||
t.Fatalf("expected function name to be TestGetFnNameAnon-func1, got %s", name) | ||
} | ||
|
||
name = getFnName(func() {}) | ||
|
||
if name != "TestGetFnNameAnon-func2" { | ||
t.Fatalf("expected function name to be TestGetFnNameAnon-func2, got %s", name) | ||
} | ||
|
||
name = getFnName(namedFunction) | ||
|
||
if name != "namedFunction" { | ||
t.Fatalf("expected function name to be namedFunction, got %s", name) | ||
} | ||
} | ||
|
||
type actionInput struct { | ||
Message string `json:"message"` | ||
} | ||
|
||
type stepOneOutput struct { | ||
Message string `json:"message"` | ||
} | ||
|
||
type stepTwoOutput struct { | ||
Message string `json:"message"` | ||
} | ||
|
||
func TestToWorkflowJob(t *testing.T) { | ||
testJob := WorkflowJob{ | ||
Name: "test", | ||
Description: "test", | ||
Timeout: "1m", | ||
Steps: []WorkflowStep{ | ||
{ | ||
Function: func(ctx context.Context, input *actionInput) (result *stepOneOutput, err error) { | ||
return nil, nil | ||
}, | ||
}, | ||
{ | ||
Function: func(ctx context.Context, input *stepOneOutput) (result *stepTwoOutput, err error) { | ||
return nil, nil | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
workflow := testJob.ToWorkflow("default") | ||
|
||
assert.Equal(t, "test", workflow.Name) | ||
} | ||
|
||
func TestFnToWorkflow(t *testing.T) { | ||
workflow := Fn(func(ctx context.Context, input *actionInput) (result *stepOneOutput, err error) { | ||
return nil, nil | ||
}).ToWorkflow("default") | ||
|
||
assert.Equal(t, "TestFnToWorkflow-func1", workflow.Name) | ||
} |