Skip to content

Commit 1f35a5b

Browse files
authoredDec 6, 2024··
mock: in order mock calls using new testify mock.InOrder() method (#1743)
mock: in order mock calls
1 parent 01b52a2 commit 1f35a5b

File tree

18 files changed

+57
-24
lines changed

18 files changed

+57
-24
lines changed
 

‎contrib/datadog/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.21.1
66

77
require (
8-
github.com/stretchr/testify v1.9.0
8+
github.com/stretchr/testify v1.10.0
99
go.temporal.io/sdk v1.25.1
1010
gopkg.in/DataDog/dd-trace-go.v1 v1.58.1
1111
)

‎contrib/datadog/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
129129
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
130130
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
131131
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
132-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
133-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
132+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
133+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
134134
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
135135
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
136136
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

‎contrib/opentelemetry/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module go.temporal.io/sdk/contrib/opentelemetry
33
go 1.21
44

55
require (
6-
github.com/stretchr/testify v1.9.0
6+
github.com/stretchr/testify v1.10.0
77
go.opentelemetry.io/otel v1.27.0
88
go.opentelemetry.io/otel/sdk v1.27.0
99
go.opentelemetry.io/otel/trace v1.27.0

‎contrib/opentelemetry/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
7474
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7575
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7676
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
77-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
78-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
77+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
78+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7979
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
8080
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
8181
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

‎contrib/opentracing/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.21.1
66

77
require (
88
github.com/opentracing/opentracing-go v1.2.0
9-
github.com/stretchr/testify v1.9.0
9+
github.com/stretchr/testify v1.10.0
1010
go.temporal.io/sdk v1.12.0
1111
)
1212

‎contrib/opentracing/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
7171
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7272
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7373
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
74-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
75-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
74+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
75+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7676
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
7777
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
7878
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

‎contrib/resourcetuner/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.22.5
77
require (
88
github.com/containerd/cgroups/v3 v3.0.3
99
github.com/shirou/gopsutil/v4 v4.24.8
10-
github.com/stretchr/testify v1.9.0
10+
github.com/stretchr/testify v1.10.0
1111
go.einride.tech/pid v0.1.3
1212
go.temporal.io/sdk v1.29.1
1313
)

‎contrib/resourcetuner/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
9696
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
9797
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
9898
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
99-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
100-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
99+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
100+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
101101
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
102102
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
103103
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=

‎contrib/tally/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.21.1
66

77
require (
8-
github.com/stretchr/testify v1.9.0
8+
github.com/stretchr/testify v1.10.0
99
github.com/uber-go/tally/v4 v4.1.1
1010
go.temporal.io/sdk v1.12.0
1111
)

‎contrib/tally/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
132132
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
133133
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
134134
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
135-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
136-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
135+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
136+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
137137
github.com/twmb/murmur3 v1.1.5 h1:i9OLS9fkuLzBXjt6dptlAEyk58fJsSTXbRg3SgVyqgk=
138138
github.com/twmb/murmur3 v1.1.5/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
139139
github.com/uber-go/tally/v4 v4.1.1 h1:jhy6WOZp4nHyCqeV43x3Wz370LXUGBhgW2JmzOIHCWI=

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/nexus-rpc/sdk-go v0.0.12
1313
github.com/pborman/uuid v1.2.1
1414
github.com/robfig/cron v1.2.0
15-
github.com/stretchr/testify v1.9.0
15+
github.com/stretchr/testify v1.10.0
1616
go.temporal.io/api v1.40.0
1717
golang.org/x/sync v0.8.0
1818
golang.org/x/sys v0.24.0

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
6969
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7070
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7171
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
72-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
73-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
72+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
73+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7474
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
7575
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
7676
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

‎internal/cmd/build/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/pmezard/go-difflib v1.0.0 // indirect
2323
github.com/robfig/cron v1.2.0 // indirect
2424
github.com/stretchr/objx v0.5.2 // indirect
25-
github.com/stretchr/testify v1.9.0 // indirect
25+
github.com/stretchr/testify v1.10.0 // indirect
2626
go.temporal.io/api v1.40.0 // indirect
2727
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect
2828
golang.org/x/exp/typeparams v0.0.0-20240409090435-93d18d7e34b8 // indirect

‎internal/cmd/build/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
7373
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7474
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7575
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
76-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
77-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
76+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
77+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7878
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
7979
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
8080
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=

‎internal/workflow_testsuite.go

+10
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@ func (e *TestWorkflowEnvironment) SetContinuedExecutionRunID(rid string) {
349349
e.impl.setContinuedExecutionRunID(rid)
350350
}
351351

352+
// InOrderMockCalls declares that the given calls should occur in order. Syntax sugar for NotBefore.
353+
func (e *TestWorkflowEnvironment) InOrderMockCalls(calls ...*MockCallWrapper) {
354+
wrappedCalls := make([]*mock.Call, 0, len(calls))
355+
for _, call := range calls {
356+
wrappedCalls = append(wrappedCalls, call.call)
357+
}
358+
359+
mock.InOrder(wrappedCalls...)
360+
}
361+
352362
// OnActivity setup a mock call for activity. Parameter activity must be activity function (func) or activity name (string).
353363
// You must call Return() with appropriate parameters on the returned *MockCallWrapper instance. The supplied parameters to
354364
// the Return() call should either be a function that has exact same signature as the mocked activity, or it should be

‎internal/workflow_testsuite_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,29 @@ func TestActivityMockingByNameWithoutRegistrationFails(t *testing.T) {
974974
assert.Panics(t, func() { env.OnActivity("SayHello", mock.Anything, mock.Anything) }, "The code did not panic")
975975
}
976976

977+
func TestMockCallWrapperInOrder(t *testing.T) {
978+
testSuite := &WorkflowTestSuite{}
979+
env := testSuite.NewTestWorkflowEnvironment()
980+
env.RegisterActivity(namedActivity)
981+
982+
env.InOrderMockCalls(
983+
env.OnActivity(namedActivity, mock.Anything, "call1").Return("result1", nil),
984+
env.OnActivity(namedActivity, mock.Anything, "call2").Return("result2", nil),
985+
)
986+
987+
env.ExecuteWorkflow(func(ctx Context) error {
988+
ctx = WithLocalActivityOptions(ctx, LocalActivityOptions{
989+
ScheduleToCloseTimeout: time.Hour,
990+
StartToCloseTimeout: time.Hour,
991+
})
992+
var result string
993+
return ExecuteLocalActivity(ctx, "namedActivity", "call2").Get(ctx, &result)
994+
})
995+
var expectedErr *PanicError
996+
require.ErrorAs(t, env.GetWorkflowError(), &expectedErr)
997+
require.ErrorContains(t, expectedErr, "Must not be called before")
998+
}
999+
9771000
func TestMockCallWrapperNotBefore(t *testing.T) {
9781001
testSuite := &WorkflowTestSuite{}
9791002
env := testSuite.NewTestWorkflowEnvironment()

‎test/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/nexus-rpc/sdk-go v0.0.12
1111
github.com/opentracing/opentracing-go v1.2.0
1212
github.com/pborman/uuid v1.2.1
13-
github.com/stretchr/testify v1.9.0
13+
github.com/stretchr/testify v1.10.0
1414
github.com/uber-go/tally/v4 v4.1.1
1515
go.opentelemetry.io/otel v1.28.0
1616
go.opentelemetry.io/otel/sdk v1.28.0

‎test/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
166166
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
167167
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
168168
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
169-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
170-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
169+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
170+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
171171
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
172172
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
173173
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=

0 commit comments

Comments
 (0)
Please sign in to comment.