diff --git a/response.go b/response.go index e1f494b..5414578 100644 --- a/response.go +++ b/response.go @@ -111,6 +111,8 @@ type FakeResponse struct { // Returns true either when nothing to compare or deep equal check passed func (fr *FakeResponse) isArgsMatch(args []driver.NamedValue) bool { + fr.mu.Lock() + defer fr.mu.Unlock() arguments := make([]interface{}, len(args)) if len(args) > 0 { for index, arg := range args { @@ -121,14 +123,19 @@ func (fr *FakeResponse) isArgsMatch(args []driver.NamedValue) bool { } func (fr *FakeResponse) isQueryMatch(query string) bool { + fr.mu.Lock() + defer fr.mu.Unlock() return fr.Pattern == "" || strings.Contains(query, fr.Pattern) } // IsMatch checks if both query and args matcher's return true and if this is Once mock func (fr *FakeResponse) IsMatch(query string, args []driver.NamedValue) bool { + fr.mu.Lock() if fr.Once && fr.Triggered { + fr.mu.Unlock() return false } + fr.mu.Unlock() return fr.isQueryMatch(query) && fr.isArgsMatch(args) }