MCPcopy
hub / github.com/keploy/keploy / findStringMatch

Method findStringMatch

pkg/agent/proxy/integrations/http/match.go:777–794  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

775// findStringMatch returns the index of the closest mock string and the
776// Levenshtein distance so callers don't need to recompute it.
777func (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

Callers 1

PerformFuzzyMatchMethod · 0.95

Calls 1

IsASCIIFunction · 0.92

Tested by

no test coverage detected