findStringMatch returns the index of the closest mock string and the Levenshtein distance so callers don't need to recompute it.
(req string, mockStrings []string)
| 775 | // findStringMatch returns the index of the closest mock string and the |
| 776 | // Levenshtein distance so callers don't need to recompute it. |
| 777 | func (h *HTTP) findStringMatch(req string, mockStrings []string) (int, int) { |
| 778 | minDist := int(^uint(0) >> 1) |
| 779 | bestMatch := -1 |
| 780 | for idx, mock := range mockStrings { |
| 781 | if !util.IsASCII(mock) { |
| 782 | continue |
| 783 | } |
| 784 | dist := levenshtein.ComputeDistance(req, mock) |
| 785 | if dist == 0 { |
| 786 | return idx, 0 |
| 787 | } |
| 788 | if dist < minDist { |
| 789 | minDist = dist |
| 790 | bestMatch = idx |
| 791 | } |
| 792 | } |
| 793 | return bestMatch, minDist |
| 794 | } |
| 795 | |
| 796 | // jaccardBestMatch finds the mock body with the highest Jaccard similarity |
| 797 | // to reqBuff. mockBodies are pre-decoded/stripped byte slices so the caller |
no test coverage detected