Skip to content

Commit

Permalink
Enable mock to verify that an activity should not be called (#428)
Browse files Browse the repository at this point in the history
Added to the MockCallWrapper a way to specify that we expect Zero calls to the activity.
  • Loading branch information
Orlando Vargas authored May 5, 2021
1 parent 1eda847 commit 9449390
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/internal_workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func (s *WorkflowTestSuiteUnitTest) Test_ActivityMockFunction() {
env.AssertExpectations(s.T())
}

func (s *WorkflowTestSuiteUnitTest) Test_ActivityMockFunctionZero() {
env := s.NewTestWorkflowEnvironment()
env.OnActivity(testActivityHello, mock.Anything, "world").Never()
env.RegisterWorkflow(testWorkflowHello)
env.ExecuteWorkflow(testWorkflowHello)

s.True(env.IsWorkflowCompleted())
s.NotNil(env.GetWorkflowError())
s.Contains(env.GetWorkflowError().Error(), "unexpected call: testActivityHello(string,string)")
env.AssertExpectations(s.T())
}

func (s *WorkflowTestSuiteUnitTest) Test_ActivityByNameMockFunction() {
mockActivity := func(ctx context.Context, msg string) (string, error) {
return "mock_" + msg, nil
Expand Down
7 changes: 7 additions & 0 deletions internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ func (c *MockCallWrapper) Times(i int) *MockCallWrapper {
return c
}

// Never indicates that the mock should not be called.
func (c *MockCallWrapper) Never() *MockCallWrapper {
c.call.Maybe()
c.call.Panic(fmt.Sprintf("unexpected call: %s(%s)", c.call.Method, c.call.Arguments.String()))
return c
}

// Run sets a handler to be called before returning. It can be used when mocking a method such as unmarshalers that
// takes a pointer to a struct and sets properties in such struct.
func (c *MockCallWrapper) Run(fn func(args mock.Arguments)) *MockCallWrapper {
Expand Down

0 comments on commit 9449390

Please sign in to comment.