-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/test: identify anonymous functions and add tests to runtime
Signed-off-by: mikeee <[email protected]>
- Loading branch information
Showing
2 changed files
with
51 additions
and
8 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,28 +1,67 @@ | ||
package workflow | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/microsoft/durabletask-go/task" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewRuntime(t *testing.T) { | ||
t.Run("failure to create newruntime without dapr", func(t *testing.T) { | ||
wr, err := NewRuntime("localhost", "50001") | ||
require.Error(t, err) | ||
assert.Equal(t, &WorkflowRuntime{}, wr) | ||
}) | ||
} | ||
|
||
func TestWorkflowRuntime(t *testing.T) { | ||
testRuntime := WorkflowRuntime{ | ||
tasks: task.NewTaskRegistry(), | ||
client: nil, | ||
mutex: sync.Mutex{}, | ||
quit: nil, | ||
cancel: nil, | ||
} | ||
|
||
// TODO: Mock grpc conn - currently requires dapr to be available | ||
t.Run("test workflow name is correct", func(t *testing.T) { | ||
wr, err := NewRuntime("localhost", "50001") | ||
t.Run("register workflow", func(t *testing.T) { | ||
err := testRuntime.RegisterWorkflow(testWorkflow) | ||
require.NoError(t, err) | ||
err = wr.RegisterWorkflow(testOrchestrator) | ||
}) | ||
t.Run("register workflow - anonymous func", func(t *testing.T) { | ||
err := testRuntime.RegisterWorkflow(func(ctx *Context) (any, error) { | ||
return nil, nil | ||
}) | ||
require.Error(t, err) | ||
}) | ||
t.Run("register activity", func(t *testing.T) { | ||
err := testRuntime.RegisterActivity(testActivity) | ||
require.NoError(t, err) | ||
}) | ||
t.Run("register activity - anonymous func", func(t *testing.T) { | ||
err := testRuntime.RegisterActivity(func(ctx ActivityContext) (any, error) { | ||
return nil, nil | ||
}) | ||
require.Error(t, err) | ||
}) | ||
} | ||
|
||
func TestGetDecorator(t *testing.T) { | ||
name, err := getDecorator(testOrchestrator) | ||
name, err := getDecorator(testWorkflow) | ||
require.NoError(t, err) | ||
assert.Equal(t, "testOrchestrator", name) | ||
assert.Equal(t, "testWorkflow", name) | ||
} | ||
|
||
func testWorkflow(ctx *Context) (any, error) { | ||
_ = ctx | ||
return nil, nil | ||
} | ||
|
||
func testOrchestrator(ctx *Context) (any, error) { | ||
func testActivity(ctx ActivityContext) (any, error) { | ||
_ = ctx | ||
return nil, nil | ||
} |