Skip to content

Commit

Permalink
Upgrading testify for proper handling of subtests
Browse files Browse the repository at this point in the history
Without this mocks are not verified as expected
(every table-test case'). While this would work, one might expect
behavior like
```
for _, tt := range testcases {
    t.Run(tt.name, func(t* testing.T) {
        init-controller-and-mocks
        // test-code
        // mocks are verified here, at the end of subtest
    }
}
```
Unfortunately, that's not the behavior you
get with `s.Run(subtest func())` as controller is not re-initialized.

In order to addres this gap testify introduced `SetupSubTest/TearDownSubTest` in v1.8.2
See stretchr/testify#1246 for more details
  • Loading branch information
dkrotx committed Jun 22, 2024
1 parent 6c4611f commit 6814275
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/pborman/uuid v0.0.0-20160209185913-a97ce2ca70fa
github.com/robfig/cron v1.2.0
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/uber-go/tally v3.3.15+incompatible
github.com/uber/cadence-idl v0.0.0-20240416202333-83d5cae7fc51
github.com/uber/jaeger-client-go v2.22.1+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
Expand Down
10 changes: 10 additions & 0 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,16 @@ func (s *workflowClientTestSuite) TearDownTest() {
s.mockCtrl.Finish() // assert mock’s expectations
}

func (s *workflowClientTestSuite) SetupSubTest() {
// required for s.Run in case of table tests and mocks
s.SetupTest()
}

func (s *workflowClientTestSuite) TearDownSubTest() {
// required for s.Run in case of table tests and mocks
s.TearDownTest()
}

func (s *workflowClientTestSuite) TestSignalWithStartWorkflow() {
signalName := "my signal"
signalInput := []byte("my signal input")
Expand Down

0 comments on commit 6814275

Please sign in to comment.