JSONDiffWithNoiseControl compares JSON with support for both Path-based noise (e.g. "body.user.id") and Global noise (e.g. "timestamp") to be ignored everywhere.
(validatedJSON ValidatedJSON, noise map[string][]string, ignoreOrdering bool)
| 109 | // JSONDiffWithNoiseControl compares JSON with support for both Path-based noise (e.g. "body.user.id") |
| 110 | // and Global noise (e.g. "timestamp") to be ignored everywhere. |
| 111 | func JSONDiffWithNoiseControl(validatedJSON ValidatedJSON, noise map[string][]string, ignoreOrdering bool) (JSONComparisonResult, error) { |
| 112 | // Split noise into Path-based (contains dots) and Global (no dots) |
| 113 | pathNoise := make(map[string][]string) |
| 114 | globalKeys := make(map[string]bool) |
| 115 | |
| 116 | for k, v := range noise { |
| 117 | // If a key has no dots, treat it as a Global Key to be ignored everywhere. |
| 118 | if !strings.Contains(k, ".") { |
| 119 | globalKeys[strings.ToLower(k)] = true |
| 120 | } else { |
| 121 | // Otherwise, it's a path-specific noise (e.g. "body.data.timestamp") |
| 122 | pathNoise[k] = v |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | idx := buildNoiseIndex(pathNoise) |
| 127 | return matchJSONWithNoiseHandlingIndexed("", validatedJSON.expected, validatedJSON.actual, idx, globalKeys, ignoreOrdering) |
| 128 | } |
| 129 | |
| 130 | // matchJSONWithNoiseHandlingIndexed now accepts globalKeys to skip specific keys at any depth. |
| 131 | func matchJSONWithNoiseHandlingIndexed(key string, expected, actual interface{}, ni noiseIndex, globalKeys map[string]bool, ignoreOrdering bool) (JSONComparisonResult, error) { |
no test coverage detected