diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c39ac045..40e291327 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: - run: ./.ci.readme.fmt.sh - run: ./.ci.govet.sh - run: go test -v -race ./... + - run: go test -tags testify_no_objx ./... test: runs-on: ubuntu-latest strategy: @@ -39,3 +40,4 @@ jobs: with: go-version: ${{ matrix.go_version }} - run: go test -v -race ./... + - run: go test -tags testify_no_objx ./... diff --git a/mock/mock.go b/mock/mock.go index e88402b3e..fa1b363c4 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -13,7 +13,6 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/pmezard/go-difflib/difflib" - "github.com/stretchr/objx" "github.com/stretchr/testify/assert" ) @@ -311,7 +310,7 @@ type Mock struct { // TestData holds any data that might be useful for testing. Testify ignores // this data completely allowing you to do whatever you like with it. - testData objx.Map + testData testData mutex sync.Mutex } @@ -324,16 +323,6 @@ func (m *Mock) String() string { return fmt.Sprintf("%[1]T<%[1]p>", m) } -// TestData holds any data that might be useful for testing. Testify ignores -// this data completely allowing you to do whatever you like with it. -func (m *Mock) TestData() objx.Map { - if m.testData == nil { - m.testData = make(objx.Map) - } - - return m.testData -} - /* Setting expectations */ diff --git a/mock/mock_no_objx.go b/mock/mock_no_objx.go new file mode 100644 index 000000000..e8db50ec0 --- /dev/null +++ b/mock/mock_no_objx.go @@ -0,0 +1,5 @@ +//go:build testify_no_objx || testify_no_deps + +package mock + +type testData = struct{} diff --git a/mock/mock_objx.go b/mock/mock_objx.go new file mode 100644 index 000000000..77f75dd65 --- /dev/null +++ b/mock/mock_objx.go @@ -0,0 +1,21 @@ +// This source file isolates the uses of the objx module to ease +// maintenance of downstream forks that remove that dependency. +// See https://github.com/stretchr/testify/issues/1752 + +//go:build !testify_no_objx && !testify_no_deps + +package mock + +import "github.com/stretchr/objx" + +type testData = objx.Map + +// TestData holds any data that might be useful for testing. Testify ignores +// this data completely allowing you to do whatever you like with it. +func (m *Mock) TestData() objx.Map { + if m.testData == nil { + m.testData = make(objx.Map) + } + + return m.testData +} diff --git a/mock/mock_objx_test.go b/mock/mock_objx_test.go new file mode 100644 index 000000000..556ac9c44 --- /dev/null +++ b/mock/mock_objx_test.go @@ -0,0 +1,21 @@ +//go:build !testify_no_objx && !testify_no_deps + +package mock + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_Mock_TestData(t *testing.T) { + t.Parallel() + + var mockedService = new(TestExampleImplementation) + + if assert.NotNil(t, mockedService.TestData()) { + + mockedService.TestData().Set("something", 123) + assert.Equal(t, 123, mockedService.TestData().Get("something").Data()) + } +} diff --git a/mock/mock_test.go b/mock/mock_test.go index c9fea8f6e..f3330f7ac 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -163,18 +163,6 @@ func (m *MockTestingT) FailNow() { Mock */ -func Test_Mock_TestData(t *testing.T) { - t.Parallel() - - var mockedService = new(TestExampleImplementation) - - if assert.NotNil(t, mockedService.TestData()) { - - mockedService.TestData().Set("something", 123) - assert.Equal(t, 123, mockedService.TestData().Get("something").Data()) - } -} - func Test_Mock_On(t *testing.T) { t.Parallel()