コード例 #1
0
ファイル: mockcaller.go プロジェクト: armada-io/h2
// matches tests if this stub matches our request - not thread safe
func (s *Stub) matches(req *client.Request) bool {
	if req == nil {
		return false
	}
	if s.Service != req.Service() || s.Endpoint != req.Endpoint() {
		return false
	}
	if s.invocationLimit > 0 && len(s.matched) >= s.invocationLimit {
		return false
	}
	if s.payload != nil {
		clone := proto.Clone(s.payload)
		req.Unmarshal(clone)
		if !proto.Equal(s.payload, clone) {
			return false
		}
	}

	// got a match
	if s.matched == nil {
		s.matched = make([]*client.Request, 0)
	}
	s.matched = append(s.matched, req)
	return true
}