Skip to content

Commit ad2de5f

Browse files
committed
mock: isolate objx-dependent code in their own source files
In order to ease maintenance of downstream forks of Testify that would remove dependency on github.com/stretchr/objx we move all uses of that module in isolated source files. A fork without that dependency could just remove those files. See #1752 (comment) The use of objx is quite contained: it is only used in Mock.TestData(). Note that we can't just remove that method or change the return value because that would be a breaking change.
1 parent a5d5c33 commit ad2de5f

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

mock/mock.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/davecgh/go-spew/spew"
1515
"github.com/pmezard/go-difflib/difflib"
16-
"github.com/stretchr/objx"
1716

1817
"github.com/stretchr/testify/assert"
1918
)
@@ -311,7 +310,7 @@ type Mock struct {
311310

312311
// TestData holds any data that might be useful for testing. Testify ignores
313312
// this data completely allowing you to do whatever you like with it.
314-
testData objx.Map
313+
testData testData
315314

316315
mutex sync.Mutex
317316
}
@@ -324,16 +323,6 @@ func (m *Mock) String() string {
324323
return fmt.Sprintf("%[1]T<%[1]p>", m)
325324
}
326325

327-
// TestData holds any data that might be useful for testing. Testify ignores
328-
// this data completely allowing you to do whatever you like with it.
329-
func (m *Mock) TestData() objx.Map {
330-
if m.testData == nil {
331-
m.testData = make(objx.Map)
332-
}
333-
334-
return m.testData
335-
}
336-
337326
/*
338327
Setting expectations
339328
*/

mock/mock_objx.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This source file isolates the uses of the objx module to ease
2+
// maintenance of downstream forks that remove that dependency.
3+
// See https://github.com/stretchr/testify/issues/1752
4+
5+
package mock
6+
7+
import "github.com/stretchr/objx"
8+
9+
type testData = objx.Map
10+
11+
// TestData holds any data that might be useful for testing. Testify ignores
12+
// this data completely allowing you to do whatever you like with it.
13+
func (m *Mock) TestData() objx.Map {
14+
if m.testData == nil {
15+
m.testData = make(objx.Map)
16+
}
17+
18+
return m.testData
19+
}

mock/mock_objx_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package mock
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func Test_Mock_TestData(t *testing.T) {
10+
t.Parallel()
11+
12+
var mockedService = new(TestExampleImplementation)
13+
14+
if assert.NotNil(t, mockedService.TestData()) {
15+
16+
mockedService.TestData().Set("something", 123)
17+
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
18+
}
19+
}

mock/mock_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,6 @@ func (m *MockTestingT) FailNow() {
162162
Mock
163163
*/
164164

165-
func Test_Mock_TestData(t *testing.T) {
166-
t.Parallel()
167-
168-
var mockedService = new(TestExampleImplementation)
169-
170-
if assert.NotNil(t, mockedService.TestData()) {
171-
172-
mockedService.TestData().Set("something", 123)
173-
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
174-
}
175-
}
176-
177165
func Test_Mock_On(t *testing.T) {
178166
t.Parallel()
179167

0 commit comments

Comments
 (0)