Fix issue #55 - Serialize calls to Mock.Called.

pull/67/head
Anup Chenthamarakshan 2014-07-11 22:08:48 -07:00
parent b641a3539b
commit 27b04ffad0
1 changed files with 5 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
"sync"
) )
// TestingT is an interface wrapper around *testing.T // TestingT is an interface wrapper around *testing.T
@ -60,6 +61,8 @@ type Mock struct {
// TestData holds any data that might be useful for testing. Testify ignores // TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it. // this data completely allowing you to do whatever you like with it.
testData objx.Map testData objx.Map
mutex sync.Mutex
} }
// TestData holds any data that might be useful for testing. Testify ignores // TestData holds any data that might be useful for testing. Testify ignores
@ -178,6 +181,8 @@ func callString(method string, arguments Arguments, includeArgumentValues bool)
// of arguments to return. Panics if the call is unexpected (i.e. not preceeded by // of arguments to return. Panics if the call is unexpected (i.e. not preceeded by
// appropriate .On .Return() calls) // appropriate .On .Return() calls)
func (m *Mock) Called(arguments ...interface{}) Arguments { func (m *Mock) Called(arguments ...interface{}) Arguments {
defer m.mutex.Unlock()
m.mutex.Lock()
// get the calling function's name // get the calling function's name
pc, _, _, ok := runtime.Caller(1) pc, _, _, ok := runtime.Caller(1)