Skip to content

Commit

Permalink
Update response.go
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueCarry authored Jun 12, 2018
1 parent 9d19606 commit 6de5ea4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down

0 comments on commit 6de5ea4

Please sign in to comment.