mirror of https://github.com/stretchr/testify.git
fixing panic in calls to assertion with nil m.mutex (#1212)
* fixing panic in calls to assertion with nil m.mutex This reverts a change that was made in https://github.com/stretchr/testify/pull/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: - https://github.com/stretchr/testify/issues/1208 - https://github.com/stretchr/testify/issues/1210 * Revert throwing out the lock because other concurrent calls can already have it locked * fix go vet copy lock by using pointer * fix obj assignment for passing testpull/689/merge v1.7.5
parent
c206b2e823
commit
b5ce165710
16
mock/mock.go
16
mock/mock.go
|
@ -255,7 +255,7 @@ type Mock struct {
|
|||
// this data completely allowing you to do whatever you like with it.
|
||||
testData objx.Map
|
||||
|
||||
mutex *sync.Mutex
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// String provides a %v format string for Mock.
|
||||
|
@ -282,10 +282,6 @@ func (m *Mock) TestData() objx.Map {
|
|||
|
||||
// Test sets the test struct variable of the mock object
|
||||
func (m *Mock) Test(t TestingT) {
|
||||
if m.mutex == nil {
|
||||
m.mutex = &sync.Mutex{}
|
||||
}
|
||||
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
m.test = t
|
||||
|
@ -316,9 +312,6 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call {
|
|||
}
|
||||
}
|
||||
|
||||
// Since we start mocks with the .On() function, m.mutex should be reset
|
||||
m.mutex = &sync.Mutex{}
|
||||
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
c := newCall(m, methodName, assert.CallerInfo(), arguments...)
|
||||
|
@ -526,9 +519,9 @@ func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
|
|||
h.Helper()
|
||||
}
|
||||
for _, obj := range testObjects {
|
||||
if m, ok := obj.(Mock); ok {
|
||||
if m, ok := obj.(*Mock); ok {
|
||||
t.Logf("Deprecated mock.AssertExpectationsForObjects(myMock.Mock) use mock.AssertExpectationsForObjects(myMock)")
|
||||
obj = &m
|
||||
obj = m
|
||||
}
|
||||
m := obj.(assertExpectationser)
|
||||
if !m.AssertExpectations(t) {
|
||||
|
@ -545,9 +538,6 @@ func (m *Mock) AssertExpectations(t TestingT) bool {
|
|||
if h, ok := t.(tHelper); ok {
|
||||
h.Helper()
|
||||
}
|
||||
if m.mutex == nil {
|
||||
m.mutex = &sync.Mutex{}
|
||||
}
|
||||
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
|
Loading…
Reference in New Issue