Skip to content

Commit

Permalink
Revert "Making Workflow and Activity registration optional when they …
Browse files Browse the repository at this point in the history
…are mocked (uber-go#1256)"

This reverts commit 2e73362.
  • Loading branch information
ketsiambaku committed Feb 29, 2024
1 parent bc2753a commit 204636e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
5 changes: 2 additions & 3 deletions internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ func (t *TestWorkflowEnvironment) OnActivity(activity interface{}, args ...inter
panic(err)
}
fnName := getActivityFunctionName(t.impl.registry, activity)
t.impl.registry.RegisterActivityWithOptions(activity, RegisterActivityOptions{DisableAlreadyRegisteredCheck: true})
call = t.Mock.On(fnName, args...)

case reflect.String:
call = t.Mock.On(activity.(string), args...)
default:
Expand Down Expand Up @@ -289,12 +289,11 @@ func (t *TestWorkflowEnvironment) OnWorkflow(workflow interface{}, args ...inter
if alias, ok := t.impl.registry.getWorkflowAlias(fnName); ok {
fnName = alias
}
t.impl.registry.RegisterWorkflowWithOptions(workflow, RegisterWorkflowOptions{DisableAlreadyRegisteredCheck: true})
call = t.Mock.On(fnName, args...)
case reflect.String:
call = t.Mock.On(workflow.(string), args...)
default:
panic("workflow must be function or string")
panic("activity must be function or string")
}

return t.wrapCall(call)
Expand Down
48 changes: 0 additions & 48 deletions internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package internal

import (
"context"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"strings"
"testing"
Expand Down Expand Up @@ -130,53 +129,6 @@ func TestWorkflowReturnNil(t *testing.T) {
require.NoError(t, err)
}

func HelloWorkflow(ctx Context, name string) (string, error) {
ctx = WithActivityOptions(ctx, ActivityOptions{
ScheduleToCloseTimeout: time.Hour,
StartToCloseTimeout: time.Hour,
ScheduleToStartTimeout: time.Hour,
})
var result string
err := ExecuteActivity(ctx, HelloActivity, name).Get(ctx, &result)
return result, err
}

func HelloActivity(ctx context.Context, name string) (string, error) {
return "Hello " + name + "!", nil
}

func TestWorkflowMockingWithoutRegistration(t *testing.T) {
testSuite := &WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
env.OnWorkflow(HelloWorkflow, mock.Anything, mock.Anything).Return(
func(ctx Context, person string) (string, error) {
return "Hello " + person + "!", nil
})
// Workflow is mocked, no activity registration required
env.ExecuteWorkflow(HelloWorkflow, "Cadence")
require.NoError(t, env.GetWorkflowError())
var result string
err := env.GetWorkflowResult(&result)
require.NoError(t, err)
require.Equal(t, "Hello Cadence!", result)
}

func TestActivityMockingWithoutRegistration(t *testing.T) {
testSuite := &WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
env.OnActivity(HelloActivity, mock.Anything, mock.Anything).Return(
func(ctx context.Context, person string) (string, error) {
return "Goodbye " + person + "!", nil
})
// Registration of activity not required
env.RegisterWorkflow(HelloWorkflow)
env.ExecuteWorkflow(HelloWorkflow, "Cadence")
require.NoError(t, env.GetWorkflowError())
var result string
err := env.GetWorkflowResult(&result)
require.NoError(t, err)
require.Equal(t, "Goodbye Cadence!", result)

type InterceptorTestSuite struct {
suite.Suite
WorkflowTestSuite
Expand Down

0 comments on commit 204636e

Please sign in to comment.