MCPcopy
hub / github.com/keploy/keploy / Match

Function Match

pkg/matcher/http/match.go:30–466  ·  view source on GitHub ↗
(tc *models.TestCase, actualResponse *models.HTTPResp, noiseConfig map[string]map[string][]string, ignoreOrdering bool, compareAll bool, logger *zap.Logger, emitFailureLogs bool)

Source from the content-addressed store, hash-verified

28var jsonUnmarshal234 = json.Unmarshal
29
30func Match(tc *models.TestCase, actualResponse *models.HTTPResp, noiseConfig map[string]map[string][]string, ignoreOrdering bool, compareAll bool, logger *zap.Logger, emitFailureLogs bool) (bool, *models.Result) {
31 // If the response body was skipped during recording (>1MB), compute body size comparison
32 // and clear the actual body so the normal comparison runs (empty vs empty).
33 var bodySizeResult models.IntResult
34 if tc.HTTPResp.BodySkipped {
35 actualBodySize := int64(len(actualResponse.Body))
36 bodySizeMatch := tc.HTTPResp.BodySize == actualBodySize
37
38 logger.Info("response body was greater than 1MB during recording, comparing body size",
39 zap.String("testcase", tc.Name),
40 zap.Int64("expected_size", tc.HTTPResp.BodySize),
41 zap.Int64("actual_size", actualBodySize),
42 zap.Bool("size_match", bodySizeMatch))
43
44 // Log actual response body as debug before clearing
45 logger.Debug("actual response body (skipped during recording)",
46 zap.String("testcase", tc.Name),
47 zap.String("body", actualResponse.Body))
48
49 bodySizeResult = models.IntResult{
50 Normal: bodySizeMatch,
51 Expected: int(tc.HTTPResp.BodySize),
52 Actual: int(actualBodySize),
53 }
54
55 // Clear actual body so body comparison below runs as empty vs empty
56 actualResponse.Body = ""
57 }
58
59 bodyType := models.Plain
60 if jsonValid234([]byte(actualResponse.Body)) {
61 bodyType = models.JSON
62 }
63
64 pass := true
65 hRes := &[]models.HeaderResult{}
66 res := &models.Result{
67 StatusCode: models.IntResult{
68 Normal: false,
69 Expected: tc.HTTPResp.StatusCode,
70 Actual: actualResponse.StatusCode,
71 },
72 BodyResult: []models.BodyResult{{
73 Normal: false,
74 Type: bodyType,
75 Expected: tc.HTTPResp.Body,
76 Actual: actualResponse.Body,
77 }},
78 BodySizeResult: bodySizeResult,
79 }
80
81 // If body size comparison failed, mark pass as false
82 if tc.HTTPResp.BodySkipped && !bodySizeResult.Normal {
83 pass = false
84 }
85
86 noise := tc.Noise
87 var (

Calls 15

IsExactMethod · 0.95
PushStatusDiffMethod · 0.95
PushHeaderDiffMethod · 0.95
MatchesMethod · 0.95
PushFooterDiffMethod · 0.95
DifferencesMethod · 0.95
PushBodyDiffMethod · 0.95
RenderMethod · 0.95
ToHTTPHeaderFunction · 0.92
RenderIfTemplatizedFunction · 0.92
LogErrorFunction · 0.92