mirror of https://github.com/stretchr/testify.git
Fix panic in AssertExpectations for mocks without expectations (#1207)
Co-authored-by: Tony Abboud <tabboud@palantir.com>pull/1198/head v1.7.4
parent
840cb80149
commit
48391ba5eb
|
@ -508,6 +508,10 @@ 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()
|
||||
var somethingMissing bool
|
||||
|
|
|
@ -915,6 +915,7 @@ func Test_AssertExpectationsForObjects_Helper(t *testing.T) {
|
|||
var mockedService1 = new(TestExampleImplementation)
|
||||
var mockedService2 = new(TestExampleImplementation)
|
||||
var mockedService3 = new(TestExampleImplementation)
|
||||
var mockedService4 = new(TestExampleImplementation) // No expectations does not cause a panic
|
||||
|
||||
mockedService1.On("Test_AssertExpectationsForObjects_Helper", 1).Return()
|
||||
mockedService2.On("Test_AssertExpectationsForObjects_Helper", 2).Return()
|
||||
|
@ -924,8 +925,8 @@ func Test_AssertExpectationsForObjects_Helper(t *testing.T) {
|
|||
mockedService2.Called(2)
|
||||
mockedService3.Called(3)
|
||||
|
||||
assert.True(t, AssertExpectationsForObjects(t, &mockedService1.Mock, &mockedService2.Mock, &mockedService3.Mock))
|
||||
assert.True(t, AssertExpectationsForObjects(t, mockedService1, mockedService2, mockedService3))
|
||||
assert.True(t, AssertExpectationsForObjects(t, &mockedService1.Mock, &mockedService2.Mock, &mockedService3.Mock, &mockedService4.Mock))
|
||||
assert.True(t, AssertExpectationsForObjects(t, mockedService1, mockedService2, mockedService3, mockedService4))
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue