Skip to content

Commit aca7672

Browse files
author
Edward Raigosa
authored
fixing panic in calls to assertion with nil m.mutex
This reverts a change that was made in stretchr#1182 The PR makes m.mutex a pointer which now needs to be checked but it's not checked for nil everywhere. This should also help with these issues: - stretchr#1208 - stretchr#1210
1 parent c206b2e commit aca7672

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

mock/mock.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ type Mock struct {
255255
// this data completely allowing you to do whatever you like with it.
256256
testData objx.Map
257257

258-
mutex *sync.Mutex
258+
mutex sync.Mutex
259259
}
260260

261261
// String provides a %v format string for Mock.
@@ -282,10 +282,6 @@ func (m *Mock) TestData() objx.Map {
282282

283283
// Test sets the test struct variable of the mock object
284284
func (m *Mock) Test(t TestingT) {
285-
if m.mutex == nil {
286-
m.mutex = &sync.Mutex{}
287-
}
288-
289285
m.mutex.Lock()
290286
defer m.mutex.Unlock()
291287
m.test = t
@@ -317,7 +313,7 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call {
317313
}
318314

319315
// Since we start mocks with the .On() function, m.mutex should be reset
320-
m.mutex = &sync.Mutex{}
316+
m.mutex = sync.Mutex{}
321317

322318
m.mutex.Lock()
323319
defer m.mutex.Unlock()
@@ -545,9 +541,6 @@ func (m *Mock) AssertExpectations(t TestingT) bool {
545541
if h, ok := t.(tHelper); ok {
546542
h.Helper()
547543
}
548-
if m.mutex == nil {
549-
m.mutex = &sync.Mutex{}
550-
}
551544

552545
m.mutex.Lock()
553546
defer m.mutex.Unlock()

0 commit comments

Comments
 (0)